fix(client): list only real audio devices and persist the choice by id

The device pickers showed every ALSA PCM plugin (Discard all samples, Rate
Converter, JACK, Open Sound System, surround/dmix aliases). Enumeration now
goes through a pure filter that keeps the system default, the PipeWire and
PulseAudio servers and one entry per hardware endpoint, with technical tails
removed and a stable sort.

Selections are stored by device id instead of list position, so the filter
and hotplug cannot move a saved choice. Indexes saved by older versions are
migrated by device name; a missing device falls back to the default.

The same preferences change records whether the voice mode was chosen by
the person: a profile that only carries the old push-to-talk default now
starts in voice activation, explicit choices are kept.
This commit is contained in:
Loki 2026-10-24 23:59:27 +02:00
parent 82dd9a324d
commit 3b95df9e9c
Signed by: boba
GPG key ID: 253067914055423B
17 changed files with 780 additions and 210 deletions

View file

@ -69,7 +69,7 @@ fn main() -> Result<()> {
}
let window = MainWindow::new()?;
window.set_address_input(state.borrow().ui.connect_input.as_str().into());
refresh_devices(&window);
refresh_devices(&window, &mut state.borrow_mut().ui);
let webhook_net = state.borrow().net.clone();
state.borrow_mut().webhooks = Some(Rc::new(ui::webhooks::WebhookUi::new(Rc::new(
@ -144,22 +144,27 @@ fn load_identity() -> Result<Option<identity::Identity>> {
}
}
fn refresh_devices(window: &MainWindow) {
let devices = vnox_client::audio::devices::enumerate().unwrap_or_default();
let model = |mut items: Vec<String>| {
if items.is_empty() {
items.push(crate::ui::i18n::text("Default"));
}
fn refresh_devices(window: &MainWindow, ui: &mut UiState) {
crate::ui::devices::refresh(ui);
let model = |items: Vec<String>| {
Rc::new(slint::VecModel::from(
items
.into_iter()
.map(slint::SharedString::from)
.enumerate()
.map(|(index, label)| {
// Position 0 is always the system default.
slint::SharedString::from(if index == 0 {
crate::ui::i18n::text("System default")
} else {
label
})
})
.collect::<Vec<_>>(),
))
.into()
};
window.set_input_devices(model(devices.input_labels));
window.set_output_devices(model(devices.output_labels));
window.set_input_devices(model(ui.device_lists.input_labels()));
window.set_output_devices(model(ui.device_lists.output_labels()));
}
fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
@ -220,9 +225,10 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
let state = state.clone();
let weak = window.as_weak();
window.on_open_settings(move || {
state.borrow_mut().ui.settings_open = true;
let mut s = state.borrow_mut();
s.ui.settings_open = true;
if let Some(window) = weak.upgrade() {
refresh_devices(&window);
refresh_devices(&window, &mut s.ui);
}
});
}
@ -242,10 +248,14 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
let state = state.clone();
window.on_audio_settings_changed(move |input, output, bitrate, mode, volume| {
let mut s = state.borrow_mut();
s.ui.mic_device = input.max(0) as usize;
s.ui.output_device = output.max(0) as usize;
crate::ui::devices::select(&mut s.ui, input.max(0) as usize, output.max(0) as usize);
s.ui.voice_bitrate = bitrate.clamp(8.0, 128.0);
s.ui.vad_mode = mode.clamp(0, 2) as usize;
let mode = mode.clamp(0, 2) as usize;
if mode != s.ui.vad_mode {
// Only a real change counts as the person's own choice.
s.ui.vad_mode_chosen = true;
}
s.ui.vad_mode = mode;
s.ui.output_volume = volume.clamp(0.0, 100.0);
if let Err(error) = crate::ui::preferences::save(&s.ui) {
s.ui.status_msg = Some(ui::i18n::Message::with(