Add fancy device names for ALSA Direct backend

Apply getDevicePrettyName translator to all audio devices in settings.
This provides user-friendly names for ALSA devices (e.g., 'USB: Topping D50s'
instead of 'hw:0,0') while preserving PipeWire's native descriptions.

Changes:
- Import getDevicePrettyName from audioDeviceNames utils
- Apply translator in deviceOptions derived state
- Create deviceByPrettyName map for reverse lookup
- Update handleBackendDeviceChange to use pretty name mapping
- Update loadAudioSettings to display pretty names

This solves the issue where Auto and ALSA Direct backends showed
cryptic device names while PipeWire showed friendly descriptions.
This commit is contained in:
vicrodh committed 2026-01-17 17:39:13 -06:00
1 parent fccc7f781d
commit 2b04d05af4
1 file changed
+15 -4
+15 -4
View File
@@ -27,6 +27,7 @@
import { setLocale, locale, t } from '$lib/i18n';
import { get } from 'svelte/store';
import MigrationModal from '../MigrationModal.svelte';
import { getDevicePrettyName } from '$lib/utils/audioDeviceNames';
import {
subscribe as subscribeOffline,
getStatus as getOfflineStatus,
@@ -215,7 +216,17 @@
let backendOptions = $derived(['Auto', ...availableBackends.filter(b => b.is_available).map(b => b.name)]);
// Device options based on selected backend (derived)
let deviceOptions = $derived(['System Default', ...backendDevices.map(d => d.name)]);
// Apply pretty names for ALSA devices (PipeWire names pass through unchanged)
let deviceOptions = $derived(['System Default', ...backendDevices.map(d => getDevicePrettyName(d.name))]);
// Map pretty name -> device for lookup when user selects
let deviceByPrettyName = $derived.by(() => {
const map = new Map<string, AudioDevice>();
for (const device of backendDevices) {
map.set(getDevicePrettyName(device.name), device);
}
return map;
});
// ALSA plugin options (derived)
let alsaPluginOptions = $derived(alsaPlugins.map(p => p.name));
@@ -748,7 +759,7 @@
// Set selected device from backend devices
if (settings.output_device) {
const device = backendDevices.find(d => d.id === settings.output_device);
outputDevice = device?.name ?? 'System Default';
outputDevice = device ? getDevicePrettyName(device.name) : 'System Default';
}
}
} else {
@@ -896,8 +907,8 @@
async function handleBackendDeviceChange(deviceName: string) {
outputDevice = deviceName;
// Get device ID from backendDevices
const device = backendDevices.find(d => d.name === deviceName);
// Get device ID from backendDevices using pretty name mapping
const device = deviceByPrettyName.get(deviceName);
const deviceId = deviceName === 'System Default' ? null : device?.id ?? null;
try {