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

pull/2296/head
lyswhut 2025-03-01 20:03:25 +08:00
parent 4f0af93b72
commit bda4650de8
8 changed files with 76 additions and 10 deletions

View File

@ -1,3 +1,7 @@
### 新增
- 新增 快进/快退5秒 自定义快捷键设置(#2289
### 修复
- 修复 Windows 下桌面歌词最小高度与宽度设置问题(#2244

View File

@ -51,6 +51,16 @@ const hotKey = {
action: 'prev',
type: '',
},
seekbackward: {
name: 'seekbackward',
action: 'seekbackward',
type: '',
},
seekforward: {
name: 'seekforward',
action: 'seekforward',
type: '',
},
volume_up: {
name: 'volume_up',
action: 'volume_up',

View File

@ -450,6 +450,8 @@
"setting__hot_key_player_music_unlove": "Unlove Song",
"setting__hot_key_player_next": "Next Song",
"setting__hot_key_player_prev": "Previous Song",
"setting__hot_key_player_seekbackward": "Seek backward 5s",
"setting__hot_key_player_seekforward": "Seek forward 5s",
"setting__hot_key_player_toggle_play": "Play/Pause Control",
"setting__hot_key_player_volume_down": "Decrease Volume",
"setting__hot_key_player_volume_mute": "Toggle Mute",

View File

@ -377,6 +377,9 @@
"setting__desktop_lyric_font": "歌词字体",
"setting__desktop_lyric_font_default": "默认",
"setting__desktop_lyric_font_weight": "加粗字体",
"setting__desktop_lyric_font_weight_extended": "翻译、罗马音歌词",
"setting__desktop_lyric_font_weight_font": "逐字歌词",
"setting__desktop_lyric_font_weight_line": "逐行歌词",
"setting__desktop_lyric_fullscreen_hide": "全屏时自动关闭歌词",
"setting__desktop_lyric_hover_hide": "鼠标移入歌词区域时降低歌词透明度",
"setting__desktop_lyric_hover_hide_tip": "此功能存在平台兼容性问题,在某些平台上可能会出现预料外的问题",
@ -408,8 +411,8 @@
"setting__download_enable": "启用下载功能",
"setting__download_lyric": "歌词下载",
"setting__download_lyric_format": "下载的歌词文件编码格式",
"setting__download_lyric_format_tip": "在某些设备上出现中文乱码时可尝试选择 GBK 格式",
"setting__download_lyric_format_gbk": "GBK",
"setting__download_lyric_format_tip": "在某些设备上出现中文乱码时可尝试选择 GBK 格式",
"setting__download_lyric_format_utf8": "UTF-8",
"setting__download_lyric_title": "同时下载歌词文件",
"setting__download_max_num": "同时下载任务数",
@ -447,6 +450,8 @@
"setting__hot_key_player_music_unlove": "取消收藏",
"setting__hot_key_player_next": "下一首歌曲",
"setting__hot_key_player_prev": "上一首歌曲",
"setting__hot_key_player_seekbackward": "快退 5s",
"setting__hot_key_player_seekforward": "快进 5s",
"setting__hot_key_player_toggle_play": "播放/暂停控制",
"setting__hot_key_player_volume_down": "减少音量",
"setting__hot_key_player_volume_mute": "静音切换",
@ -549,9 +554,6 @@
"setting__search_focus_search_box": "启动时自动聚焦搜索框",
"setting__search_history": "显示历史搜索记录",
"setting__search_hot": "显示热门搜索",
"setting__desktop_lyric_font_weight_extended": "翻译、罗马音歌词",
"setting__desktop_lyric_font_weight_font": "逐字歌词",
"setting__desktop_lyric_font_weight_line": "逐行歌词",
"setting__sync": "数据同步",
"setting__sync_client_address": "当前设备地址:{address}",
"setting__sync_client_host": "同步服务地址",

View File

@ -377,6 +377,9 @@
"setting__desktop_lyric_font": "歌詞字體",
"setting__desktop_lyric_font_default": "預設",
"setting__desktop_lyric_font_weight": "加粗字體",
"setting__desktop_lyric_font_weight_extended": "翻譯、羅馬音歌詞",
"setting__desktop_lyric_font_weight_font": "逐字歌詞",
"setting__desktop_lyric_font_weight_line": "逐行歌詞",
"setting__desktop_lyric_fullscreen_hide": "全螢幕時自動關閉歌詞視窗",
"setting__desktop_lyric_hover_hide": "滑鼠移入歌詞視窗時降低歌詞透明度",
"setting__desktop_lyric_hover_hide_tip": "此功能存在平台相容性問題,在某些平台上可能會出現預料外的問題",
@ -408,8 +411,8 @@
"setting__download_enable": "啟用下載功能",
"setting__download_lyric": "歌詞下載",
"setting__download_lyric_format": "下載的歌詞檔案編碼格式",
"setting__download_lyric_format_tip": "在某些裝置上出現中文亂碼時可嘗試選取 GBK 格式",
"setting__download_lyric_format_gbk": "GBK",
"setting__download_lyric_format_tip": "在某些裝置上出現中文亂碼時可嘗試選取 GBK 格式",
"setting__download_lyric_format_utf8": "UTF-8",
"setting__download_lyric_title": "同時下載歌詞檔案",
"setting__download_max_num": "同時下載任務數",
@ -447,6 +450,8 @@
"setting__hot_key_player_music_unlove": "取消收藏",
"setting__hot_key_player_next": "下一首歌曲",
"setting__hot_key_player_prev": "上一首歌曲",
"setting__hot_key_player_seekbackward": "快退 5s",
"setting__hot_key_player_seekforward": "快進 5s",
"setting__hot_key_player_toggle_play": "播放/暫停控制",
"setting__hot_key_player_volume_down": "減少音量",
"setting__hot_key_player_volume_mute": "靜音切換",
@ -549,9 +554,6 @@
"setting__search_focus_search_box": "啟動時自動聚焦搜尋框",
"setting__search_history": "顯示歷史搜尋記錄",
"setting__search_hot": "顯示熱門搜尋",
"setting__desktop_lyric_font_weight_extended": "翻譯、羅馬音歌詞",
"setting__desktop_lyric_font_weight_font": "逐字歌詞",
"setting__desktop_lyric_font_weight_line": "逐行歌詞",
"setting__sync": "資料同步",
"setting__sync_client_address": "目前裝置位址:{address}",
"setting__sync_client_host": "同步服務位址",

View File

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

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 = () => {

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,