From e4318a887a70c9bf70888c55bec09e33efb2351d Mon Sep 17 00:00:00 2001
From: sadan4 <117494111+sadan4@users.noreply.github.com>
Date: Sun, 22 Sep 2024 03:24:12 -0400
Subject: [PATCH 1/2] ConsoleJanitor: Ignore all loggers with whitelist (#2896)
---
src/plugins/consoleJanitor/README.md | 4 +-
src/plugins/consoleJanitor/index.ts | 61 ++++++++++++++--------------
2 files changed, 32 insertions(+), 33 deletions(-)
diff --git a/src/plugins/consoleJanitor/README.md b/src/plugins/consoleJanitor/README.md
index fbba766a4..9737f53d1 100644
--- a/src/plugins/consoleJanitor/README.md
+++ b/src/plugins/consoleJanitor/README.md
@@ -1,5 +1,5 @@
# ConsoleJanitor
-Disables annoying console messages/errors. This plugin mainly removes errors/warnings that happen all the time and noisy/spammy logging messages.
+Disables annoying console messages/errors. This plugin mainly removes errors/warnings that happen all the time and Discord logger messages.
-Some of the disabled messages include the "notosans-400-normalitalic" error and MessageActionCreators, Routing/Utils loggers.
+One of the disabled messages is the "Window state not initialized" warning, for example.
diff --git a/src/plugins/consoleJanitor/index.ts b/src/plugins/consoleJanitor/index.ts
index f5f43c06b..b0c8905f7 100644
--- a/src/plugins/consoleJanitor/index.ts
+++ b/src/plugins/consoleJanitor/index.ts
@@ -6,7 +6,7 @@
import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
-import definePlugin, { OptionType } from "@utils/types";
+import definePlugin, { OptionType, StartAt } from "@utils/types";
const Noop = () => { };
const NoopLogger = {
@@ -22,10 +22,12 @@ const NoopLogger = {
fileOnly: Noop
};
+const logAllow = new Set();
+
const settings = definePluginSettings({
- disableNoisyLoggers: {
+ disableLoggers: {
type: OptionType.BOOLEAN,
- description: "Disable noisy loggers like the MessageActionCreators",
+ description: "Disables Discords loggers",
default: false,
restartNeeded: true
},
@@ -34,16 +36,34 @@ const settings = definePluginSettings({
description: "Disable the Spotify logger, which leaks account information and access token",
default: true,
restartNeeded: true
+ },
+ whitelistedLoggers: {
+ type: OptionType.STRING,
+ description: "Semi colon separated list of loggers to allow even if others are hidden",
+ default: "GatewaySocket; Routing/Utils",
+ onChange(newVal: string) {
+ logAllow.clear();
+ newVal.split(";").map(x => x.trim()).forEach(logAllow.add.bind(logAllow));
+ }
}
});
export default definePlugin({
name: "ConsoleJanitor",
description: "Disables annoying console messages/errors",
- authors: [Devs.Nuckyz],
+ authors: [Devs.Nuckyz, Devs.sadan],
settings,
+ startAt: StartAt.Init,
+ start() {
+ logAllow.clear();
+ this.settings.store.whitelistedLoggers?.split(";").map(x => x.trim()).forEach(logAllow.add.bind(logAllow));
+ },
+
NoopLogger: () => NoopLogger,
+ shouldLog(logger: string) {
+ return logAllow.has(logger);
+ },
patches: [
{
@@ -103,34 +123,13 @@ export default definePlugin({
replace: ""
}
},
- ...[
- '("MessageActionCreators")', '("ChannelMessages")',
- '("Routing/Utils")', '("RTCControlSocket")',
- '("ConnectionEventFramerateReducer")', '("RTCLatencyTestManager")',
- '("OverlayBridgeStore")', '("RPCServer:WSS")', '("RPCServer:IPC")'
- ].map(logger => ({
- find: logger,
- predicate: () => settings.store.disableNoisyLoggers,
- all: true,
- replacement: {
- match: new RegExp(String.raw`new \i\.\i${logger.replace(/([()])/g, "\\$1")}`),
- replace: `$self.NoopLogger${logger}`
- }
- })),
+ // Patches discords generic logger function
{
- find: '"Experimental codecs: "',
- predicate: () => settings.store.disableNoisyLoggers,
+ find: "Σ:",
+ predicate: () => settings.store.disableLoggers,
replacement: {
- match: /new \i\.\i\("Connection\("\.concat\(\i,"\)"\)\)/,
- replace: "$self.NoopLogger()"
- }
- },
- {
- find: '"_handleLocalVideoDisabled: ',
- predicate: () => settings.store.disableNoisyLoggers,
- replacement: {
- match: /new \i\.\i\("RTCConnection\("\.concat.+?\)\)(?=,)/,
- replace: "$self.NoopLogger()"
+ match: /(?<=&&)(?=console)/,
+ replace: "$self.shouldLog(arguments[0])&&"
}
},
{
@@ -141,5 +140,5 @@ export default definePlugin({
replace: "$self.NoopLogger()"
}
}
- ]
+ ],
});
From db5fe2a39472275d2422035d3c55cb6f8cf15538 Mon Sep 17 00:00:00 2001
From: TheGreenPig <67547385+TheGreenPig@users.noreply.github.com>
Date: Sun, 22 Sep 2024 09:38:32 +0200
Subject: [PATCH 2/2] Fix plugin settings inconsistency regarding setting names
(#2884)
---
.../PluginSettings/components/SettingNumericComponent.tsx | 5 ++++-
.../PluginSettings/components/SettingSelectComponent.tsx | 5 ++++-
.../PluginSettings/components/SettingSliderComponent.tsx | 5 ++++-
.../PluginSettings/components/SettingTextComponent.tsx | 5 ++++-
4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/components/PluginSettings/components/SettingNumericComponent.tsx b/src/components/PluginSettings/components/SettingNumericComponent.tsx
index 446d2504b..b724717d7 100644
--- a/src/components/PluginSettings/components/SettingNumericComponent.tsx
+++ b/src/components/PluginSettings/components/SettingNumericComponent.tsx
@@ -16,6 +16,8 @@
* along with this program. If not, see .
*/
+import { Margins } from "@utils/margins";
+import { wordsFromCamel, wordsToTitle } from "@utils/text";
import { OptionType, PluginOptionNumber } from "@utils/types";
import { Forms, React, TextInput } from "@webpack/common";
@@ -54,7 +56,8 @@ export function SettingNumericComponent({ option, pluginSettings, definedSetting
return (
- {option.description}
+ {wordsToTitle(wordsFromCamel(id))}
+ {option.description}
.
*/
+import { Margins } from "@utils/margins";
+import { wordsFromCamel, wordsToTitle } from "@utils/text";
import { PluginOptionSelect } from "@utils/types";
import { Forms, React, Select } from "@webpack/common";
@@ -44,7 +46,8 @@ export function SettingSelectComponent({ option, pluginSettings, definedSettings
return (
- {option.description}
+ {wordsToTitle(wordsFromCamel(id))}
+ {option.description}
.
*/
+import { Margins } from "@utils/margins";
+import { wordsFromCamel, wordsToTitle } from "@utils/text";
import { PluginOptionSlider } from "@utils/types";
import { Forms, React, Slider } from "@webpack/common";
@@ -50,7 +52,8 @@ export function SettingSliderComponent({ option, pluginSettings, definedSettings
return (
- {option.description}
+ {wordsToTitle(wordsFromCamel(id))}
+ {option.description}
.
*/
+import { Margins } from "@utils/margins";
+import { wordsFromCamel, wordsToTitle } from "@utils/text";
import { PluginOptionString } from "@utils/types";
import { Forms, React, TextInput } from "@webpack/common";
@@ -41,7 +43,8 @@ export function SettingTextComponent({ option, pluginSettings, definedSettings,
return (
- {option.description}
+ {wordsToTitle(wordsFromCamel(id))}
+ {option.description}