diff --git a/Cargo.toml b/Cargo.toml index 1884bc5..b1ca7ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/android.rs b/src/android.rs index 56f7cc4..83d64ed 100644 --- a/src/android.rs +++ b/src/android.rs @@ -78,15 +78,11 @@ impl btleplug::api::Central for Adapter { let (tx, rx) = tokio::sync::mpsc::channel::(1); let stream = ReceiverStream::new(rx); let channel: Channel = Channel::new(move |response| { - match response.deserialize::() { - 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::() + .expect("failed to deserialize event"); + tx.blocking_send(event) + .expect("failed to send notification"); Ok(()) }); get_handle() diff --git a/src/handler.rs b/src/handler.rs index 89c2add..18eaf8e 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -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(); }