From f64374c8a64392d4440deccbca770944787a4dee Mon Sep 17 00:00:00 2001 From: Joseph Birks Date: Sat, 28 Mar 2026 22:22:43 +0000 Subject: [PATCH] Fix clear_peripherals on CoreBluetooth to clear internal map clear_peripherals() only cleared the AdapterManager's public DashMap but not CoreBluetoothInternal's private HashMap. After clearing, re-discovered peripherals were treated as DeviceUpdated (already known internally) instead of DeviceDiscovered, so they were never re-added to the public map. Send a ClearPeripherals message to the CoreBluetooth thread so both maps are cleared in sync. Windows and Android are unaffected as they only have the single AdapterManager map. --- src/corebluetooth/adapter.rs | 5 +++++ src/corebluetooth/internal.rs | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/corebluetooth/adapter.rs b/src/corebluetooth/adapter.rs index 0c489a28..f1c5170c 100644 --- a/src/corebluetooth/adapter.rs +++ b/src/corebluetooth/adapter.rs @@ -140,6 +140,11 @@ impl Central for Adapter { async fn clear_peripherals(&self) -> Result<()> { self.manager.clear_peripherals(); + self.sender + .to_owned() + .send(CoreBluetoothMessage::ClearPeripherals) + .await + .map_err(|e| Error::Other(Box::new(e)))?; Ok(()) } diff --git a/src/corebluetooth/internal.rs b/src/corebluetooth/internal.rs index c0f42aa6..59ac0b77 100644 --- a/src/corebluetooth/internal.rs +++ b/src/corebluetooth/internal.rs @@ -499,6 +499,7 @@ pub enum CoreBluetoothMessage { peripheral_uuid: Uuid, future: CoreBluetoothReplyStateShared, }, + ClearPeripherals, } #[derive(Debug)] @@ -1438,6 +1439,9 @@ impl CoreBluetoothInternal { CoreBluetoothMessage::ReadRssi{peripheral_uuid, future} => { self.read_rssi(peripheral_uuid, future) } + CoreBluetoothMessage::ClearPeripherals => { + self.peripherals.clear(); + } }; } }