diff --git a/src/app.ts b/src/app.ts index eaaadaeb..e032496b 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,5 +1,6 @@ import '@/utils/errorHandle' import { init as initLog } from '@/utils/log' +import { bootLog, getBootLog } from '@/utils/bootLog' import '@/config/globalData' import { init as initNavigation, navigations } from '@/navigation' import { getFontSize } from '@/utils/data' @@ -10,15 +11,24 @@ console.log('starting app...') let isInited = false let handlePushedHomeScreen: () => void +const tryGetBootLog = () => { + try { + return getBootLog() + } catch (err) { + return 'Get boot log failed.' + } +} + const handleInit = async() => { if (isInited) return void initLog() global.lx.fontSize = await getFontSize() + bootLog('Font size setting loaded.') const { default: init } = await import('@/core/init') try { handlePushedHomeScreen = await init() } catch (err: any) { - Alert.alert('初始化失败 (Init Failed)', err.stack ?? err.message, [ + Alert.alert('初始化失败 (Init Failed)', `Boot Log:\n${tryGetBootLog()}\n\n${(err.stack ?? err.message) as string}`, [ { text: 'Exit', onPress() { diff --git a/src/core/init/index.ts b/src/core/init/index.ts index 03fdcc3d..37aa27bd 100644 --- a/src/core/init/index.ts +++ b/src/core/init/index.ts @@ -10,6 +10,7 @@ import { setUserApi } from '@/core/apiSource' import commonActions from '@/store/common/action' import settingState from '@/store/setting/state' import { checkUpdate } from '@/core/version' +import { bootLog } from '@/utils/bootLog' let isFirstPush = true const handlePushedHomeScreen = () => { @@ -27,20 +28,30 @@ const handlePushedHomeScreen = () => { let isInited = false export default async() => { if (isInited) return handlePushedHomeScreen + bootLog('Initing...') commonActions.setFontSize(global.lx.fontSize) + bootLog('Font size changed.') const setting = await initSetting() + bootLog('Setting inited.') // console.log(setting) await initTheme(setting) + bootLog('Theme inited.') await initI18n(setting) + bootLog('I18n inited.') setUserApi(setting['common.apiSource']) + bootLog('Api inited.') registerPlaybackService() + bootLog('Playback Service Registered.') await initPlayer(setting) + bootLog('Player inited.') await dataInit(setting) + bootLog('Data inited.') void initSync(setting) + bootLog('Sync inited.') // syncSetting() diff --git a/src/utils/bootLog.ts b/src/utils/bootLog.ts new file mode 100644 index 00000000..6b75bc02 --- /dev/null +++ b/src/utils/bootLog.ts @@ -0,0 +1,11 @@ +const logs: string[] = [] + + +export const bootLog = (...msgs: any[]) => { + logs.push(msgs.map(m => typeof m == 'string' ? m : JSON.stringify(m)).join(' ')) +} + +export const getBootLog = () => { + return logs.join('\n') +} +