Skip to content

Commit

Permalink
优化代码逻辑,修复潜在播放问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lyswhut committed Jan 14, 2023
1 parent d3c8f16 commit 850a429
Show file tree
Hide file tree
Showing 35 changed files with 85 additions and 342 deletions.
2 changes: 1 addition & 1 deletion publish/changeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

- 修复备份文件导入指引无法识别v2配置的问题
- 修复从搜索界面进入歌单详情后,若启用强迫症设置的清空功能会导致意外清空搜索框、搜索列表的问题
- 就放桌面歌词在启用卡拉OK歌词后字体边缘可能被截断的问题
- 修复桌面歌词在启用卡拉OK歌词后字体边缘可能被截断的问题(特别是纵向歌词某些字的边角被截断导致后面的阴影露出来或阴影不均匀的问题)
- 修复桌面歌词启用歌词缩放后的阴影显示问题
- 修复Linux armv7l系统(如树莓派)下无法启动的问题(与修复Linux arm64的方法一样采用内置预编译模块的方式修复)
- 修复备份与恢复的列表导入列表信息设置逻辑问题与潜在导入问题
2 changes: 1 addition & 1 deletion src/common/theme/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports.createThemeColors = (rgbaColor, fontRgbaColor, isDark) => {
const createFontColors = (rgbaColor, isDark) => {
// rgb(238, 238, 238)
// let prec = 'rgb(255, 255, 255)'
if (rgbaColor == null) rgbaColor = isDark ? 'rgb(229, 229, 229)' : 'rgb(33, 33, 33)'
rgbaColor ??= isDark ? 'rgb(229, 229, 229)' : 'rgb(33, 33, 33)'
if (isDark) return createFontDarkColors(rgbaColor)

let colors = {
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/lyric-font-player/font-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ module.exports = class FontPlayer {
// lineText += text

if (this.shadowContent) {
if (!lrcShadowContent) lrcShadowContent = document.createElement('div')
lrcShadowContent ??= document.createElement('div')
const shadowDom = document.createElement('span')
shadowDom.textContent = text
lrcShadowContent.appendChild(shadowDom)
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/migrateSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default (setting: any): Partial<LX.AppSetting> => {
// 迁移列表滚动位置设置 ~0.18.3
if (setting.list?.scroll) {
let scroll = setting.list.scroll
if (setting.list.isSaveScrollLocation) setting.list.isSaveScrollLocation = scroll.enable
setting.list.isSaveScrollLocation &&= scroll.enable
delete setting.list.scroll
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export const scrollXRTo = (element: HTMLElement, to: number, duration = 300, fn
*/
let dom_title = document.getElementsByTagName('title')[0]
export const setTitle = (title: string | null) => {
if (!title) title = '洛雪音乐助手'
title ||= '洛雪音乐助手'
dom_title.innerText = title
}

2 changes: 1 addition & 1 deletion src/main/modules/sync/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/userApi/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/userApi/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/winMain/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const winEvent = () => {
return
}

if (global.lx.isTrafficLightClose) global.lx.isTrafficLightClose = false
global.lx.isTrafficLightClose &&= false
event.preventDefault()
browserWindow!.hide()
})
Expand Down
4 changes: 2 additions & 2 deletions src/main/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/main/worker/dbService/modules/list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -96,7 +96,7 @@ export const setUserLists = (lists: LX.List.UserListInfo[]) => {
*/
export const removeUserLists = (ids: string[]) => {
deleteUserLists(ids)
if (userLists) userLists = queryAllUserList()
userLists &&= queryAllUserList()
}

/**
Expand All @@ -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()
}

/**
Expand All @@ -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]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default () => {

const handleMove = (x, y) => {
if (isMsDown.value) {
if (!isStopScroll) isStopScroll = true
isStopScroll ||= true
if (cancelScrollFn) {
cancelScrollFn()
cancelScrollFn = null
Expand Down Expand Up @@ -164,7 +164,7 @@ export default () => {
const scrollLine = (line, oldLine) => {
if (line < 0 || !lyric.lines.length) return
if (line == 0 && isSetedLines) return isSetedLines = false
if (isSetedLines) isSetedLines = false
isSetedLines &&= false
if (oldLine == null || line - oldLine != 1) return handleScrollLrc()

if (setting['desktopLyric.isDelayScroll']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default () => {

const handleMove = (x, y) => {
if (isMsDown.value) {
if (!isStopScroll) isStopScroll = true
isStopScroll ||= true
if (cancelScrollFn) {
cancelScrollFn()
cancelScrollFn = null
Expand Down Expand Up @@ -164,7 +164,7 @@ export default () => {
const scrollLine = (line, oldLine) => {
if (line < 0) return
if (line == 0 && isSetedLines) return isSetedLines = false
if (isSetedLines) isSetedLines = false
isSetedLines &&= false
if (oldLine == null || line - oldLine != 1) return handleScrollLrc()

if (setting['desktopLyric.isDelayScroll']) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/common/ProgressBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default {
}
const handleMsMove = event => {
if (!msEvent.isMsDown) return
if (!dragging.value) dragging.value = true
dragging.value ||= true
let progress = msEvent.msDownProgress + (event.clientX - msEvent.msDownX) / dom_progress.value.clientWidth
if (progress > 1) progress = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ export default {
let lxlyric = props.lyricInfo.lxlyric
if (offsetTagRxp.test(lyric)) {
lyric = lyric.replace(offsetTagAllRxp, `$1[offset:${offset}]`)
if (tlyric) tlyric = tlyric.replace(offsetTagAllRxp, `$1[offset:${offset}]`)
if (lxlyric) lxlyric = lxlyric.replace(offsetTagAllRxp, `$1[offset:${offset}]`)
if (rlyric) rlyric = rlyric.replace(offsetTagAllRxp, `$1[offset:${offset}]`)
tlyric &&= tlyric.replace(offsetTagAllRxp, `$1[offset:${offset}]`)
lxlyric &&= lxlyric.replace(offsetTagAllRxp, `$1[offset:${offset}]`)
rlyric &&= rlyric.replace(offsetTagAllRxp, `$1[offset:${offset}]`)
} else {
lyric = `[offset:${offset}]\n` + lyric
if (tlyric) tlyric = `[offset:${offset}]\n` + tlyric
if (lxlyric) lxlyric = `[offset:${offset}]\n` + lxlyric
if (rlyric) rlyric = `[offset:${offset}]\n` + rlyric
lyric &&= `[offset:${offset}]\n` + lyric
tlyric &&= `[offset:${offset}]\n` + tlyric
lxlyric &&= `[offset:${offset}]\n` + lxlyric
rlyric &&= `[offset:${offset}]\n` + rlyric
}
const musicInfo = 'progress' in props.lyricInfo.musicInfo ? props.lyricInfo.musicInfo.meta.musicInfo : props.lyricInfo.musicInfo
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/layout/Toolbar/SearchInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default {
}
const handleSearch = () => {
if (visibleList.value) visibleList.value = false
visibleList.value &&= false
if (!searchText.value && route.path != '/search') {
setSearchText('')
return
Expand All @@ -83,13 +83,13 @@ export default {
switch (action) {
case 'focus':
isFocused = true
if (!visibleList.value) visibleList.value = true
visibleList.value ||= true
if (searchText.value) handleTipSearch()
break
case 'blur':
isFocused = false
setTimeout(() => {
if (visibleList.value) visibleList.value = false
visibleList.value &&= false
}, 50)
break
case 'submit':
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/material/OnlineList/useList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ const useKeyEvent = ({ handleSelectAllData }: {
}

const handle_key_shift_down = () => {
if (!keyEvent.isShiftDown) keyEvent.isShiftDown = true
keyEvent.isShiftDown ||= true
}
const handle_key_shift_up = () => {
if (keyEvent.isShiftDown) keyEvent.isShiftDown = false
keyEvent.isShiftDown &&= false
}
const handle_key_mod_down = () => {
if (!keyEvent.isModDown) keyEvent.isModDown = true
keyEvent.isModDown ||= true
}
const handle_key_mod_up = () => {
if (keyEvent.isModDown) keyEvent.isModDown = false
keyEvent.isModDown &&= false
}
const handle_key_mod_a_down = ({ event }: LX.KeyDownEevent) => {
if (!event || (event.target as HTMLElement).tagName == 'INPUT') return
Expand Down
24 changes: 13 additions & 11 deletions src/renderer/core/player/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { requestMsg } from '@renderer/utils/message'
import { getRandom } from '@renderer/utils/index'
// import { checkMusicFileAvailable } from '@renderer/utils/music'

let isGettingUrl = false
let gettingUrlId = ''
const createDelayNextTimeout = (delay: number) => {
let timeout: NodeJS.Timeout | null
const clearDelayNextTimeout = () => {
Expand Down Expand Up @@ -86,7 +86,7 @@ const getMusicPlayUrl = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListIt

export const setMusicUrl = (musicInfo: LX.Music.MusicInfo | LX.Download.ListItem, isRefresh?: boolean) => {
if (appSetting['player.autoSkipOnError']) addLoadTimeout()
isGettingUrl = true
gettingUrlId = musicInfo.id
void getMusicPlayUrl(musicInfo, isRefresh).then((url) => {
if (!url) return
setResource(url)
Expand All @@ -96,8 +96,10 @@ export const setMusicUrl = (musicInfo: LX.Music.MusicInfo | LX.Download.ListItem
window.app_event.error()
if (appSetting['player.autoSkipOnError']) addDelayNextTimeout()
}).finally(() => {
clearLoadTimeout()
if (musicInfo === playMusicInfo.musicInfo) isGettingUrl = false
if (musicInfo === playMusicInfo.musicInfo) {
gettingUrlId = ''
clearLoadTimeout()
}
})
}

Expand Down Expand Up @@ -139,24 +141,24 @@ const handleRestorePlay = async(restorePlayInfo: LX.Player.SavedPlayInfo) => {

// 处理音乐播放
const handlePlay = () => {
if (window.lx.isPlayedStop) window.lx.isPlayedStop = false
if (isGettingUrl) isGettingUrl = false
window.lx.isPlayedStop &&= false

if (window.lx.restorePlayInfo) {
void handleRestorePlay(window.lx.restorePlayInfo)
window.lx.restorePlayInfo = null
return
}
const musicInfo = playMusicInfo.musicInfo

if (!musicInfo || gettingUrlId == musicInfo.id) return
gettingUrlId &&= ''

setStop()
window.app_event.pause()

clearDelayNextTimeout()
clearLoadTimeout()

const musicInfo = playMusicInfo.musicInfo

if (!musicInfo) return

if (appSetting['player.togglePlayMethod'] == 'random' && playMusicInfo.listId) addPlayedList({ ...(playMusicInfo as LX.Player.PlayMusicInfo) })

Expand Down Expand Up @@ -414,7 +416,7 @@ export const playPrev = async(isAutoToggle = false): Promise<void> => {
export const play = () => {
if (playMusicInfo.musicInfo == null) return
if (isEmpty()) {
setMusicUrl(playMusicInfo.musicInfo)
if (playMusicInfo.musicInfo.id != gettingUrlId) setMusicUrl(playMusicInfo.musicInfo)
return
}
setPlay()
Expand All @@ -441,7 +443,7 @@ export const stop = () => {
* 播放、暂停播放切换
*/
export const togglePlay = () => {
if (window.lx.isPlayedStop) window.lx.isPlayedStop = false
window.lx.isPlayedStop &&= false
if (isPlay.value) {
pause()
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/core/player/timeoutStop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ const timeoutTools: {
}

export const startTimeoutStop = (time: number) => {
if (window.lx.isPlayedStop) window.lx.isPlayedStop = false
window.lx.isPlayedStop &&= false
timeoutTools.start(time)
}
export const stopTimeoutStop = () => {
console.warn('stopTimeoutStop')
if (window.lx.isPlayedStop) window.lx.isPlayedStop = false
window.lx.isPlayedStop &&= false
timeoutTools.clearTimeout()
}

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/core/useApp/usePlayer/useMediaDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export default () => {
let mediaDeviceId = appSetting['player.mediaDeviceId']
const devices = await getDevices()
let device = devices.find(device => device.deviceId === mediaDeviceId)
if (!device) device = devices.find(device => device.deviceId === 'default')
device ??= devices.find(device => device.deviceId === 'default')
// @ts-expect-error
if (!device) device = { label: '', deviceId: '' }
device ??= { label: '', deviceId: '' }

// @ts-expect-error
handleDeviceChangeStopPlay(device, mediaDeviceId)
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/core/useApp/usePlayer/usePlayProgress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default () => {
if (window.lx.isPlayedStop) return
const currentTime = getCurrentTime()

if (!mediaBuffer.playTime) mediaBuffer.playTime = currentTime
mediaBuffer.playTime ||= currentTime
let skipTime = currentTime + getRandom(3, 6)
if (skipTime > playProgress.maxPlayTime) skipTime = (playProgress.maxPlayTime - currentTime) / 2
if (skipTime - mediaBuffer.playTime < 1 || playProgress.maxPlayTime - skipTime < 1) {
Expand Down Expand Up @@ -97,7 +97,7 @@ export default () => {
}

const handleError = () => {
if (!restorePlayTime) restorePlayTime = getCurrentTime() // 记录出错的播放时间
restorePlayTime ||= getCurrentTime() // 记录出错的播放时间
console.log('handleError')
prevProgressStatus = 'error'
handleSetTaskBarState(playProgress.progress, prevProgressStatus)
Expand Down
Loading

0 comments on commit 850a429

Please sign in to comment.