diff --git a/src/ui/app.rs b/src/ui/app.rs index 9024a7b..523bc79 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -252,6 +252,9 @@ impl App { } pub fn shutdown_xrservice(&mut self) { + if let Some(worker) = self.autostart_worker.as_ref() { + worker.stop(); + } self.xrservice_ready = false; if let Some(w) = self.openxr_prober_worker.as_ref() { w.stop(); @@ -262,9 +265,6 @@ impl App { if let Some(worker) = self.xrservice_worker.as_ref() { worker.stop(); } - if let Some(worker) = self.autostart_worker.as_ref() { - worker.stop(); - } self.libmonado = None; self.main_view .sender() diff --git a/src/ui/job_worker/mod.rs b/src/ui/job_worker/mod.rs index 0c6c689..bf3c396 100644 --- a/src/ui/job_worker/mod.rs +++ b/src/ui/job_worker/mod.rs @@ -89,17 +89,26 @@ impl JobWorker { } pub fn stop(&self) { - if self.state.lock().unwrap().started && !self.state.lock().unwrap().exited { + let should_stop_manually = { + let state = self.state.lock().unwrap(); + state.started && !state.exited + }; + if should_stop_manually { self.state.lock().unwrap().stop_requested = true; if let Some(pid) = self.state.lock().unwrap().current_pid { - kill(pid, SIGTERM).expect("Could not send sigterm to process"); + if let Err(e) = kill(pid, SIGTERM) { + eprintln!("Failed to send SIGTERM: {e:#?}"); + } let state = self.state.clone(); thread::spawn(move || { sleep(Duration::from_secs(2)); if let Ok(s) = state.lock() { if !s.exited { // process is still alive - kill(pid, SIGKILL).expect("Failed to kill process"); + eprintln!("Process is still alive 2 seconds after SIGTERM, proceeding to send SIGKILL..."); + if let Err(e) = kill(pid, SIGKILL) { + eprintln!("Failed to send SIGKILL: {e:#?}"); + }; } } });