mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-07-06 21:22:07 +08:00
添加启动日志记录
This commit is contained in:
12
src/app.ts
12
src/app.ts
@ -1,5 +1,6 @@
|
|||||||
import '@/utils/errorHandle'
|
import '@/utils/errorHandle'
|
||||||
import { init as initLog } from '@/utils/log'
|
import { init as initLog } from '@/utils/log'
|
||||||
|
import { bootLog, getBootLog } from '@/utils/bootLog'
|
||||||
import '@/config/globalData'
|
import '@/config/globalData'
|
||||||
import { init as initNavigation, navigations } from '@/navigation'
|
import { init as initNavigation, navigations } from '@/navigation'
|
||||||
import { getFontSize } from '@/utils/data'
|
import { getFontSize } from '@/utils/data'
|
||||||
@ -10,15 +11,24 @@ console.log('starting app...')
|
|||||||
let isInited = false
|
let isInited = false
|
||||||
let handlePushedHomeScreen: () => void
|
let handlePushedHomeScreen: () => void
|
||||||
|
|
||||||
|
const tryGetBootLog = () => {
|
||||||
|
try {
|
||||||
|
return getBootLog()
|
||||||
|
} catch (err) {
|
||||||
|
return 'Get boot log failed.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleInit = async() => {
|
const handleInit = async() => {
|
||||||
if (isInited) return
|
if (isInited) return
|
||||||
void initLog()
|
void initLog()
|
||||||
global.lx.fontSize = await getFontSize()
|
global.lx.fontSize = await getFontSize()
|
||||||
|
bootLog('Font size setting loaded.')
|
||||||
const { default: init } = await import('@/core/init')
|
const { default: init } = await import('@/core/init')
|
||||||
try {
|
try {
|
||||||
handlePushedHomeScreen = await init()
|
handlePushedHomeScreen = await init()
|
||||||
} catch (err: any) {
|
} 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',
|
text: 'Exit',
|
||||||
onPress() {
|
onPress() {
|
||||||
|
@ -10,6 +10,7 @@ import { setUserApi } from '@/core/apiSource'
|
|||||||
import commonActions from '@/store/common/action'
|
import commonActions from '@/store/common/action'
|
||||||
import settingState from '@/store/setting/state'
|
import settingState from '@/store/setting/state'
|
||||||
import { checkUpdate } from '@/core/version'
|
import { checkUpdate } from '@/core/version'
|
||||||
|
import { bootLog } from '@/utils/bootLog'
|
||||||
|
|
||||||
let isFirstPush = true
|
let isFirstPush = true
|
||||||
const handlePushedHomeScreen = () => {
|
const handlePushedHomeScreen = () => {
|
||||||
@ -27,20 +28,30 @@ const handlePushedHomeScreen = () => {
|
|||||||
let isInited = false
|
let isInited = false
|
||||||
export default async() => {
|
export default async() => {
|
||||||
if (isInited) return handlePushedHomeScreen
|
if (isInited) return handlePushedHomeScreen
|
||||||
|
bootLog('Initing...')
|
||||||
commonActions.setFontSize(global.lx.fontSize)
|
commonActions.setFontSize(global.lx.fontSize)
|
||||||
|
bootLog('Font size changed.')
|
||||||
const setting = await initSetting()
|
const setting = await initSetting()
|
||||||
|
bootLog('Setting inited.')
|
||||||
// console.log(setting)
|
// console.log(setting)
|
||||||
|
|
||||||
await initTheme(setting)
|
await initTheme(setting)
|
||||||
|
bootLog('Theme inited.')
|
||||||
await initI18n(setting)
|
await initI18n(setting)
|
||||||
|
bootLog('I18n inited.')
|
||||||
|
|
||||||
setUserApi(setting['common.apiSource'])
|
setUserApi(setting['common.apiSource'])
|
||||||
|
bootLog('Api inited.')
|
||||||
|
|
||||||
registerPlaybackService()
|
registerPlaybackService()
|
||||||
|
bootLog('Playback Service Registered.')
|
||||||
await initPlayer(setting)
|
await initPlayer(setting)
|
||||||
|
bootLog('Player inited.')
|
||||||
await dataInit(setting)
|
await dataInit(setting)
|
||||||
|
bootLog('Data inited.')
|
||||||
|
|
||||||
void initSync(setting)
|
void initSync(setting)
|
||||||
|
bootLog('Sync inited.')
|
||||||
|
|
||||||
// syncSetting()
|
// syncSetting()
|
||||||
|
|
||||||
|
11
src/utils/bootLog.ts
Normal file
11
src/utils/bootLog.ts
Normal 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')
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user