From 7fbbb65cb5d3db6b393526d1b79834489d60e01f Mon Sep 17 00:00:00 2001 From: Lennard Kittner Date: Fri, 20 Feb 2026 16:09:26 +0100 Subject: [PATCH] Fix handling of Headset dongle disconnecting --- src/devices/mod.rs | 2 -- src/main.rs | 5 ++++- src/status_tray.rs | 9 ++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/devices/mod.rs b/src/devices/mod.rs index ae3305a..3af4b40 100644 --- a/src/devices/mod.rs +++ b/src/devices/mod.rs @@ -602,8 +602,6 @@ pub trait Device { self.execute_headset_specific_functionality()?; let mut responded = false; - // So we do not immediately break if another response is queued - self.get_device_state_mut().connected = Some(true); for packet in packets.into_iter().flatten() { self.prepare_write(); debug_println!("Write packet: {packet:?}"); diff --git a/src/main.rs b/src/main.rs index 490ae2d..64a2d35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,10 @@ fn main() { let mut device = loop { match connect_compatible_device() { Ok(d) => break d, - Err(e) => eprintln!("Connecting failed with error: {e}"), + Err(e) => { + tray_handler.clear_state(); + eprintln!("Connecting failed with error: {e}") + } } std::thread::sleep(Duration::from_secs(1)); }; diff --git a/src/status_tray.rs b/src/status_tray.rs index 4e7e6e0..5b752de 100644 --- a/src/status_tray.rs +++ b/src/status_tray.rs @@ -5,7 +5,7 @@ pub struct TrayHandler { handle: Handle, } -const NO_COMPATIBLE_DEVICE: &str = "No compatible device found.\nIs the dongle plugged in?\nIf you are using Linux did you add the Udev rules?"; +const NO_COMPATIBLE_DEVICE: &str = "No compatible device found.\nIs the dongle plugged in?\nIf you are using Linux did you\nadd the Udev rules?"; impl TrayHandler { pub fn new(tray: StatusTray) -> Self { @@ -32,6 +32,13 @@ impl TrayHandler { tray.device_name = name; }) } + + pub fn clear_state(&self) { + self.handle.update(|tray| { + tray.message = NO_COMPATIBLE_DEVICE.to_string(); + tray.device_name = None; + }) + } } pub struct StatusTray {