修复初始化列表信息可能导致崩溃的问题

This commit is contained in:
lyswhut 2023-06-10 19:59:34 +08:00
parent 09029f3771
commit 39bf0b13f6
3 changed files with 7 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import { init as musicSdkInit } from '@/utils/musicSdk'
import { getUserLists, setUserList } from '@/core/list'
import { setNavActiveId } from '../common'
import { getViewPrevState } from '@/utils/data'
import { bootLog } from '@/utils/bootLog'
// import { play, playList } from '../player/player'
// const initPrevPlayInfo = async(appSetting: LX.AppSetting) => {
@ -23,8 +24,9 @@ export default async(appSetting: LX.AppSetting) => {
// initUserApi(), // 自定义API
// ]).catch(err => log.error(err))
void musicSdkInit() // 初始化音乐sdk
bootLog('User list init...')
setUserList(await getUserLists()) // 获取用户列表
bootLog('User list inited.')
setNavActiveId((await getViewPrevState()).id)
// await initPrevPlayInfo(appSetting).catch(err => log.error(err)) // 初始化上次的歌曲播放信息
}

View File

@ -6,7 +6,7 @@ import SourceSelector, {
type SourceSelectorType as _SourceSelectorType,
type SourceSelectorProps as _SourceSelectorProps,
} from '@/components/SourceSelector'
import songlistState, { type Source, type InitState } from '@/store/leaderboard/state'
import leaderboardState, { type Source, type InitState } from '@/store/leaderboard/state'
type Sources = Readonly<InitState['sources']>
type SourceSelectorCommonProps = _SourceSelectorProps<Sources>
@ -26,13 +26,13 @@ export default forwardRef<SourceSelectorType, SourceSelectorProps>(({ style, onS
useImperativeHandle(ref, () => ({
setSource(source) {
sourceSelectorRef.current?.setSourceList(songlistState.sources, source)
sourceSelectorRef.current?.setSourceList(leaderboardState.sources, source)
},
}), [])
return (
<View style={StyleSheet.compose<ViewStyle>(styles.selector, style)}>
<View style={StyleSheet.compose<ViewStyle, ViewStyle, ViewStyle>(styles.selector, style)}>
<SourceSelector ref={sourceSelectorRef} onSourceChange={onSourceChange} center />
</View>
)

View File

@ -235,7 +235,7 @@ export const getUserLists = async(): Promise<LX.List.UserListInfo[]> => {
const list = await getData<LX.List.UserListInfo[]>(userListKey) ?? []
for (const info of list) {
// 兼容v2.3.0之前版本PC端插入数字类型的ID导致其意外在末尾追加 .0 的问题
if (info.sourceListId?.endsWith('.0')) {
if (info.sourceListId?.endsWith?.('.0')) {
info.sourceListId = info.sourceListId.replace(idFixRxp, '')
}
}