feat: use native bridge for alerting errors
This commit is contained in:
parent
d33f68ebad
commit
5684fa9d8b
2 changed files with 16 additions and 15 deletions
|
|
@ -3,7 +3,7 @@ import '@revenge-mod/react/init'
|
||||||
import '@revenge-mod/storage/init'
|
import '@revenge-mod/storage/init'
|
||||||
|
|
||||||
import { onRunApplication } from '@revenge-mod/react/native'
|
import { onRunApplication } from '@revenge-mod/react/native'
|
||||||
import { onError } from './preinit'
|
import { onError } from '~preinit'
|
||||||
|
|
||||||
const unsub = onRunApplication(() => {
|
const unsub = onRunApplication(() => {
|
||||||
unsub()
|
unsub()
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@ import {
|
||||||
onModuleFirstRequired,
|
onModuleFirstRequired,
|
||||||
onModuleInitialized,
|
onModuleInitialized,
|
||||||
} from '@revenge-mod/modules/metro/subscriptions'
|
} from '@revenge-mod/modules/metro/subscriptions'
|
||||||
|
import { callBridgeMethod } from '@revenge-mod/modules/native'
|
||||||
import { getErrorStack } from '@revenge-mod/utils/error'
|
import { getErrorStack } from '@revenge-mod/utils/error'
|
||||||
import { BuildEnvironment, FullVersion } from './constants'
|
import { BuildEnvironment, FullVersion } from '~constants'
|
||||||
|
|
||||||
const IndexModuleId = 0
|
const IndexModuleId = 0
|
||||||
|
|
||||||
|
|
@ -49,19 +50,19 @@ onModuleFirstRequired(IndexModuleId, function onIndexRequired() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export function onError(e: unknown) {
|
export function onError(error: unknown) {
|
||||||
// TODO(init): Move to use native provided alert function, which will accept a string stack trace
|
const stack = getErrorStack(error) ?? String(error)
|
||||||
// Above will reduce the need for runCatching() to exist, as the code won't be able to be deduped any further
|
|
||||||
const { ClientInfoModule, DeviceModule } =
|
|
||||||
require('@revenge-mod/discord/native') as typeof import('@revenge-mod/discord/native')
|
|
||||||
|
|
||||||
const Client = ClientInfoModule.getConstants()
|
callBridgeMethod('revenge.alertError', [
|
||||||
const Device = DeviceModule.getConstants()
|
stack,
|
||||||
|
`${FullVersion} (${BuildEnvironment})`,
|
||||||
|
])
|
||||||
|
|
||||||
alert(
|
nativeLoggingHook(`\u001b[31m${stack}\u001b[0m`, 2)
|
||||||
`Failed to load Revenge (${FullVersion} (${BuildEnvironment}))\n` +
|
}
|
||||||
`Discord: ${Client.Version} (${Client.Build})\n` +
|
|
||||||
`Device: ${Device.deviceManufacturer} ${Device.deviceModel}\n\n` +
|
declare module '@revenge-mod/modules/native' {
|
||||||
getErrorStack(e),
|
export interface Methods {
|
||||||
)
|
'revenge.alertError': [[error: string, title?: string], void]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue