优化代码逻辑,修复潜在播放问题
This commit is contained in:
@@ -44,7 +44,7 @@ export const createClientKeyInfo = (deviceName: string): LX.Sync.KeyInfo => {
|
||||
deviceName,
|
||||
}
|
||||
const store = getStore(STORE_NAME)
|
||||
if (!keyInfos) keyInfos = store.get('keys') as KeyInfos || {}
|
||||
keyInfos ??= store.get('keys') as KeyInfos || {}
|
||||
if (Object.keys(keyInfos).length > 101) throw new Error('max keys')
|
||||
|
||||
keyInfos[keyInfo.clientId] = keyInfo
|
||||
|
||||
@@ -27,7 +27,7 @@ const winEvent = () => {
|
||||
|
||||
export const createWindow = async(userApi: LX.UserApi.UserApiInfo) => {
|
||||
await closeWindow()
|
||||
if (!dir) dir = global.isDev ? webpackUserApiPath : join(encodePath(__dirname), 'userApi')
|
||||
dir ??= global.isDev ? webpackUserApiPath : join(encodePath(__dirname), 'userApi')
|
||||
|
||||
if (!html) {
|
||||
html = await fs.promises.readFile(join(dir, 'renderer/user-api.html'), 'utf8')
|
||||
|
||||
@@ -33,7 +33,7 @@ export const importApi = (script: string): LX.UserApi.UserApiInfo => {
|
||||
script,
|
||||
allowShowUpdateAlert: true,
|
||||
}
|
||||
if (!userApis) userApis = []
|
||||
userApis ??= []
|
||||
userApis.push(apiInfo)
|
||||
getStore(STORE_NAMES.USER_API).set('userApis', userApis)
|
||||
return apiInfo
|
||||
|
||||
@@ -20,7 +20,7 @@ const winEvent = () => {
|
||||
return
|
||||
}
|
||||
|
||||
if (global.lx.isTrafficLightClose) global.lx.isTrafficLightClose = false
|
||||
global.lx.isTrafficLightClose &&= false
|
||||
event.preventDefault()
|
||||
browserWindow!.hide()
|
||||
})
|
||||
|
||||
@@ -113,7 +113,7 @@ export const updateSetting = (setting?: Partial<LX.AppSetting>, isInit: boolean
|
||||
|
||||
let originSetting: LX.AppSetting
|
||||
if (isInit) {
|
||||
if (setting) setting = migrateSetting(setting)
|
||||
setting &&= migrateSetting(setting)
|
||||
originSetting = { ...defaultSetting }
|
||||
} else originSetting = global.lx.appSetting
|
||||
|
||||
@@ -196,7 +196,7 @@ export const openDevTools = (webContents: Electron.WebContents) => {
|
||||
|
||||
let userThemes: LX.Theme[]
|
||||
export const getAllThemes = () => {
|
||||
if (!userThemes) userThemes = getStore(STORE_NAMES.THEME).get('themes') as LX.Theme[] | null ?? []
|
||||
userThemes ??= getStore(STORE_NAMES.THEME).get('themes') as (LX.Theme[] | null) ?? []
|
||||
return {
|
||||
themes,
|
||||
userThemes,
|
||||
|
||||
@@ -39,7 +39,7 @@ const toDBMusicInfo = (musicInfos: LX.Music.MusicInfo[], listId: string, offset:
|
||||
* @returns
|
||||
*/
|
||||
export const getAllUserList = (): LX.List.UserListInfo[] => {
|
||||
if (userLists == null) userLists = queryAllUserList()
|
||||
userLists ??= queryAllUserList()
|
||||
|
||||
return userLists.map(list => {
|
||||
const { position, ...newList } = list
|
||||
@@ -53,7 +53,7 @@ export const getAllUserList = (): LX.List.UserListInfo[] => {
|
||||
* @param lists 列表信息
|
||||
*/
|
||||
export const createUserLists = (position: number, lists: LX.List.UserListInfo[]) => {
|
||||
if (userLists == null) userLists = queryAllUserList()
|
||||
userLists ??= queryAllUserList()
|
||||
if (position < 0 || position >= userLists.length) {
|
||||
const newLists: LX.DBService.UserListInfo[] = lists.map((list, index) => {
|
||||
return {
|
||||
@@ -96,7 +96,7 @@ export const setUserLists = (lists: LX.List.UserListInfo[]) => {
|
||||
*/
|
||||
export const removeUserLists = (ids: string[]) => {
|
||||
deleteUserLists(ids)
|
||||
if (userLists) userLists = queryAllUserList()
|
||||
userLists &&= queryAllUserList()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +117,7 @@ export const updateUserLists = (lists: LX.List.UserListInfo[]) => {
|
||||
}
|
||||
}).filter(Boolean) as LX.DBService.UserListInfo[]
|
||||
updateUserListsFromDB(dbList)
|
||||
if (userLists) userLists = queryAllUserList()
|
||||
userLists &&= queryAllUserList()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,7 +126,7 @@ export const updateUserLists = (lists: LX.List.UserListInfo[]) => {
|
||||
* @param ids 列表ids
|
||||
*/
|
||||
export const updateUserListsPosition = (position: number, ids: string[]) => {
|
||||
if (userLists == null) userLists = queryAllUserList()
|
||||
userLists ??= queryAllUserList()
|
||||
|
||||
const newUserLists = [...userLists]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user