From dd0ee59f945c0a4c6c491c9f7d9339e8d7b6f5bf Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Wed, 9 Jul 2025 20:15:46 +0700 Subject: [PATCH] feat(plugins/no-track): improve sentry blocking, noop `AnalyticsTrackActionCreators` --- src/plugins/preinit/no-track/index.ts | 40 +++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/plugins/preinit/no-track/index.ts b/src/plugins/preinit/no-track/index.ts index c62016a..a5508f8 100644 --- a/src/plugins/preinit/no-track/index.ts +++ b/src/plugins/preinit/no-track/index.ts @@ -1,5 +1,7 @@ +import { DispatcherModuleId } from '@revenge-mod/discord/common/flux' import { byProps } from '@revenge-mod/modules/finders/filters' import { waitForModules } from '@revenge-mod/modules/finders/wait' +import { getModuleDependencies } from '@revenge-mod/modules/metro/utils' import { instead } from '@revenge-mod/patcher' import { InternalPluginFlags, registerPlugin } from '@revenge-mod/plugins/_' import { PluginFlags } from '@revenge-mod/plugins/constants' @@ -30,7 +32,27 @@ registerPlugin( }, ) - cleanup(unsubSIU) + // Discord uses ReactNavigationInstrumentation to track navigation + const unsubSentry = waitForModules( + byProps('ReactNavigationInstrumentation'), + exports => { + unsubSentry() + + console.log('Patching ReactNavigationInstrumentation...') + exports.ReactNavigationInstrumentation = class { + // https://docs.sentry.io/platforms/react-native/tracing/instrumentation/react-navigation/#initialization + registerNavigationContainer = noop + } + }, + ) + + // Make sure __SENTRY__ can never be set + Object.defineProperty(globalThis, '__SENTRY__', { + writable: false, + configurable: false, + }) + + cleanup(unsubSIU, unsubSentry) }, init({ cleanup, logger }) { // utils/AnalyticsUtils.tsx @@ -58,6 +80,7 @@ registerPlugin( ) }, ) + // modules/app_analytics/useTrackImpression.tsx const unsubTI = waitForModules( byProps<{ @@ -74,7 +97,20 @@ registerPlugin( }, ) - cleanup(unsubAU, unsubTI) + // actions/AnalyticsTrackActionCreators.tsx + const unsubATAC = waitForModules( + byProps('track'), + (AnalyticsTrackActionCreators, id) => { + if (getModuleDependencies(id)![0] === DispatcherModuleId) { + unsubATAC() + + logger.info('Patching AnalyticsTrackActionCreators...') + instead(AnalyticsTrackActionCreators, 'track', noop) + } + }, + ) + + cleanup(unsubAU, unsubTI, unsubATAC) }, stop({ plugin }) { plugin.flags |= PluginFlags.ReloadRequired