chore(plugins): merge error-boundary into recovery
This commit is contained in:
parent
e47ba711f4
commit
cad8e1fa7d
3 changed files with 57 additions and 73 deletions
|
|
@ -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<typeof DiscordErrorBoundary>('ErrorBoundary'),
|
||||
exports => {
|
||||
unsubEB()
|
||||
|
||||
instead(
|
||||
exports.prototype,
|
||||
'render',
|
||||
function (this: DiscordErrorBoundary) {
|
||||
if (this.state.error)
|
||||
return (
|
||||
<ErrorBoundaryScreen
|
||||
error={this.state.error}
|
||||
reload={this.handleReload.bind(this)}
|
||||
rerender={() => {
|
||||
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
|
||||
}
|
||||
|
|
@ -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<typeof DiscordErrorBoundary>('ErrorBoundary'),
|
||||
exports => {
|
||||
unsub()
|
||||
|
||||
instead(
|
||||
exports.prototype,
|
||||
'render',
|
||||
function (this: DiscordErrorBoundary) {
|
||||
if (this.state.error)
|
||||
return (
|
||||
<ErrorBoundaryScreen
|
||||
error={this.state.error}
|
||||
reload={this.handleReload.bind(this)}
|
||||
rerender={() => {
|
||||
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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue