diff --git a/Plugins/DoNotTrack/DoNotTrack.plugin.js b/Plugins/DoNotTrack/DoNotTrack.plugin.js index 8fc1ae0..a9040cc 100644 --- a/Plugins/DoNotTrack/DoNotTrack.plugin.js +++ b/Plugins/DoNotTrack/DoNotTrack.plugin.js @@ -97,26 +97,29 @@ module.exports = !global.ZeresPluginLibrary ? Dummy : (([Plugin, Api]) => { const plugin = (Plugin, Api) => { const {Patcher, WebpackModules, Modals} = Api; - const SettingsManager = WebpackModules.getByProps("ShowCurrentGame"); + const SettingsManager = WebpackModules.getModule(m => m?.updateAsync, {searchExports: true}); + const BoolSetting = WebpackModules.getModule(m => m?.typeName?.includes("Bool"), {searchExports: true}); const Analytics = WebpackModules.getByProps("AnalyticEventConfigs"); + const NativeModule = WebpackModules.getByProps("getDiscordUtils"); return class DoNotTrack extends Plugin { onStart() { Patcher.instead(Analytics.default, "track", () => {}); + Patcher.instead(NativeModule, "ensureModule", (_, [moduleName], originalFunction) => { + if (moduleName.includes("discord_rpc")) return; + return originalFunction(moduleName); + }); + + // No more global processors + window.__SENTRY__.globalEventProcessors.splice(0, window.__SENTRY__.globalEventProcessors.length); - const Logger = window.__SENTRY__.logger; - Logger.disable(); // Kill sentry logs + // Kill sentry logs + window.__SENTRY__.logger.disable(); const SentryHub = window.DiscordSentry.getCurrentHub(); SentryHub.getClient().close(0); // Kill reporting - SentryHub.getStackTop().scope.clear(); // Delete PII - - /* eslint-disable no-console */ - for (const method in console) { - if (!console[method].__sentry_original__) continue; - console[method] = console[method].__sentry_original__; - } + SentryHub.getScope().clear(); // Delete PII if (this.settings.stopProcessMonitor) this.disableProcessMonitor(); } @@ -126,20 +129,19 @@ module.exports = !global.ZeresPluginLibrary ? Dummy : (([Plugin, Api]) => { } disableProcessMonitor() { - SettingsManager?.ShowCurrentGame?.updateSetting(false); - const NativeModule = WebpackModules.getByProps("getDiscordUtils"); + SettingsManager?.updateAsync("status", settings => settings.showCurrentGame = BoolSetting.create({value: false})); const DiscordUtils = NativeModule.getDiscordUtils(); - DiscordUtils.setObservedGamesCallback([], () => {}); + const original = DiscordUtils.setObservedGamesCallback; + Patcher.instead(DiscordUtils, "setObservedGamesCallback", () => {}); + setTimeout(() => original([], () => {}), 3000); // Delay this in case there's a boot order issue } enableProcessMonitor() { - SettingsManager?.ShowCurrentGame?.updateSetting(true); + SettingsManager?.updateAsync("status", settings => settings.showCurrentGame = BoolSetting.create({value: true})); Modals.showConfirmationModal("Reload Discord?", "To reenable the process monitor Discord needs to be reloaded.", { confirmText: "Reload", cancelText: "Later", - onConfirm: () => { - window.location.reload(); - } + onConfirm: () => window.location.reload() }); } diff --git a/src/plugins/DoNotTrack/config.json b/src/plugins/DoNotTrack/config.json index 9be5d2b..7fa711b 100644 --- a/src/plugins/DoNotTrack/config.json +++ b/src/plugins/DoNotTrack/config.json @@ -7,7 +7,7 @@ "github_username": "rauenzi", "twitter_username": "ZackRauen" }], - "version": "0.0.8", + "version": "0.0.9", "description": "Stops Discord from tracking everything you do like Sentry and Analytics.", "github": "https://github.com/rauenzi/BetterDiscordAddons/tree/master/Plugins/DoNotTrack", "github_raw": "https://raw.githubusercontent.com/rauenzi/BetterDiscordAddons/master/Plugins/DoNotTrack/DoNotTrack.plugin.js" diff --git a/src/plugins/DoNotTrack/index.js b/src/plugins/DoNotTrack/index.js index 5e543a5..9ef7224 100644 --- a/src/plugins/DoNotTrack/index.js +++ b/src/plugins/DoNotTrack/index.js @@ -5,26 +5,29 @@ module.exports = (Plugin, Api) => { const {Patcher, WebpackModules, Modals} = Api; - const SettingsManager = WebpackModules.getByProps("ShowCurrentGame"); + const SettingsManager = WebpackModules.getModule(m => m?.updateAsync, {searchExports: true}); + const BoolSetting = WebpackModules.getModule(m => m?.typeName?.includes("Bool"), {searchExports: true}); const Analytics = WebpackModules.getByProps("AnalyticEventConfigs"); + const NativeModule = WebpackModules.getByProps("getDiscordUtils"); return class DoNotTrack extends Plugin { onStart() { Patcher.instead(Analytics.default, "track", () => {}); + Patcher.instead(NativeModule, "ensureModule", (_, [moduleName], originalFunction) => { + if (moduleName.includes("discord_rpc")) return; + return originalFunction(moduleName); + }); + + // No more global processors + window.__SENTRY__.globalEventProcessors.splice(0, window.__SENTRY__.globalEventProcessors.length); - const Logger = window.__SENTRY__.logger; - Logger.disable(); // Kill sentry logs + // Kill sentry logs + window.__SENTRY__.logger.disable(); const SentryHub = window.DiscordSentry.getCurrentHub(); SentryHub.getClient().close(0); // Kill reporting - SentryHub.getStackTop().scope.clear(); // Delete PII - - /* eslint-disable no-console */ - for (const method in console) { - if (!console[method].__sentry_original__) continue; - console[method] = console[method].__sentry_original__; - } + SentryHub.getScope().clear(); // Delete PII if (this.settings.stopProcessMonitor) this.disableProcessMonitor(); } @@ -34,20 +37,19 @@ module.exports = (Plugin, Api) => { } disableProcessMonitor() { - SettingsManager?.ShowCurrentGame?.updateSetting(false); - const NativeModule = WebpackModules.getByProps("getDiscordUtils"); + SettingsManager?.updateAsync("status", settings => settings.showCurrentGame = BoolSetting.create({value: false})); const DiscordUtils = NativeModule.getDiscordUtils(); - DiscordUtils.setObservedGamesCallback([], () => {}); + const original = DiscordUtils.setObservedGamesCallback; + Patcher.instead(DiscordUtils, "setObservedGamesCallback", () => {}); + setTimeout(() => original([], () => {}), 3000); // Delay this in case there's a boot order issue } enableProcessMonitor() { - SettingsManager?.ShowCurrentGame?.updateSetting(true); + SettingsManager?.updateAsync("status", settings => settings.showCurrentGame = BoolSetting.create({value: true})); Modals.showConfirmationModal("Reload Discord?", "To reenable the process monitor Discord needs to be reloaded.", { confirmText: "Reload", cancelText: "Later", - onConfirm: () => { - window.location.reload(); - } + onConfirm: () => window.location.reload() }); }