修复界面不可见时状态栏歌词没有更新的问题

pull/2077/head
lyswhut 2024-06-19 12:39:44 +08:00
parent b0881726fa
commit 9eb87911a6
6 changed files with 43 additions and 12 deletions

View File

@ -228,7 +228,7 @@ export default class Lyric {
} else this.playingLineNum = 0
}
setAutoPause(autoPause) {
this.linePlayer.setAutoPause(autoPause)
setDisabledAutoPause(autoPause) {
this.linePlayer.setDisabledAutoPause(autoPause)
}
}

View File

@ -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)
}
}
}

View File

@ -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)
}

View File

@ -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'
@ -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()
@ -65,6 +67,7 @@ export default () => {
void initDeeplink(envParams)
void initSyncService()
void initOpenAPI()
void initStatusbarLyric()
sendInited()
handleListAutoUpdate()

View File

@ -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) => {
@ -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')
}
})
}

View File

@ -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)
}
}
}