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