Fix handling of Headset dongle disconnecting

This commit is contained in:
Lennard Kittner
2026-02-20 16:09:26 +01:00
parent a21a79d09c
commit 7fbbb65cb5
3 changed files with 12 additions and 4 deletions

View File

@@ -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:?}");

View File

@@ -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));
};

View File

@@ -5,7 +5,7 @@ pub struct TrayHandler {
handle: Handle<StatusTray>,
}
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 {