Prevent disconnection handling when already disconnected, curing a race condition.

chore/offband-rebrand
Winston Lowe 8 months ago
parent 90ce46392a
commit d30e7c4e2c

@ -706,7 +706,7 @@ class MeshCoreConnector extends ChangeNotifier {
try { try {
_connectionSubscription = device.connectionState.listen((state) { _connectionSubscription = device.connectionState.listen((state) {
if (state == BluetoothConnectionState.disconnected) { if (state == BluetoothConnectionState.disconnected && isConnected) {
_handleDisconnection(); _handleDisconnection();
} }
}); });
@ -959,12 +959,7 @@ class MeshCoreConnector extends ChangeNotifier {
if (!isConnected) return; if (!isConnected) return;
if (_batteryRequested && !force) return; if (_batteryRequested && !force) return;
_batteryRequested = true; _batteryRequested = true;
try { await sendFrame(buildGetBattAndStorageFrame());
await sendFrame(buildGetBattAndStorageFrame());
} catch (e) {
// Connection likely lost - trigger disconnection handling
_handleDisconnection();
}
} }
void _startBatteryPolling() { void _startBatteryPolling() {

Loading…
Cancel
Save

Powered by TurnKey Linux.