新增 快进/快退5秒 自定义快捷键设置(#2289)

This commit is contained in:
lyswhut
2025-03-01 20:03:25 +08:00
parent 4f0af93b72
commit bda4650de8
8 changed files with 76 additions and 10 deletions
@@ -3,6 +3,8 @@ import { useI18n } from '@renderer/plugins/i18n'
import { setTitle } from '@renderer/utils'
import {
getCurrentTime,
getDuration,
setPause, setStop,
} from '@renderer/plugins/player'
@@ -97,6 +99,24 @@ export default () => {
// })
}
const setProgress = (time: number) => {
window.app_event.setProgress(time)
}
const handleSeekforward = () => {
const seekOffset = 5
const curTime = getCurrentTime()
const time = Math.min(getCurrentTime() + seekOffset, getDuration())
if (Math.trunc(curTime) == Math.trunc(time)) return
setProgress(time)
}
const handleSeekbackward = () => {
const seekOffset = 5
const curTime = getCurrentTime()
const time = Math.max(getCurrentTime() - seekOffset, 0)
if (Math.trunc(curTime) == Math.trunc(time)) return
setProgress(time)
}
const setStopStatus = () => {
setPlay(false)
setTitle(null)
@@ -120,6 +140,8 @@ export default () => {
window.key_event.on(HOTKEY_PLAYER.music_love.action, collectMusic)
window.key_event.on(HOTKEY_PLAYER.music_unlove.action, uncollectMusic)
window.key_event.on(HOTKEY_PLAYER.music_dislike.action, dislikeMusic)
window.key_event.on(HOTKEY_PLAYER.seekbackward.action, handleSeekbackward)
window.key_event.on(HOTKEY_PLAYER.seekforward.action, handleSeekforward)
window.app_event.on('play', setPlayStatus)
window.app_event.on('pause', setPauseStatus)
@@ -142,6 +164,8 @@ export default () => {
window.key_event.off(HOTKEY_PLAYER.music_love.action, collectMusic)
window.key_event.off(HOTKEY_PLAYER.music_unlove.action, uncollectMusic)
window.key_event.off(HOTKEY_PLAYER.music_dislike.action, dislikeMusic)
window.key_event.off(HOTKEY_PLAYER.seekbackward.action, handleSeekbackward)
window.key_event.off(HOTKEY_PLAYER.seekforward.action, handleSeekforward)
window.app_event.off('play', setPlayStatus)
+4 -2
View File
@@ -432,7 +432,8 @@ export const setMute = (isMute: boolean) => {
}
export const getCurrentTime = () => {
return audio?.currentTime ?? 0
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return audio?.currentTime || 0
}
export const setCurrentTime = (time: number) => {
@@ -449,7 +450,8 @@ export const setVolume = (volume: number) => {
}
export const getDuration = () => {
return audio?.duration ?? 0
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return audio?.duration || 0
}
// export const getPlaybackRate = () => {
+20
View File
@@ -343,6 +343,16 @@ export const allHotKeys = markRaw({
action: hotKeys.HOTKEY_PLAYER.next.action,
type: APP_EVENT_NAMES.winMainName,
},
{
name: hotKeys.HOTKEY_PLAYER.seekbackward.name,
action: hotKeys.HOTKEY_PLAYER.seekbackward.action,
type: APP_EVENT_NAMES.winMainName,
},
{
name: hotKeys.HOTKEY_PLAYER.seekforward.name,
action: hotKeys.HOTKEY_PLAYER.seekforward.action,
type: APP_EVENT_NAMES.winMainName,
},
{
name: hotKeys.HOTKEY_PLAYER.music_dislike.name,
action: hotKeys.HOTKEY_PLAYER.music_dislike.action,
@@ -395,6 +405,16 @@ export const allHotKeys = markRaw({
action: hotKeys.HOTKEY_PLAYER.next.action,
type: APP_EVENT_NAMES.winMainName,
},
{
name: hotKeys.HOTKEY_PLAYER.seekbackward.name,
action: hotKeys.HOTKEY_PLAYER.seekbackward.action,
type: APP_EVENT_NAMES.winMainName,
},
{
name: hotKeys.HOTKEY_PLAYER.seekforward.name,
action: hotKeys.HOTKEY_PLAYER.seekforward.action,
type: APP_EVENT_NAMES.winMainName,
},
{
name: hotKeys.HOTKEY_PLAYER.volume_up.name,
action: hotKeys.HOTKEY_PLAYER.volume_up.action,