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:
parent
82dd9a324d
commit
3b95df9e9c
17 changed files with 780 additions and 210 deletions
|
|
@ -1,42 +1,22 @@
|
|||
use anyhow::{Result, anyhow};
|
||||
use cpal::Device;
|
||||
use cpal::traits::{DeviceTrait, HostTrait};
|
||||
use cpal::traits::HostTrait;
|
||||
use tracing::warn;
|
||||
|
||||
pub fn output_at(index: usize) -> Result<Device> {
|
||||
/// Opens the output with persisted id `id`; an empty id is the system default. A saved
|
||||
/// device that has disappeared falls back to the default instead of failing the join.
|
||||
pub fn open_output(id: &str) -> Result<Device> {
|
||||
let host = cpal::default_host();
|
||||
if index == 0 {
|
||||
return host
|
||||
.default_output_device()
|
||||
.ok_or_else(|| anyhow!("no default output device"));
|
||||
}
|
||||
|
||||
let devices: Vec<Device> = host.output_devices()?.collect();
|
||||
|
||||
let mut names: Vec<String> = Vec::new();
|
||||
for dev in &devices {
|
||||
if let Ok(name) = dev.description().map(|d| d.name().to_string())
|
||||
&& !name.is_empty()
|
||||
&& !names.contains(&name)
|
||||
{
|
||||
names.push(name);
|
||||
if !id.is_empty() {
|
||||
let alsa = super::is_alsa(&host);
|
||||
if let Some(device) = super::find_by_id(host.output_devices()?, id, alsa) {
|
||||
return Ok(device);
|
||||
}
|
||||
warn!(
|
||||
device = id,
|
||||
"saved output device not found, using the system default"
|
||||
);
|
||||
}
|
||||
|
||||
let name = names
|
||||
.get(index.saturating_sub(1))
|
||||
.ok_or_else(|| anyhow!("output device index {index} out of range"))?;
|
||||
|
||||
for dev in devices {
|
||||
if dev
|
||||
.description()
|
||||
.map(|d| d.name().to_string())
|
||||
.ok()
|
||||
.as_deref()
|
||||
== Some(name.as_str())
|
||||
{
|
||||
return Ok(dev);
|
||||
}
|
||||
}
|
||||
|
||||
Err(anyhow!("output device not found: {name}"))
|
||||
host.default_output_device()
|
||||
.ok_or_else(|| anyhow!("no default output device"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue