diff --git a/src/input/engine_page.rs b/src/input/engine_page.rs index 2269b74..dba4504 100644 --- a/src/input/engine_page.rs +++ b/src/input/engine_page.rs @@ -224,16 +224,16 @@ pub(super) fn handle_engine_page(ctx: &mut InputContext, key: KeyEvent) -> Input DeviceKind::Output => { let cursor = ctx.app.audio.output_list.cursor; if cursor < ctx.app.audio.output_devices.len() { - let name = ctx.app.audio.output_devices[cursor].name.clone(); - ctx.dispatch(AppCommand::SetOutputDevice(name)); + let index = ctx.app.audio.output_devices[cursor].index; + ctx.dispatch(AppCommand::SetOutputDevice(index.to_string())); ctx.app.save_settings(ctx.link); } } DeviceKind::Input => { let cursor = ctx.app.audio.input_list.cursor; if cursor < ctx.app.audio.input_devices.len() { - let name = ctx.app.audio.input_devices[cursor].name.clone(); - ctx.dispatch(AppCommand::SetInputDevice(name)); + let index = ctx.app.audio.input_devices[cursor].index; + ctx.dispatch(AppCommand::SetInputDevice(index.to_string())); ctx.app.save_settings(ctx.link); } } diff --git a/src/state/audio.rs b/src/state/audio.rs index b7cd64a..3c4f9c8 100644 --- a/src/state/audio.rs +++ b/src/state/audio.rs @@ -448,11 +448,19 @@ impl AudioSettings { pub fn current_output_device_index(&self) -> usize { match &self.config.output_device { - Some(name) => self - .output_devices - .iter() - .position(|d| &d.name == name) - .unwrap_or(0), + Some(spec) => { + if let Ok(idx) = spec.parse::() { + self.output_devices + .iter() + .position(|d| d.index == idx) + .unwrap_or(0) + } else { + self.output_devices + .iter() + .position(|d| &d.name == spec) + .unwrap_or(0) + } + } None => self .output_devices .iter() @@ -463,11 +471,19 @@ impl AudioSettings { pub fn current_input_device_index(&self) -> usize { match &self.config.input_device { - Some(name) => self - .input_devices - .iter() - .position(|d| &d.name == name) - .unwrap_or(0), + Some(spec) => { + if let Ok(idx) = spec.parse::() { + self.input_devices + .iter() + .position(|d| d.index == idx) + .unwrap_or(0) + } else { + self.input_devices + .iter() + .position(|d| &d.name == spec) + .unwrap_or(0) + } + } None => self .input_devices .iter()