Skip to content

Commit

Permalink
修复界面不可见时状态栏歌词没有更新的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lyswhut committed Jun 19, 2024
1 parent b088172 commit 9eb8791
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/common/utils/lyric-font-player/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export default class Lyric {
} else this.playingLineNum = 0
}

setAutoPause(autoPause) {
this.linePlayer.setAutoPause(autoPause)
setDisabledAutoPause(autoPause) {
this.linePlayer.setDisabledAutoPause(autoPause)
}
}
10 changes: 5 additions & 5 deletions src/common/utils/lyric-font-player/line-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ export default class LinePlayer {
this._init()
}

setAutoPause(autoPause) {
if (autoPause) {
timeoutTools.nextTick = window.requestAnimationFrame.bind(window)
timeoutTools.cancelNextTick = window.cancelAnimationFrame.bind(window)
} else {
setDisabledAutoPause(disabledAutoPause) {
if (disabledAutoPause) {
timeoutTools.nextTick = (handler) => {
return setTimeout(handler, 20)
}
timeoutTools.cancelNextTick = clearTimeout.bind(global)
} else {
timeoutTools.nextTick = window.requestAnimationFrame.bind(window)
timeoutTools.cancelNextTick = window.cancelAnimationFrame.bind(window)
}
}
}
14 changes: 12 additions & 2 deletions src/renderer/core/lyric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,18 @@ export const setLyric = () => {
}
}

export const setAutoPause = (autoPause: boolean) => {
lrc.setAutoPause(autoPause)
export const setDisabledAutoPause = (disabledAutoPause: boolean) => {
lrc.setDisabledAutoPause(disabledAutoPause)
}

let sources = new Map<string, boolean>()
let prevDisabled = false
export const setDisableAutoPauseBySource = (disabled: boolean, source: string) => {
sources.set(source, disabled)
const currentDisabled = Array.from(sources.values()).some(e => e)
if (prevDisabled == currentDisabled) return
prevDisabled = currentDisabled
setDisabledAutoPause(currentDisabled)
}


Expand Down
3 changes: 3 additions & 0 deletions src/renderer/core/useApp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { appSetting } from '@renderer/store/setting'

import useSync from './useSync'
import useOpenAPI from './useOpenAPI'
import useStatusbarLyric from './useStatusbarLyric'
import useUpdate from './useUpdate'
import useDataInit from './useDataInit'
import useHandleEnvParams from './useHandleEnvParams'
Expand All @@ -27,6 +28,7 @@ export default () => {
const router = useRouter()
const initSyncService = useSync()
const initOpenAPI = useOpenAPI()
const initStatusbarLyric = useStatusbarLyric()
useEventListener()
const initPlayer = usePlayer()
const handleEnvParams = useHandleEnvParams()
Expand Down Expand Up @@ -65,6 +67,7 @@ export default () => {
void initDeeplink(envParams)
void initSyncService()
void initOpenAPI()
void initStatusbarLyric()
sendInited()

handleListAutoUpdate()
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/core/useApp/useOpenAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { watch } from '@common/utils/vueTools'
import { appSetting } from '@renderer/store/setting'
import { sendOpenAPIAction } from '@renderer/utils/ipc'
import { openAPI } from '@renderer/store'
import { setAutoPause } from '@renderer/core/lyric'
import { setDisableAutoPauseBySource } from '@renderer/core/lyric'

export default () => {
const handleEnable = async(enable: boolean, port: string, bindLan: boolean) => {
Expand All @@ -21,9 +21,9 @@ export default () => {
openAPI.message = error.message
}).finally(() => {
if (openAPI.address) {
setAutoPause(false)
setDisableAutoPauseBySource(true, 'openAPI')
} else {
setAutoPause(true)
setDisableAutoPauseBySource(false, 'openAPI')
}
})
}
Expand Down
18 changes: 18 additions & 0 deletions src/renderer/core/useApp/useStatusbarLyric.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { watch } from '@common/utils/vueTools'
import { appSetting } from '@renderer/store/setting'
import { setDisableAutoPauseBySource } from '@renderer/core/lyric'

export default () => {
const handleEnable = (enable: boolean) => {
setDisableAutoPauseBySource(enable, 'statusBarLyric')
}
watch(() => appSetting['player.isShowStatusBarLyric'], enable => {
handleEnable(enable)
})

return async() => {
if (appSetting['player.isShowStatusBarLyric']) {
handleEnable(true)
}
}
}

0 comments on commit 9eb8791

Please sign in to comment.