From fd09f5078a2ae234aa59f9aafddb53b681193668 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Sat, 17 Jan 2026 18:08:53 -0600 Subject: [PATCH] Fix Auto backend to show fancy device names Problem: When Audio Backend was set to Auto, device names showed as raw ALSA names (hw:0,0) instead of friendly names, even though the translator exists and works for ALSA Direct. Root cause: Translation was only applied when selectedBackend === 'ALSA Direct'. Auto mode can use either ALSA or PipeWire depending on system, so it needs smart translation. Solution: Instead of checking selectedBackend, check the device NAME itself. If it looks like a raw ALSA device (starts with hw:, plughw:, sysdefault:CARD=, etc.), apply getDevicePrettyName(). Otherwise (PipeWire names like 'Built-in Audio Analog Stereo'), pass through unchanged. This works for: - ALSA Direct: Always translates (all devices are raw ALSA) - PipeWire: Never translates (all devices are friendly pactl names) - Auto: Translates only if backend chose ALSA Changes: - Add needsTranslation() helper to detect raw ALSA device names - Apply translation conditionally in deviceOptions and deviceByDisplayName - Update loadAudioSettings to use same logic --- src/lib/components/views/SettingsView.svelte | 26 ++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/lib/components/views/SettingsView.svelte b/src/lib/components/views/SettingsView.svelte index 70e4eb029..23e5a4bad 100644 --- a/src/lib/components/views/SettingsView.svelte +++ b/src/lib/components/views/SettingsView.svelte @@ -215,20 +215,33 @@ // Backend selector options (derived) let backendOptions = $derived(['Auto', ...availableBackends.filter(b => b.is_available).map(b => b.name)]); + // Helper to check if a device name looks like raw ALSA (needs translation) + function needsTranslation(name: string): boolean { + return name.startsWith('hw:') + || name.startsWith('plughw:') + || name.startsWith('sysdefault:CARD=') + || name.startsWith('default:CARD=') + || name.startsWith('front:CARD=') + || name.startsWith('surround') + || name.startsWith('hdmi:') + || name.startsWith('iec958:') + || name === 'default'; + } + // Device options based on selected backend (derived) - // Apply pretty names for ALSA devices only (PipeWire already has friendly names) + // Apply pretty names only to raw ALSA device names (Auto may use ALSA or PipeWire) let deviceOptions = $derived.by(() => { - const shouldTranslate = selectedBackend === 'ALSA Direct' || selectedBackend === 'Auto'; - const names = backendDevices.map(d => shouldTranslate ? getDevicePrettyName(d.name) : d.name); + const names = backendDevices.map(d => + needsTranslation(d.name) ? getDevicePrettyName(d.name) : d.name + ); return ['System Default', ...names]; }); // Map display name -> device for lookup when user selects let deviceByDisplayName = $derived.by(() => { const map = new Map(); - const shouldTranslate = selectedBackend === 'ALSA Direct' || selectedBackend === 'Auto'; for (const device of backendDevices) { - const displayName = shouldTranslate ? getDevicePrettyName(device.name) : device.name; + const displayName = needsTranslation(device.name) ? getDevicePrettyName(device.name) : device.name; map.set(displayName, device); } return map; @@ -766,8 +779,7 @@ if (settings.output_device) { const device = backendDevices.find(d => d.id === settings.output_device); if (device) { - const shouldTranslate = settings.backend_type === 'Alsa' || !settings.backend_type; - outputDevice = shouldTranslate ? getDevicePrettyName(device.name) : device.name; + outputDevice = needsTranslation(device.name) ? getDevicePrettyName(device.name) : device.name; } else { outputDevice = 'System Default'; }