forked from lyswhut/lx-music-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
158 lines (143 loc) · 4.88 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* @format
*/
// import '@/utils/log'
import './shim'
import '@/utils/errorHandle'
import { init as initLog, log } from '@/utils/log'
import '@/config/globalData'
import SplashScreen from 'react-native-splash-screen'
import { init as initNavigation, navigations, showPactModal } from '@/navigation'
import { registerPlaybackService } from '@/plugins/player'
import { getStore } from '@/store'
import { action as commonAction } from '@/store/modules/common'
import { action as playerAction } from '@/store/modules/player'
import { action as listAction } from '@/store/modules/list'
import { init as initMusicTools } from '@/utils/music'
import { init as initLyric, toggleTranslation, toggleRoma } from '@/utils/lyric'
import { showLyric, onPositionChange } from '@/utils/lyricDesktop'
import { init as initI18n, supportedLngs } from '@/plugins/i18n'
import { deviceLanguage, getPlayInfo, toast, onAppearanceChange, getIsSupportedAutoTheme, getAppearance } from '@/utils/tools'
import { LIST_ID_PLAY_TEMP } from '@/config/constant'
import { connect, SYNC_CODE } from '@/plugins/sync'
console.log('starting app...')
let store
let isInited = false
let isFirstRun = true
initLog()
const init = () => {
if (isInited) return Promise.resolve()
isInited = true
store = getStore()
// console.log('deviceLanguage', deviceLanguage)
return Promise.all([
store.dispatch(commonAction.initSetting()),
store.dispatch(listAction.initList()),
initLyric(),
registerPlaybackService(),
]).then(() => {
let setting = store.getState().common.setting
if (getIsSupportedAutoTheme()) {
onAppearanceChange(color => {
store.dispatch(commonAction.setSystemColor(color))
})
}
toggleTranslation(setting.player.isShowLyricTranslation)
toggleRoma(setting.player.isShowLyricRoma)
if (setting.sync.enable) {
connect().catch(err => {
if (err.message == SYNC_CODE.unknownServiceAddress) {
store.dispatch(commonAction.setIsEnableSync(false))
}
})
}
if (setting.desktopLyric.enable) {
showLyric({
isShowToggleAnima: setting.desktopLyric.showToggleAnima,
isSingleLine: setting.desktopLyric.isSingleLine,
isLock: setting.desktopLyric.isLock,
themeId: setting.desktopLyric.theme,
opacity: setting.desktopLyric.style.opacity,
textSize: setting.desktopLyric.style.fontSize,
width: setting.desktopLyric.width,
maxLineNum: setting.desktopLyric.maxLineNum,
positionX: setting.desktopLyric.position.x,
positionY: setting.desktopLyric.position.y,
textPositionX: setting.desktopLyric.textPosition.x,
textPositionY: setting.desktopLyric.textPosition.y,
}).catch(() => {
store.dispatch(commonAction.setIsShowDesktopLyric(false))
})
}
onPositionChange(position => {
store.dispatch(commonAction.setDesktopLyricPosition(position))
})
let lang = setting.langId
let needSetLang = false
if (!supportedLngs.includes(lang)) {
if (typeof deviceLanguage == 'string' && supportedLngs.includes(deviceLanguage)) {
lang = deviceLanguage
} else {
lang = 'en_us'
}
needSetLang = true
}
console.log(lang)
return initI18n(lang).then(() => {
if (needSetLang) return store.dispatch(commonAction.setLang(lang))
})
// .catch(_ => _)
// StatusBar.setHidden(false)
// console.log('init')
}).then(() => {
initMusicTools()
getPlayInfo().then(info => {
if (!info) return
if (info.listId != LIST_ID_PLAY_TEMP) {
info.list = global.allList[info.listId]
if (info.list) info.list = info.list.list
}
if (!info.list || !info.list[info.index]) {
const info2 = { ...info }
if (info2.list) {
info2.music = info2.list[info2.index]?.name
info2.list = info2.list.length
}
toast('恢复播放数据失败,请去错误日志查看', 'long')
log.warn('Restore Play Info failed: ', JSON.stringify(info2, null, 2))
return
}
let setting = store.getState().common.setting
global.restorePlayInfo = {
info,
startupAutoPlay: setting.startupAutoPlay,
}
store.dispatch(playerAction.setList({
list: {
list: info.list,
id: info.listId,
},
index: info.index,
}))
})
})
}
initNavigation(() => {
init().then(() => {
if (getIsSupportedAutoTheme()) store.dispatch(commonAction.setSystemColor(getAppearance()))
return navigations.pushHomeScreen().then(() => {
SplashScreen.hide()
if (store.getState().common.setting.isAgreePact) {
if (isFirstRun) {
isFirstRun = false
store.dispatch(commonAction.checkVersion())
}
} else {
if (isFirstRun) isFirstRun = false
showPactModal()
}
})
}).catch(err => {
toast(err.stack, 'long')
})
})