Skip to content

Commit

Permalink
Update DNT
Browse files Browse the repository at this point in the history
- Fixes #710
- Fixes #186
- Fixes #465
- Fixes #417
  • Loading branch information
zerebos committed Apr 16, 2023
1 parent 24e3501 commit e75f77c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
36 changes: 19 additions & 17 deletions Plugins/DoNotTrack/DoNotTrack.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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()
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/DoNotTrack/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
36 changes: 19 additions & 17 deletions src/plugins/DoNotTrack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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()
});
}

Expand Down

0 comments on commit e75f77c

Please sign in to comment.