From 95c255d2ba64171fb0d76c7b9355f9b17840e0f2 Mon Sep 17 00:00:00 2001 From: algerkong Date: Mon, 23 Jun 2025 20:58:08 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=BD=91=E9=A1=B5=E7=AB=AF=E5=92=8C=E5=BF=AB=E6=8D=B7=E9=94=AE?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=B0=83=E6=95=B4=E9=9F=B3=E9=87=8F=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/services/audioService.ts | 2 ++ src/renderer/utils/appShortcuts.ts | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/renderer/services/audioService.ts b/src/renderer/services/audioService.ts index b6e3d08..0f7217e 100644 --- a/src/renderer/services/audioService.ts +++ b/src/renderer/services/audioService.ts @@ -802,6 +802,8 @@ class AudioService { // 立即设置音量 this.gainNode.gain.cancelScheduledValues(this.context!.currentTime); this.gainNode.gain.setValueAtTime(linearVolume, this.context!.currentTime); + } else { + this.currentSound?.volume(linearVolume); } // 保存值 diff --git a/src/renderer/utils/appShortcuts.ts b/src/renderer/utils/appShortcuts.ts index 0f25ad9..9878256 100644 --- a/src/renderer/utils/appShortcuts.ts +++ b/src/renderer/utils/appShortcuts.ts @@ -67,7 +67,6 @@ export async function handleShortcutAction(action: string) { const playerStore = usePlayerStore(); const settingsStore = useSettingsStore(); - const currentSound = audioService.getCurrentSound(); const showToast = (message: string, iconName: string) => { if (settingsStore.isMiniMode) { return; @@ -95,19 +94,25 @@ export async function handleShortcutAction(action: string) { showToast(t('player.playBar.next'), 'ri-skip-forward-line'); break; case 'volumeUp': - if (currentSound && currentSound?.volume() < 1) { - currentSound?.volume((currentSound?.volume() || 0) + 0.1); + // 从localStorage获取当前音量 + const currentVolumeUp = parseFloat(localStorage.getItem('volume') || '1'); + if (currentVolumeUp < 1) { + const newVolume = Math.min(1, currentVolumeUp + 0.1); + await audioService.setVolume(newVolume); showToast( - `${t('player.playBar.volume')}${Math.round((currentSound?.volume() || 0) * 100)}%`, + `${t('player.playBar.volume')}${Math.round(newVolume * 100)}%`, 'ri-volume-up-line' ); } break; case 'volumeDown': - if (currentSound && currentSound?.volume() > 0) { - currentSound?.volume((currentSound?.volume() || 0) - 0.1); + // 从localStorage获取当前音量 + const currentVolumeDown = parseFloat(localStorage.getItem('volume') || '1'); + if (currentVolumeDown > 0) { + const newVolume = Math.max(0, currentVolumeDown - 0.1); + await audioService.setVolume(newVolume); showToast( - `${t('player.playBar.volume')}${Math.round((currentSound?.volume() || 0) * 100)}%`, + `${t('player.playBar.volume')}${Math.round(newVolume * 100)}%`, 'ri-volume-down-line' ); }