feat(alsa): use stable device IDs for persistent device selection

Convert hw:X,0 to front:CARD=name,DEV=0 format when saving device selection.
This makes device IDs stable across reboots and USB reconnections since they
use the card name (e.g., C20) instead of the card number which can change.

- Add normalize_device_id_to_stable() to convert hw:X,0 to front:CARD=name,DEV=0
- Add resolve_stable_to_current_hw() for reverse lookup when needed
- Apply normalization automatically in set_audio_output_device command
- Export functions from audio module for use across codebase
This commit is contained in:
vicrodh committed 2026-02-02 21:41:34 -06:00
1 parent 67895aaa9b
commit 9b12f761b5
3 files changed
+138 -4

No files matched your search

+13 -2
View File
@@ -292,9 +292,20 @@ pub fn set_audio_output_device(
state: tauri::State<'_, AudioSettingsState>,
device: Option<String>,
) -> Result<(), String> {
log::info!("Command: set_audio_output_device {:?}", device);
// Normalize hw:X,0 to stable front:CARD=name,DEV=0 format
// This ensures the saved device ID survives reboots and USB reconnections
let normalized_device = device.as_ref().map(|d| {
crate::audio::normalize_device_id_to_stable(d)
});
log::info!(
"Command: set_audio_output_device {:?} -> {:?} (normalized)",
device,
normalized_device
);
let store = state.store.lock().map_err(|e| format!("Lock error: {}", e))?;
store.set_output_device(device.as_deref())
store.set_output_device(normalized_device.as_deref())
}
#[tauri::command]