Feat: better engine output device switching
This commit is contained in:
@@ -224,16 +224,16 @@ pub(super) fn handle_engine_page(ctx: &mut InputContext, key: KeyEvent) -> Input
|
|||||||
DeviceKind::Output => {
|
DeviceKind::Output => {
|
||||||
let cursor = ctx.app.audio.output_list.cursor;
|
let cursor = ctx.app.audio.output_list.cursor;
|
||||||
if cursor < ctx.app.audio.output_devices.len() {
|
if cursor < ctx.app.audio.output_devices.len() {
|
||||||
let name = ctx.app.audio.output_devices[cursor].name.clone();
|
let index = ctx.app.audio.output_devices[cursor].index;
|
||||||
ctx.dispatch(AppCommand::SetOutputDevice(name));
|
ctx.dispatch(AppCommand::SetOutputDevice(index.to_string()));
|
||||||
ctx.app.save_settings(ctx.link);
|
ctx.app.save_settings(ctx.link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DeviceKind::Input => {
|
DeviceKind::Input => {
|
||||||
let cursor = ctx.app.audio.input_list.cursor;
|
let cursor = ctx.app.audio.input_list.cursor;
|
||||||
if cursor < ctx.app.audio.input_devices.len() {
|
if cursor < ctx.app.audio.input_devices.len() {
|
||||||
let name = ctx.app.audio.input_devices[cursor].name.clone();
|
let index = ctx.app.audio.input_devices[cursor].index;
|
||||||
ctx.dispatch(AppCommand::SetInputDevice(name));
|
ctx.dispatch(AppCommand::SetInputDevice(index.to_string()));
|
||||||
ctx.app.save_settings(ctx.link);
|
ctx.app.save_settings(ctx.link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -448,11 +448,19 @@ impl AudioSettings {
|
|||||||
|
|
||||||
pub fn current_output_device_index(&self) -> usize {
|
pub fn current_output_device_index(&self) -> usize {
|
||||||
match &self.config.output_device {
|
match &self.config.output_device {
|
||||||
Some(name) => self
|
Some(spec) => {
|
||||||
.output_devices
|
if let Ok(idx) = spec.parse::<usize>() {
|
||||||
.iter()
|
self.output_devices
|
||||||
.position(|d| &d.name == name)
|
.iter()
|
||||||
.unwrap_or(0),
|
.position(|d| d.index == idx)
|
||||||
|
.unwrap_or(0)
|
||||||
|
} else {
|
||||||
|
self.output_devices
|
||||||
|
.iter()
|
||||||
|
.position(|d| &d.name == spec)
|
||||||
|
.unwrap_or(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
None => self
|
None => self
|
||||||
.output_devices
|
.output_devices
|
||||||
.iter()
|
.iter()
|
||||||
@@ -463,11 +471,19 @@ impl AudioSettings {
|
|||||||
|
|
||||||
pub fn current_input_device_index(&self) -> usize {
|
pub fn current_input_device_index(&self) -> usize {
|
||||||
match &self.config.input_device {
|
match &self.config.input_device {
|
||||||
Some(name) => self
|
Some(spec) => {
|
||||||
.input_devices
|
if let Ok(idx) = spec.parse::<usize>() {
|
||||||
.iter()
|
self.input_devices
|
||||||
.position(|d| &d.name == name)
|
.iter()
|
||||||
.unwrap_or(0),
|
.position(|d| d.index == idx)
|
||||||
|
.unwrap_or(0)
|
||||||
|
} else {
|
||||||
|
self.input_devices
|
||||||
|
.iter()
|
||||||
|
.position(|d| &d.name == spec)
|
||||||
|
.unwrap_or(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
None => self
|
None => self
|
||||||
.input_devices
|
.input_devices
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
Reference in New Issue
Block a user