BREAKING CHANGES: - lib/modules!: Renamed `callBridgeMethod*` to `callNativeMethod*` and interface `Methods` to `NativeMethods`. This is to achieve naming consistency with the native API and be more clear. - lib/storage!: Renamed to `@revenge-mod/json-storage`. A storage can be in any arbitrary format. While there's little potential for non-JSON storage formats, but the naming should allow for it regardless. This is not a drop-in replacements. There are breaking changes in export names and new APIs. - plugins/revenge.api.storage!: Renamed to `revenge.api.jsonStorage`. Plugin options are renamed and its structure has changed as well. - Native now holds the path for official storage APIs. This update uses new paths without any migration! - lib/plugins!: `Plugin.errors` is now read-only. Use `Plugin.reportError(e)` instead. - lib/plugins!: `Plugin.flags` has been completely removed in favor of these methods: `Plugin.requireReload()`, `Plugin.disable()`. OTHER CHANGES: - Fixed sorting for 'Enabled first' - Updated native method names to be more consistent - Cleand up dead code - Make methods more 'safe' by removing non-null assertion casts
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { callNativeMethod } from '@revenge-mod/modules/native'
|
|
import { getErrorStack } from '@revenge-mod/utils/error'
|
|
import { BuildEnvironment, FullVersion } from '~constants'
|
|
import type { Metro } from '@revenge-mod/modules/types'
|
|
|
|
// @ts-expect-error
|
|
globalThis.ErrorUtils = {
|
|
// RN JSI only requires these two properties:
|
|
// https://github.com/facebook/react-native/blob/802e1a7/packages/react-native/ReactCommon/cxxreact/ErrorUtils.h#L18-L19
|
|
reportError: onError,
|
|
reportFatalError: onError,
|
|
}
|
|
|
|
Object.defineProperty(globalThis, '__registerSegment', {
|
|
configurable: true,
|
|
set(registerSegment: Metro.RegisterSegmentFn) {
|
|
// @ts-expect-error
|
|
// biome-ignore lint/performance/noDelete: Prevent infinite set loop
|
|
delete globalThis.__registerSegment
|
|
globalThis.__registerSegment = registerSegment
|
|
|
|
// @as-require
|
|
import('./preinit')
|
|
},
|
|
})
|
|
|
|
export function onError(error: unknown) {
|
|
const stack = getErrorStack(error)
|
|
|
|
callNativeMethod('revenge.alertError', [
|
|
stack,
|
|
`${FullVersion} (${BuildEnvironment})`,
|
|
])
|
|
|
|
nativeLoggingHook(`\u001b[31m${stack}\u001b[0m`, 2)
|
|
}
|
|
|
|
declare module '@revenge-mod/modules/native' {
|
|
export interface NativeMethods {
|
|
'revenge.alertError': [[error: string, version: string], void]
|
|
}
|
|
}
|