use device name instead of node id to get audio device

This commit is contained in:
2025-10-05 23:26:29 +03:00
parent d877f79d5c
commit 874c8063aa
11 changed files with 35 additions and 42 deletions
+2 -7
View File
@@ -44,13 +44,8 @@ pub fn parse_command(request: &Request) -> Option<Box<dyn Executable + Send>> {
"get_input" => Some(Box::new(GetCurrentInputCommand {})),
"get_inputs" => Some(Box::new(GetAllInputsCommand {})),
"set_input" => {
let id = request
.args
.get("input_id")
.unwrap_or(&String::new())
.parse::<u32>()
.ok();
Some(Box::new(SetCurrentInputCommand { id }))
let name = Some(request.args.get("input_name").unwrap_or(&String::new())).cloned();
Some(Box::new(SetCurrentInputCommand { name }))
}
_ => None,
}
+6 -11
View File
@@ -96,10 +96,8 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
.collect::<Vec<&str>>()
.first()
.unwrap()
.to_string()
.parse::<u32>()
.unwrap_or_default(),
false => 0,
.to_string(),
false => String::new(),
};
let all_inputs = match all_inputs_res.status {
true => all_inputs_res
@@ -111,14 +109,11 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
if entry.is_empty() {
return None;
}
entry.split_once(" - ").and_then(|(k, v)| {
k.trim()
.parse::<u32>()
.ok()
.map(|key| (key, v.trim().to_string()))
})
entry
.split_once(" - ")
.map(|(k, v)| (k.trim().to_string(), v.trim().to_string()))
})
.collect(),
.collect::<HashMap<String, String>>(),
false => HashMap::new(),
};
+2 -2
View File
@@ -199,12 +199,12 @@ pub async fn get_all_devices() -> Result<(Vec<AudioDevice>, Vec<AudioDevice>), B
}
}
pub async fn get_device(node_id: u32) -> Result<AudioDevice, Box<dyn Error>> {
pub async fn get_device(device_name: &str) -> Result<AudioDevice, Box<dyn Error>> {
let (mut input_devices, output_devices) = get_all_devices().await?;
input_devices.extend(output_devices);
for device in input_devices {
if device.id == node_id {
if device.name == device_name {
return Ok(device);
}
}