chore(lib/init): make runCatching actually only run-catching

This commit is contained in:
PalmDevs 2025-04-29 23:58:23 +07:00
parent f19c8e925a
commit dcbdd97000
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA

View file

@ -8,18 +8,16 @@ import { getErrorStack } from '@revenge-mod/utils/errors'
import { logger } from './shared'
onModuleFirstRequired(
0,
runCatching(function onceIndexRequired() {
onModuleFirstRequired(0, function onceIndexRequired() {
runCatching(() => {
if (!__BUILD_FLAG_INIT_DISABLE_PATCH_LOG_PROMISE_REJECTIONS__) require('./patches/log-promise-rejections')
// Initialize preinit libraries
require('@revenge-mod/modules/preinit')
require('@revenge-mod/react/preinit')
onModuleInitialized(
0,
runCatching(function onceIndexInitialized() {
onModuleInitialized(0, function onceIndexInitialized() {
runCatching(() => {
// Register all plugins
require('@plugins/all')
@ -34,28 +32,26 @@ onModuleFirstRequired(
gc()
gc()
})
}),
})
})
})
})
function runCatching(fn: () => void) {
try {
fn()
} catch (e) {
const { ClientInfoModule, DeviceModule } = require('@revenge-mod/discord/native') as
// biome-ignore format: Don't format this please
typeof import('@revenge-mod/discord/native')
// TODO(init): Move to use native module
alert(
// biome-ignore lint/style/useTemplate: I want this to be readable, thank you
'Failed to load Revenge!\n' +
`Discord: ${ClientInfoModule.Version} (${ClientInfoModule.Build})\n` +
`Device: ${DeviceModule.deviceManufacturer} ${DeviceModule.deviceModel}\n\n` +
getErrorStack(e),
)
}),
)
function runCatching<F extends (...args: any[]) => any>(fn: F) {
return (...args: Parameters<F>) => {
try {
fn(...args)
} catch (e) {
const { ClientInfoModule, DeviceModule } = require('@revenge-mod/discord/native') as
// biome-ignore format: Don't format this please
typeof import('@revenge-mod/discord/native')
// TODO(init): Move to use native module
alert(
// biome-ignore lint/style/useTemplate: I want this to be readable, thank you
'Failed to load Revenge!\n' +
`Discord: ${ClientInfoModule.Version} (${ClientInfoModule.Build})\n` +
`Device: ${DeviceModule.deviceManufacturer} ${DeviceModule.deviceModel}\n\n` +
getErrorStack(e),
)
}
}
}