This commit is contained in:
lyswhut
2022-10-29 11:36:35 +08:00
parent 66b965d9f7
commit e45cee6596
715 changed files with 57096 additions and 31771 deletions
+44
View File
@@ -0,0 +1,44 @@
import { getPlayInfo } from '@renderer/utils/ipc'
import music from '@renderer/utils/musicSdk'
import { log } from '@common/utils'
import { getListMusics, getUserLists, registerAction } from '@renderer/store/list/action'
import useInitUserApi from './useInitUserApi'
import { play, playList } from '@renderer/core/player'
import { onBeforeUnmount } from '@common/utils/vueTools'
import { appSetting } from '@renderer/store/setting'
const initPrevPlayInfo = async() => {
const info = await getPlayInfo()
window.lx.restorePlayInfo = null
if (!info?.listId || info.index < 0) return
const list = await getListMusics(info.listId)
if (!list || !list[info.index]) return
window.lx.restorePlayInfo = info
playList(info.listId, info.index)
if (appSetting['player.startupAutoPlay']) setTimeout(play)
}
export default () => {
const initUserApi = useInitUserApi()
let unregister: null | (() => void) = null
onBeforeUnmount(() => {
if (unregister) unregister()
})
return async() => {
await Promise.all([
initUserApi(), // 自定义API
]).catch(err => log.error(err))
void music.init() // 初始化音乐sdk
unregister = registerAction((ids) => {
window.app_event.myListUpdate(ids)
})
window.lxData.userLists = await getUserLists() // 获取用户列表
await initPrevPlayInfo().catch(err => log.error(err)) // 初始化上次的歌曲播放信息
}
}