feat: small refactor of physical xr device detection and subsequent profile selection

This commit is contained in:
Gabriele Musco 2024-08-05 13:32:15 +02:00
commit 2bd0b12e91
2 changed files with 44 additions and 44 deletions

View file

@ -2,7 +2,7 @@ use serde::{de::Error, Deserialize, Serialize};
use crate::{
constants::CMD_NAME,
device_prober::get_xr_usb_devices,
device_prober::PhysicalXRDevice,
file_utils::get_writer,
paths::get_config_dir,
profile::Profile,
@ -46,18 +46,16 @@ impl Config {
pub fn get_selected_profile(&self, profiles: &[Profile]) -> Profile {
let def = || profiles.first().expect("No profiles found").clone();
match profiles
if let Some(p) = profiles
.iter()
.find(|p| p.uuid == self.selected_profile_uuid)
{
Some(p) => p.clone(),
None => match get_xr_usb_devices().first() {
Some(dev) => match dev.get_default_profile() {
Some(p) => p,
None => def(),
},
None => def(),
},
p.clone()
} else {
PhysicalXRDevice::from_usb()
.first()
.and_then(|xrd| xrd.get_default_profile())
.unwrap_or_else(def)
}
}

View file

@ -151,7 +151,8 @@ fn list_usb_devs() -> Vec<(u16, u16)> {
.collect()
}
pub fn get_xr_usb_devices() -> Vec<PhysicalXRDevice> {
impl PhysicalXRDevice {
pub fn from_usb() -> Vec<Self> {
list_usb_devs()
.into_iter()
.filter_map(|t| match t {
@ -186,3 +187,4 @@ pub fn get_xr_usb_devices() -> Vec<PhysicalXRDevice> {
})
.collect()
}
}