From baa6235c567f317e325b6553ee98bfedb381b07d Mon Sep 17 00:00:00 2001 From: Atdunbg Date: Mon, 18 May 2026 15:52:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=BE=E7=BD=AE=E9=9F=B3?= =?UTF-8?q?=E9=A2=91=E8=BE=93=E5=87=BA=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 8 +++++++ src/components/CustomSelect.vue | 10 ++++---- src/stores/settings.ts | 14 ++++++++++- src/views/Settings.vue | 42 ++++++++++++++++++++++++++++++++- 4 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/App.vue b/src/App.vue index 42068df..86c928c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -440,6 +440,14 @@ onMounted(async () => { } catch {} updater.checkForUpdate(true); + + // 恢复保存的输出设备设置 + if(settings.outputDevice) { + try { + await invoke('set_output_device', { device: settings.outputDevice }); + } + catch{} + } }); const currentWindow = getCurrentWindow(); diff --git a/src/components/CustomSelect.vue b/src/components/CustomSelect.vue index 5f19352..1ef45e4 100644 --- a/src/components/CustomSelect.vue +++ b/src/components/CustomSelect.vue @@ -2,22 +2,22 @@
-
+
diff --git a/src/stores/settings.ts b/src/stores/settings.ts index 6368919..ab5b0f9 100644 --- a/src/stores/settings.ts +++ b/src/stores/settings.ts @@ -41,6 +41,7 @@ interface SettingsData { theme: ThemeMode; closeAction: CloseAction; shortcuts: Record; + outputDevice: string | null; } function loadSettings(): SettingsData { @@ -54,6 +55,7 @@ function loadSettings(): SettingsData { theme: parsed.theme || 'dark', closeAction: parsed.closeAction || 'ask', shortcuts: { ...defaultShortcuts, ...(parsed.shortcuts || {}) }, + outputDevice: parsed.outputDevice || null, }; } } catch {} @@ -63,6 +65,7 @@ function loadSettings(): SettingsData { theme: 'dark', closeAction: 'ask', shortcuts: { ...defaultShortcuts }, + outputDevice: null, }; } @@ -74,6 +77,7 @@ export const useSettingsStore = defineStore('settings', () => { const theme = ref(saved.theme); const closeAction = ref(saved.closeAction || 'ask'); const shortcuts = ref>(saved.shortcuts); + const outputDevice = ref(saved.outputDevice); function setAudioQuality(q: AudioQuality) { audioQuality.value = q; @@ -99,21 +103,27 @@ export const useSettingsStore = defineStore('settings', () => { shortcuts.value = { ...defaultShortcuts }; } + function setOutputDevice(device: string | null) { + outputDevice.value = device; + } + function resetAll() { audioQuality.value = 'standard'; downloadPath.value = ''; theme.value = 'dark'; closeAction.value = 'ask'; shortcuts.value = { ...defaultShortcuts }; + outputDevice.value = null; } - watch([audioQuality, downloadPath, theme, closeAction, shortcuts], () => { + watch([audioQuality, downloadPath, theme, closeAction, shortcuts, outputDevice], () => { const data: SettingsData = { audioQuality: audioQuality.value, downloadPath: downloadPath.value, theme: theme.value, closeAction: closeAction.value, shortcuts: shortcuts.value, + outputDevice: outputDevice.value, }; localStorage.setItem('app_settings', JSON.stringify(data)); }, { deep: true }); @@ -124,10 +134,12 @@ export const useSettingsStore = defineStore('settings', () => { theme, closeAction, shortcuts, + outputDevice, setAudioQuality, setDownloadPath, setTheme, setCloseAction, + setOutputDevice, setShortcut, resetShortcuts, resetAll, diff --git a/src/views/Settings.vue b/src/views/Settings.vue index bca8356..8c11eea 100644 --- a/src/views/Settings.vue +++ b/src/views/Settings.vue @@ -8,6 +8,14 @@

播放

+
+
+

输出设备

+

选择音频播放设备

+
+ +
+

音质选择

@@ -246,13 +254,45 @@ const settings = useSettingsStore(); const { showToast } = useToast(); const updater = useUpdater(); +const devices = ref([]); +const deviceOptions = computed(() => { + const options: Record = { '': '跟随系统默认' }; + for (const name of devices.value) { + options[name] = name; + } + return options; +}); + +const selectedDevice = computed({ + get: () => settings.outputDevice || '', + set: (val: string) => { + const device = val === '' ? null : val; + settings.setOutputDevice(device); + invoke('set_output_device', { device }).then(() => { + showToast(device ? `已切换到: ${device}` : '已切换到系统默认', 'success'); + }).catch((e) => { + console.error('切换设备失败: ', e); + showToast('切换设备失败', 'error'); + }); + } +}); + +async function loadDevices() { + try { + devices.value = await invoke('get_output_devices'); + } catch (e) { + console.error('获取设备失败: ', e); + } +} + const appVersion = ref(''); const defaultDownloadPath = ref(''); onMounted(async () => { appVersion.value = await getVersion(); try { defaultDownloadPath.value = await invoke('get_default_download_path'); - } catch {} + } catch { } + loadDevices(); }); const closeActionValue = computed({