迁移搜索、播放启动参数支持

pull/1050/head
lyswhut 2022-11-04 15:56:34 +08:00
parent 303d712860
commit 9bec54c454
5 changed files with 94 additions and 93 deletions

View File

@ -21,7 +21,7 @@ export default () => {
const id = decodeURIComponent(link)
const playListId = `${source}__${decodeURIComponent(link)}`
let list = (await getListDetail(id, source, 1)).list
if (playIndex != null && list.length > playIndex) {
if (playIndex == null || list.length > playIndex) {
isPlayingList = true
await setTempList(playListId, list)
playList(tempList.id, getListPlayIndex(list, playIndex))

View File

@ -6,7 +6,7 @@ import { appSetting } from '@renderer/store/setting'
import useSync from './useSync'
import useUpdate from './useUpdate'
import useDataInit from './useDataInit'
// import useHandleEnvParams from './useHandleEnvParams'
import useHandleEnvParams from './useHandleEnvParams'
import useEventListener from './useEventListener'
import useDeeplink from './useDeeplink'
import usePlayer from './usePlayer'
@ -29,7 +29,7 @@ export default () => {
const initSyncService = useSync()
useEventListener()
const initPlayer = usePlayer()
// const handleEnvParams = useHandleEnvParams()
const handleEnvParams = useHandleEnvParams()
const initData = useDataInit()
const initDeeplink = useDeeplink()
// const handleListAutoUpdate = useListAutoUpdate()
@ -61,7 +61,7 @@ export default () => {
// 初始化我的列表、下载列表等数据
void initData().then(() => {
initPlayer()
// handleEnvParams(envParams) // 处理传入的启动参数
handleEnvParams(envParams) // 处理传入的启动参数
void initDeeplink(envParams)
void initSyncService()
handleListAutoUpdate()

View File

@ -37,6 +37,7 @@ const useSearchMusic = () => {
if (isShowPlayerDetail.value) setShowPlayerDetail(false)
const sourceList = [...sources, 'all']
source = sourceList.includes(source) ? source : null
setTimeout(() => {
router.replace({
path: '/search',
query: {
@ -44,6 +45,7 @@ const useSearchMusic = () => {
source,
},
})
}, 500)
focusWindow()
}
}

View File

@ -1,90 +1,89 @@
// import { useRouter } from '@common/utils/vueTools'
// import { parseUrlParams } from '@common/utils/renderer'
// import { defaultList, loveList, userLists } from '@renderer/store/list'
// import { getList } from '@renderer/store/utils'
// import usePlaySonglist from './compositions/usePlaySonglist'
// import { setPlayList } from '@renderer/store/player'
import { useRouter } from '@common/utils/vueRouter'
import { parseUrlParams } from '@common/utils/common'
import { defaultList, loveList, userLists } from '@renderer/store/list/state'
import { getListMusics } from '@renderer/store/list/action'
import usePlaySonglist from './compositions/usePlaySonglist'
import { playList } from '@renderer/core/player'
// const getListPlayIndex = (list: LX.Music.MusicInfo[], indexStr?: string): number => {
// let index: number
// if (indexStr == null) {
// index = 1
// } else {
// index = parseInt(indexStr)
// if (Number.isNaN(index)) {
// index = 1
// } else {
// if (index < 1) index = 1
// else if (index > list.length) index = list.length
// }
// }
// return index - 1
// }
const getListPlayIndex = (list: LX.Music.MusicInfo[], indexStr?: string): number => {
let index: number
if (indexStr == null) {
index = 1
} else {
index = parseInt(indexStr)
if (Number.isNaN(index)) {
index = 1
} else {
if (index < 1) index = 1
else if (index > list.length) index = list.length
}
}
return index - 1
}
// const useInitEnvParamSearch = () => {
// const router = useRouter()
const useInitEnvParamSearch = () => {
const router = useRouter()
// return (search?: string) => {
// if (search == null) return
// void router.push({
// path: 'search',
// query: {
// text: search,
// },
// })
// }
// }
// const useInitEnvParamPlay = () => {
// // const setPlayList = useCommit('player', 'setList')
return (search?: string) => {
if (search == null) return
setTimeout(() => {
void router.replace({
path: '/search',
query: {
text: search,
},
})
}, 1000)
}
}
const useInitEnvParamPlay = () => {
// const setPlayList = useCommit('player', 'setList')
// const playSongListDetail = usePlaySonglist()
const playSongListDetail = usePlaySonglist()
// return (playStr?: string) => {
// if (playStr == null || typeof playStr != 'string') return
// // -play="source=kw&link=链接、ID"
// // -play="source=myList&name=名字"
// // -play="source=myList&name=名字&index=位置"
// const params = parseUrlParams(playStr)
// if (params.type != 'songList') return
// switch (params.source) {
// case 'myList':
// if (params.name != null) {
// let targetList
// const lists = [defaultList, loveList, ...userLists]
// for (const list of lists) {
// if (list.name === params.name) {
// targetList = list
// break
// }
// }
// if (!targetList) return
return async(playStr?: string) => {
if (playStr == null || typeof playStr != 'string') return
// -play="source=kw&link=链接、ID"
// -play="source=myList&name=名字"
// -play="source=myList&name=名字&index=位置"
const params = parseUrlParams(playStr)
if (params.type != 'songList') return
switch (params.source) {
case 'myList':
if (params.name != null) {
let targetList
const lists = [defaultList, loveList, ...userLists]
for (const list of lists) {
if (list.name === params.name) {
targetList = list
break
}
}
if (!targetList) return
// setPlayList({
// listId: targetList.id,
// index: getListPlayIndex(getList(targetList.id), params.index),
// })
// }
// break
// case 'kw':
// case 'kg':
// case 'tx':
// case 'mg':
// case 'wy':
// playSongListDetail(params.source, params.link, params.index)
// break
// }
// }
// }
playList(targetList.id, getListPlayIndex(await getListMusics(targetList.id), params.index))
}
break
case 'kw':
case 'kg':
case 'tx':
case 'mg':
case 'wy':
void playSongListDetail(params.source, params.link, parseInt(params.index))
break
}
}
}
// export default () => {
// // 处理启动参数 search
// const initEnvParamSearch = useInitEnvParamSearch()
export default () => {
// 处理启动参数 search
const initEnvParamSearch = useInitEnvParamSearch()
// // 处理启动参数 play
// const initEnvParamPlay = useInitEnvParamPlay()
// 处理启动参数 play
const initEnvParamPlay = useInitEnvParamPlay()
// return (envParams: LX.EnvParams) => {
// initEnvParamSearch(envParams.cmdParams.search)
// initEnvParamPlay(envParams.cmdParams.play)
// }
// }
return (envParams: LX.EnvParams) => {
initEnvParamSearch(envParams.cmdParams.search)
void initEnvParamPlay(envParams.cmdParams.play)
}
}

View File

@ -66,7 +66,7 @@ if (appSetting['search.isShowHistorySearch']) {
const router = useRouter()
const handleSearch = (text) => {
router.replace({
path: 'search',
path: '/search',
query: {
text,
},