Refresh state when headset turns on

This commit is contained in:
Lennard Kittner
2026-03-22 12:54:08 +01:00
parent 4d0e835077
commit 4cc44cef9c

View File

@@ -920,9 +920,15 @@ pub trait Device {
/// Refreshes the state by listening for events /// Refreshes the state by listening for events
/// Only the battery level is actively queried because it is not communicated by the device on its own /// Only the battery level is actively queried because it is not communicated by the device on its own
fn passive_refresh_state(&mut self) -> Result<(), DeviceError> { fn passive_refresh_state(&mut self) -> Result<(), DeviceError> {
let mut request_active_refresh = false;
if self.allow_passive_refresh() { if self.allow_passive_refresh() {
if let Some(events) = self.wait_for_updates(PASSIVE_REFRESH_TIME_OUT) { if let Some(events) = self.wait_for_updates(PASSIVE_REFRESH_TIME_OUT) {
for event in events { for event in events {
// Some headsets send this if they just turned on so we should refresh the
// state
if matches!(event, DeviceEvent::WirelessConnected(true)) {
request_active_refresh = true;
}
self.get_device_state_mut().update_self_with_event(&event); self.get_device_state_mut().update_self_with_event(&event);
} }
} }
@@ -933,10 +939,18 @@ pub trait Device {
std::thread::sleep(RESPONSE_DELAY); std::thread::sleep(RESPONSE_DELAY);
if let Some(events) = self.wait_for_updates(Duration::from_secs(1)) { if let Some(events) = self.wait_for_updates(Duration::from_secs(1)) {
for event in events { for event in events {
// Some headsets send this if they just turned on so we should refresh the
// state
if matches!(event, DeviceEvent::WirelessConnected(true)) {
request_active_refresh = true;
}
self.get_device_state_mut().update_self_with_event(&event); self.get_device_state_mut().update_self_with_event(&event);
} }
} }
} }
if request_active_refresh {
self.active_refresh_state()?;
}
Ok(()) Ok(())
} }