添加启动日志记录

This commit is contained in:
lyswhut 2023-06-09 10:36:49 +08:00
parent 3b1eab3381
commit 27f7cc57ed
3 changed files with 33 additions and 1 deletions

View File

@ -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() {

View File

@ -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()

11
src/utils/bootLog.ts Normal file
View File

@ -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')
}