From 98218ab3968192ba1cb09d4dfa58949bb9a08b86 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Thu, 14 Sep 2023 21:57:22 +0200 Subject: [PATCH] fix: more gentle libmonado probing (keep monado instance around) --- src/ui/app.rs | 29 +++++++++++++++++++++++------ src/xr_devices.rs | 30 +++++++++++++----------------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/ui/app.rs b/src/ui/app.rs index 8597ab4..94069b3 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -94,6 +94,8 @@ pub struct App { xr_devices: XRDevices, #[tracker::do_not_track] fbt_config_editor: Option>, + #[tracker::do_not_track] + libmonado: Option, } #[derive(Debug)] @@ -218,6 +220,7 @@ impl App { if let Some(worker) = self.xrservice_worker.as_ref() { worker.stop(); } + self.libmonado = None; self.restore_openxr_openvr_files(); self.main_view .sender() @@ -310,12 +313,25 @@ impl SimpleComponent for App { Msg::ClockTicking => { self.main_view.sender().emit(MainViewMsg::ClockTicking); if let Some(w) = self.xrservice_worker.as_ref() { - if w.state.lock().unwrap().exit_status.is_none() { - self.xr_devices - .merge(XRDevices::from_libmonado(&self.get_selected_profile())); - self.main_view - .sender() - .emit(MainViewMsg::UpdateDevices(Some(self.xr_devices.clone()))); + if { + let state = w.state.lock().unwrap(); + state.exit_status.is_none() && !state.stop_requested + } { + if let Some(monado) = self.libmonado.as_ref() { + self.xr_devices + .merge(XRDevices::from_libmonado(monado)); + self.main_view + .sender() + .emit(MainViewMsg::UpdateDevices(Some(self.xr_devices.clone()))); + } + else { + if let Some(so) = self.get_selected_profile().libmonado_so() { + self.libmonado = libmonado_rs::Monado::create(so).ok(); + if self.libmonado.is_some() { + sender.input(Msg::ClockTicking); + } + } + } } } } @@ -657,6 +673,7 @@ impl SimpleComponent for App { xr_devices: XRDevices::default(), fbt_config_editor: None, restart_xrservice: false, + libmonado: None, }; let widgets = view_output!(); diff --git a/src/xr_devices.rs b/src/xr_devices.rs index 06f25b6..2c2e1bc 100644 --- a/src/xr_devices.rs +++ b/src/xr_devices.rs @@ -71,25 +71,21 @@ impl XRDevices { } } - pub fn from_libmonado(prof: &Profile) -> Self { + pub fn from_libmonado(monado: &libmonado_rs::Monado) -> Self { let mut res = Self::default(); - if let Some(libmonado_path) = prof.libmonado_so() { - if let Ok(monado) = libmonado_rs::Monado::create(libmonado_path) { - [ - XRDevice::Head, - XRDevice::Left, - XRDevice::Right, - XRDevice::Gamepad, - XRDevice::Eyes, - ] - .iter() - .for_each(|xrd| { - if let Ok(dev) = monado.device_from_role(xrd.to_monado_str()) { - res.set_device(&xrd, dev.name); - } - }); + [ + XRDevice::Head, + XRDevice::Left, + XRDevice::Right, + XRDevice::Gamepad, + XRDevice::Eyes, + ] + .iter() + .for_each(|xrd| { + if let Ok(dev) = monado.device_from_role(xrd.to_monado_str()) { + res.set_device(&xrd, dev.name); } - } + }); res }