From 2506ba1b2eae1d1f868b704040c6d0dd82b2edef Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 3 Jul 2024 00:06:12 -0300 Subject: [PATCH 1/2] feat(plugins): ConsoleJanitor (#2659) --- src/plugins/consoleJanitor/README.md | 5 + src/plugins/consoleJanitor/index.ts | 153 +++++++++++++++++++++++++++ src/plugins/index.ts | 4 + src/webpack/patchWebpack.ts | 3 - 4 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 src/plugins/consoleJanitor/README.md create mode 100644 src/plugins/consoleJanitor/index.ts diff --git a/src/plugins/consoleJanitor/README.md b/src/plugins/consoleJanitor/README.md new file mode 100644 index 000000000..fbba766a4 --- /dev/null +++ b/src/plugins/consoleJanitor/README.md @@ -0,0 +1,5 @@ +# ConsoleJanitor + +Disables annoying console messages/errors. This plugin mainly removes errors/warnings that happen all the time and noisy/spammy logging messages. + +Some of the disabled messages include the "notosans-400-normalitalic" error and MessageActionCreators, Routing/Utils loggers. diff --git a/src/plugins/consoleJanitor/index.ts b/src/plugins/consoleJanitor/index.ts new file mode 100644 index 000000000..5579b4c70 --- /dev/null +++ b/src/plugins/consoleJanitor/index.ts @@ -0,0 +1,153 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { definePluginSettings } from "@api/Settings"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; + +const Noop = () => { }; +const NoopLogger = { + logDangerously: Noop, + log: Noop, + verboseDangerously: Noop, + verbose: Noop, + info: Noop, + warn: Noop, + error: Noop, + trace: Noop, + time: Noop, + fileOnly: Noop +}; + +const settings = definePluginSettings({ + disableNoisyLoggers: { + type: OptionType.BOOLEAN, + description: "Disable noisy loggers like the MessageActionCreators", + default: false, + restartNeeded: true + }, + disableSpotifyLogger: { + type: OptionType.BOOLEAN, + description: "Disable the Spotify logger, which leaks account information and access token", + default: true, + restartNeeded: true + } +}); + +export default definePlugin({ + name: "ConsoleJanitor", + description: "Disables annoying console messages/errors", + authors: [Devs.Nuckyz], + enabledByDefault: true, + settings, + + NoopLogger: () => NoopLogger, + + patches: [ + { + find: 'console.warn("Window state not initialized"', + replacement: { + match: /console\.warn\("Window state not initialized",\i\),/, + replace: "" + } + }, + { + find: "is not a valid locale.", + replacement: { + match: /\i\.error\(""\.concat\(\i," is not a valid locale."\)\);/, + replace: "" + } + }, + { + find: "notosans-400-normalitalic", + replacement: { + match: /,"notosans-.+?"/g, + replace: "" + } + }, + { + find: 'console.warn("[DEPRECATED] Please use `subscribeWithSelector` middleware");', + all: true, + replacement: { + match: /console\.warn\("\[DEPRECATED\] Please use `subscribeWithSelector` middleware"\);/, + replace: "" + } + }, + { + find: "RPCServer:WSS", + replacement: { + match: /\i\.error\("Error: "\.concat\((\i)\.message/, + replace: '!$1.message.includes("EADDRINUSE")&&$&' + } + }, + { + find: "Tried getting Dispatch instance before instantiated", + replacement: { + match: /null==\i&&\i\.warn\("Tried getting Dispatch instance before instantiated"\),/, + replace: "" + } + }, + { + find: "Unable to determine render window for element", + replacement: { + match: /console\.warn\("Unable to determine render window for element",\i\),/, + replace: "" + } + }, + { + find: "failed to send analytics events", + replacement: { + match: /console\.error\("\[analytics\] failed to send analytics events query: "\.concat\(\i\)\)/, + replace: "" + } + }, + { + find: "Slow dispatch on", + replacement: { + match: /\i\.totalTime>100&&\i\.verbose\("Slow dispatch on ".+?\)\);/, + replace: "" + } + }, + ...[ + '("MessageActionCreators")', '("ChannelMessages")', + '("Routing/Utils")', '("RTCControlSocket")', + '("ConnectionEventFramerateReducer")', '("RTCLatencyTestManager")', + '("OverlayBridgeStore")', '("RPCServer:WSS")' + ].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}` + } + })), + { + find: '"Experimental codecs: "', + predicate: () => settings.store.disableNoisyLoggers, + replacement: { + match: /new \i\.\i\("Connection\("\.concat\(\i,"\)"\)\)/, + replace: "$self.NoopLogger()" + } + }, + { + find: '"Handling ping: "', + predicate: () => settings.store.disableNoisyLoggers, + replacement: { + match: /new \i\.\i\("RTCConnection\("\.concat.+?\)\)(?=,)/, + replace: "$self.NoopLogger()" + } + }, + { + find: '("Spotify")', + predicate: () => settings.store.disableSpotifyLogger, + replacement: { + match: /new \i\.\i\("Spotify"\)/, + replace: "$self.NoopLogger()" + } + } + ] +}); diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 9268051ff..e6caf7340 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -59,11 +59,15 @@ export function addPatch(newPatch: Omit, pluginName: string) { delete patch.group; } + if (patch.predicate && !patch.predicate()) return; + canonicalizeFind(patch); if (!Array.isArray(patch.replacement)) { patch.replacement = [patch.replacement]; } + patch.replacement = patch.replacement.filter(({ predicate }) => !predicate || predicate()); + if (IS_REPORTER) { patch.replacement.forEach(r => { delete r.predicate; diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index 4b3b28a8e..f32aeb789 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -259,7 +259,6 @@ function patchFactories(factories: Record Date: Wed, 3 Jul 2024 00:06:12 -0300 Subject: [PATCH 2/2] feat(plugins): ConsoleJanitor (#2659) --- src/plugins/consoleJanitor/README.md | 5 + src/plugins/consoleJanitor/index.ts | 152 +++++++++++++++++++++++++++ src/plugins/index.ts | 4 + src/webpack/patchWebpack.ts | 3 - 4 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 src/plugins/consoleJanitor/README.md create mode 100644 src/plugins/consoleJanitor/index.ts diff --git a/src/plugins/consoleJanitor/README.md b/src/plugins/consoleJanitor/README.md new file mode 100644 index 000000000..fbba766a4 --- /dev/null +++ b/src/plugins/consoleJanitor/README.md @@ -0,0 +1,5 @@ +# ConsoleJanitor + +Disables annoying console messages/errors. This plugin mainly removes errors/warnings that happen all the time and noisy/spammy logging messages. + +Some of the disabled messages include the "notosans-400-normalitalic" error and MessageActionCreators, Routing/Utils loggers. diff --git a/src/plugins/consoleJanitor/index.ts b/src/plugins/consoleJanitor/index.ts new file mode 100644 index 000000000..30887f5a7 --- /dev/null +++ b/src/plugins/consoleJanitor/index.ts @@ -0,0 +1,152 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { definePluginSettings } from "@api/Settings"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; + +const Noop = () => { }; +const NoopLogger = { + logDangerously: Noop, + log: Noop, + verboseDangerously: Noop, + verbose: Noop, + info: Noop, + warn: Noop, + error: Noop, + trace: Noop, + time: Noop, + fileOnly: Noop +}; + +const settings = definePluginSettings({ + disableNoisyLoggers: { + type: OptionType.BOOLEAN, + description: "Disable noisy loggers like the MessageActionCreators", + default: false, + restartNeeded: true + }, + disableSpotifyLogger: { + type: OptionType.BOOLEAN, + description: "Disable the Spotify logger, which leaks account information and access token", + default: true, + restartNeeded: true + } +}); + +export default definePlugin({ + name: "ConsoleJanitor", + description: "Disables annoying console messages/errors", + authors: [Devs.Nuckyz], + settings, + + NoopLogger: () => NoopLogger, + + patches: [ + { + find: 'console.warn("Window state not initialized"', + replacement: { + match: /console\.warn\("Window state not initialized",\i\),/, + replace: "" + } + }, + { + find: "is not a valid locale.", + replacement: { + match: /\i\.error\(""\.concat\(\i," is not a valid locale."\)\);/, + replace: "" + } + }, + { + find: "notosans-400-normalitalic", + replacement: { + match: /,"notosans-.+?"/g, + replace: "" + } + }, + { + find: 'console.warn("[DEPRECATED] Please use `subscribeWithSelector` middleware");', + all: true, + replacement: { + match: /console\.warn\("\[DEPRECATED\] Please use `subscribeWithSelector` middleware"\);/, + replace: "" + } + }, + { + find: "RPCServer:WSS", + replacement: { + match: /\i\.error\("Error: "\.concat\((\i)\.message/, + replace: '!$1.message.includes("EADDRINUSE")&&$&' + } + }, + { + find: "Tried getting Dispatch instance before instantiated", + replacement: { + match: /null==\i&&\i\.warn\("Tried getting Dispatch instance before instantiated"\),/, + replace: "" + } + }, + { + find: "Unable to determine render window for element", + replacement: { + match: /console\.warn\("Unable to determine render window for element",\i\),/, + replace: "" + } + }, + { + find: "failed to send analytics events", + replacement: { + match: /console\.error\("\[analytics\] failed to send analytics events query: "\.concat\(\i\)\)/, + replace: "" + } + }, + { + find: "Slow dispatch on", + replacement: { + match: /\i\.totalTime>100&&\i\.verbose\("Slow dispatch on ".+?\)\);/, + replace: "" + } + }, + ...[ + '("MessageActionCreators")', '("ChannelMessages")', + '("Routing/Utils")', '("RTCControlSocket")', + '("ConnectionEventFramerateReducer")', '("RTCLatencyTestManager")', + '("OverlayBridgeStore")', '("RPCServer:WSS")' + ].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}` + } + })), + { + find: '"Experimental codecs: "', + predicate: () => settings.store.disableNoisyLoggers, + replacement: { + match: /new \i\.\i\("Connection\("\.concat\(\i,"\)"\)\)/, + replace: "$self.NoopLogger()" + } + }, + { + find: '"Handling ping: "', + predicate: () => settings.store.disableNoisyLoggers, + replacement: { + match: /new \i\.\i\("RTCConnection\("\.concat.+?\)\)(?=,)/, + replace: "$self.NoopLogger()" + } + }, + { + find: '("Spotify")', + predicate: () => settings.store.disableSpotifyLogger, + replacement: { + match: /new \i\.\i\("Spotify"\)/, + replace: "$self.NoopLogger()" + } + } + ] +}); diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 9268051ff..e6caf7340 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -59,11 +59,15 @@ export function addPatch(newPatch: Omit, pluginName: string) { delete patch.group; } + if (patch.predicate && !patch.predicate()) return; + canonicalizeFind(patch); if (!Array.isArray(patch.replacement)) { patch.replacement = [patch.replacement]; } + patch.replacement = patch.replacement.filter(({ predicate }) => !predicate || predicate()); + if (IS_REPORTER) { patch.replacement.forEach(r => { delete r.predicate; diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index 4b3b28a8e..f32aeb789 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -259,7 +259,6 @@ function patchFactories(factories: Record