Skip to content

Commit

Permalink
disconnect logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MnlPhlp committed Jan 8, 2025
1 parent f9f6062 commit c692259
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tauri-plugin-blec"
license = "MIT OR Apache-2.0"
version = "0.3.1"
version = "0.3.2"
authors = ["Manuel Philipp"]
description = "BLE-Client plugin for Tauri"
edition = "2021"
Expand Down
14 changes: 5 additions & 9 deletions src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,11 @@ impl btleplug::api::Central for Adapter {
let (tx, rx) = tokio::sync::mpsc::channel::<CentralEvent>(1);
let stream = ReceiverStream::new(rx);
let channel: Channel = Channel::new(move |response| {
match response.deserialize::<CentralEvent>() {
Ok(event) => tx
.blocking_send(event)
.expect("failed to send notification"),
Err(e) => {
tracing::error!("failed to deserialize notification: {:?}", e);
return Err(tauri::Error::from(e));
}
};
let event = response
.deserialize::<CentralEvent>()
.expect("failed to deserialize event");
tx.blocking_send(event)
.expect("failed to send notification");
Ok(())
});
get_handle()
Expand Down
12 changes: 9 additions & 3 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,22 @@ impl Handler {

/// Clears internal state, updates connected flag and calls disconnect callback
async fn handle_disconnect(&self, peripheral_id: PeripheralId) -> Result<(), Error> {
let mut dev = self.connected_dev.lock().await;
if !dev.as_ref().is_some_and(|dev| dev.id() == peripheral_id) {
let connected = self
.connected_dev
.lock()
.await
.as_ref()
.map(btleplug::api::Peripheral::id);
if !connected.as_ref().is_some_and(|c| *c == peripheral_id) {
// event not for currently connected device, ignore
warn!("Unexpected disconnect event for device {peripheral_id}, connected device is {connected:?}",);
return Ok(());
}
{
debug!("locking state for disconnect");
let mut state = self.state.lock().await;
info!("disconnecting");
*dev = None;
*self.connected_dev.lock().await = None;
if let Some(handle) = state.listen_handle.take() {
handle.abort();
}
Expand Down

0 comments on commit c692259

Please sign in to comment.