diff --git a/src/plugins/start/error-boundary/index.tsx b/src/plugins/start/error-boundary/index.tsx deleted file mode 100644 index d419ab9..0000000 --- a/src/plugins/start/error-boundary/index.tsx +++ /dev/null @@ -1,72 +0,0 @@ -import { waitForModules } from '@revenge-mod/modules/finders' -import { withName } from '@revenge-mod/modules/finders/filters' -import { instead } from '@revenge-mod/patcher' -import { - InternalPluginFlags, - PluginFlags, - registerInternalPlugin, -} from '@revenge-mod/plugins/_' -import ErrorBoundaryScreen from './components/ErrorBoundaryScreen' -import type { Component, ReactNode } from 'react' - -registerInternalPlugin( - { - id: 'revenge.error-boundary', - name: 'Error Boundary', - description: 'Shows debug information on rendering crashes.', - author: 'Revenge', - icon: 'ScreenXIcon', - }, - { - start({ cleanup }) { - const unsubEB = waitForModules( - withName('ErrorBoundary'), - exports => { - unsubEB() - - instead( - exports.prototype, - 'render', - function (this: DiscordErrorBoundary) { - if (this.state.error) - return ( - { - this.setState({ - error: null, - info: null, - }) - }} - /> - ) - - return this.props.children - }, - ) - }, - { - cached: true, - }, - ) - - cleanup(unsubEB) - }, - }, - PluginFlags.Enabled, - InternalPluginFlags.Internal | InternalPluginFlags.Essential, -) - -declare class DiscordErrorBoundary extends Component< - { children: ReactNode }, - { - error: (Error & { componentStack?: string }) | unknown | null - info: { componentStack?: string } | null - } -> { - // render() is always called with `this` as the instance of DiscordErrorBoundary - render(this: DiscordErrorBoundary): ReactNode - discordErrorsSet: boolean - handleReload(): void -} diff --git a/src/plugins/start/error-boundary/components/ErrorBoundaryScreen.tsx b/src/plugins/start/recovery/components/ErrorBoundaryScreen.tsx similarity index 100% rename from src/plugins/start/error-boundary/components/ErrorBoundaryScreen.tsx rename to src/plugins/start/recovery/components/ErrorBoundaryScreen.tsx diff --git a/src/plugins/start/recovery/index.tsx b/src/plugins/start/recovery/index.tsx index 188c282..a2de34b 100644 --- a/src/plugins/start/recovery/index.tsx +++ b/src/plugins/start/recovery/index.tsx @@ -6,7 +6,10 @@ import { onSettingsModulesLoaded, registerSettingsItem, } from '@revenge-mod/discord/modules/settings' +import { waitForModules } from '@revenge-mod/modules/finders' +import { withName } from '@revenge-mod/modules/finders/filters' import { callNativeMethod, getBridgeInfo } from '@revenge-mod/modules/native' +import { instead } from '@revenge-mod/patcher' import { InternalPluginFlags, isDefaultsOnlyBoot, @@ -22,7 +25,9 @@ import { mErrorChain } from '../../../../lib/modules/src/metro/runtime' import pluginSettings from '../settings' import { Setting } from '../settings/constants' import { RouteNames } from '../settings.plugins/constants' +import ErrorBoundaryScreen from './components/ErrorBoundaryScreen' import RevengeEnterRecoveryModeSetting from './definitions/RevengeEnterRecoveryModeSetting' +import type { Component, ReactNode } from 'react' registerInternalPlugin( { @@ -35,7 +40,7 @@ registerInternalPlugin( dependencies: { [pluginSettings]: {} }, }, { - start() { + start({ cleanup }) { onSettingsModulesLoaded(() => { registerSettingsItem( Setting.RevengeEnterRecoveryMode, @@ -43,6 +48,8 @@ registerInternalPlugin( ) }) + cleanup(errorBoundaryService()) + freezeDetectionService() if (isDefaultsOnlyBoot) { @@ -114,6 +121,55 @@ function freezeDetectionService() { const unsub = onFluxEventDispatched('APP_STATE_UPDATE', clear) } +function errorBoundaryService() { + const unsub = waitForModules( + withName('ErrorBoundary'), + exports => { + unsub() + + instead( + exports.prototype, + 'render', + function (this: DiscordErrorBoundary) { + if (this.state.error) + return ( + { + this.setState({ + error: null, + info: null, + }) + }} + /> + ) + + return this.props.children + }, + ) + }, + { + cached: true, + }, + ) + + return unsub +} + +declare class DiscordErrorBoundary extends Component< + { children: ReactNode }, + { + error: (Error & { componentStack?: string }) | unknown | null + info: { componentStack?: string } | null + } +> { + // render() is always called with `this` as the instance of DiscordErrorBoundary + render(this: DiscordErrorBoundary): ReactNode + discordErrorsSet: boolean + handleReload(): void +} + function RecoveryModal() { const navigation = RootNavigationRef.getRootNavigationRef()