mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-03 22:58:44 +00:00
feat: small refactor of physical xr device detection and subsequent profile selection
This commit is contained in:
parent
34d29a05b4
commit
2bd0b12e91
2 changed files with 44 additions and 44 deletions
|
@ -2,7 +2,7 @@ use serde::{de::Error, Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
constants::CMD_NAME,
|
constants::CMD_NAME,
|
||||||
device_prober::get_xr_usb_devices,
|
device_prober::PhysicalXRDevice,
|
||||||
file_utils::get_writer,
|
file_utils::get_writer,
|
||||||
paths::get_config_dir,
|
paths::get_config_dir,
|
||||||
profile::Profile,
|
profile::Profile,
|
||||||
|
@ -46,18 +46,16 @@ impl Config {
|
||||||
pub fn get_selected_profile(&self, profiles: &[Profile]) -> Profile {
|
pub fn get_selected_profile(&self, profiles: &[Profile]) -> Profile {
|
||||||
let def = || profiles.first().expect("No profiles found").clone();
|
let def = || profiles.first().expect("No profiles found").clone();
|
||||||
|
|
||||||
match profiles
|
if let Some(p) = profiles
|
||||||
.iter()
|
.iter()
|
||||||
.find(|p| p.uuid == self.selected_profile_uuid)
|
.find(|p| p.uuid == self.selected_profile_uuid)
|
||||||
{
|
{
|
||||||
Some(p) => p.clone(),
|
p.clone()
|
||||||
None => match get_xr_usb_devices().first() {
|
} else {
|
||||||
Some(dev) => match dev.get_default_profile() {
|
PhysicalXRDevice::from_usb()
|
||||||
Some(p) => p,
|
.first()
|
||||||
None => def(),
|
.and_then(|xrd| xrd.get_default_profile())
|
||||||
},
|
.unwrap_or_else(def)
|
||||||
None => def(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,8 @@ fn list_usb_devs() -> Vec<(u16, u16)> {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_xr_usb_devices() -> Vec<PhysicalXRDevice> {
|
impl PhysicalXRDevice {
|
||||||
|
pub fn from_usb() -> Vec<Self> {
|
||||||
list_usb_devs()
|
list_usb_devs()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|t| match t {
|
.filter_map(|t| match t {
|
||||||
|
@ -186,3 +187,4 @@ pub fn get_xr_usb_devices() -> Vec<PhysicalXRDevice> {
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue