WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 5ea27d3

Browse files
committed
fix: bluez device disconnection
1 parent 295f817 commit 5ea27d3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/bluez/adapter.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,15 @@ async fn central_event(
143143
Some(CentralEvent::DeviceDiscovered(device.id.into()))
144144
}
145145
DeviceEvent::Connected { connected } => {
146-
let device = session.get_device_info(&id).await.ok()?;
147-
if connected {
148-
Some(CentralEvent::DeviceConnected(device.id.into()))
146+
// device may be unknown if unpaired manually from the system
147+
let device = session.get_device_info(&id).await;
148+
if device.is_ok() && connected {
149+
Some(CentralEvent::DeviceConnected(id.into()))
150+
} else if !connected {
151+
Some(CentralEvent::DeviceDisconnected(id.into()))
149152
} else {
150-
Some(CentralEvent::DeviceDisconnected(device.id.into()))
153+
// unexpected state. connected without device_info
154+
None
151155
}
152156
}
153157
DeviceEvent::Rssi { rssi: _ } => {

0 commit comments

Comments
 (0)