From d30e7c4e2c4cb7b12b3d2a76265a460a2027656f Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Sat, 31 Jan 2026 14:55:55 -0800 Subject: [PATCH 1/2] Prevent disconnection handling when already disconnected, curing a race condition. --- lib/connector/meshcore_connector.dart | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 1bab130..d5a36e3 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -706,7 +706,7 @@ class MeshCoreConnector extends ChangeNotifier { try { _connectionSubscription = device.connectionState.listen((state) { - if (state == BluetoothConnectionState.disconnected) { + if (state == BluetoothConnectionState.disconnected && isConnected) { _handleDisconnection(); } }); @@ -959,12 +959,7 @@ class MeshCoreConnector extends ChangeNotifier { if (!isConnected) return; if (_batteryRequested && !force) return; _batteryRequested = true; - try { - await sendFrame(buildGetBattAndStorageFrame()); - } catch (e) { - // Connection likely lost - trigger disconnection handling - _handleDisconnection(); - } + await sendFrame(buildGetBattAndStorageFrame()); } void _startBatteryPolling() { From 6d7d51f0a4cd1c5f44cd7b425540d5602fb4cd91 Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Sat, 31 Jan 2026 16:03:05 -0800 Subject: [PATCH 2/2] _requestDeviceInfo added isConnected not already _awaitingSelfInfo --- lib/connector/meshcore_connector.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index d5a36e3..3a36a92 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -990,6 +990,7 @@ class MeshCoreConnector extends ChangeNotifier { } Future _requestDeviceInfo() async { + if (!isConnected || _awaitingSelfInfo) return; _awaitingSelfInfo = true; await sendFrame(buildDeviceQueryFrame()); await sendFrame(buildAppStartFrame());