diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 81f0ff70..84c22341 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -32,6 +32,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate public var isConnecting: Bool = false public var isConnected: Bool = false public var isSubscribed: Bool = false + public var allowDisconnect: Bool = false private var configNonce: UInt32 = 1 var timeoutTimer: Timer? var timeoutTimerCount = 0 @@ -172,6 +173,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate isConnecting = false isConnected = false isSubscribed = false + allowDisconnect = false self.connectedPeripheral = nil invalidVersion = false connectedVersion = "0.0.0" @@ -204,6 +206,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate self.FROMRADIO_characteristic = nil self.isConnected = false self.isSubscribed = false + self.allowDisconnect = false self.invalidVersion = false self.connectedVersion = "0.0.0" self.stopScanning() @@ -563,7 +566,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate sendWantConfig() } else { Logger.mesh.error("🚨 Want Config failed after \(self.maxWantConfigRetries) attempts, forcing disconnect") - forceDisconnect() + lastConnectionError = "Bluetooth connection timeout, keep your node closer or reboot your radio if the problem continues.".localized } } @@ -576,12 +579,6 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate } } - private func forceDisconnect() { - disconnectPeripheral(reconnect: false) - lastConnectionError = "Bluetooth connection timeout, keep your node closer or reboot your radio if the problem continues.".localized - Logger.mesh.error("💥 [BLE] Forced disconnect due to Want Config timeout") - } - // Call this to reset the retry mechanism (e.g., on new connection) func resetWantConfigRetries() { wantConfigRetryCount = 0 @@ -1059,6 +1056,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate invalidVersion = false lastConnectionError = "" isSubscribed = true + allowDisconnect = true Logger.mesh.info("🤜 [BLE] Want Config Complete. ID:\(decodedInfo.configCompleteID, privacy: .public)") if sendTime() { } diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index 5e73270e..1176241a 100644 --- a/Meshtastic/Views/Bluetooth/Connect.swift +++ b/Meshtastic/Views/Bluetooth/Connect.swift @@ -90,7 +90,7 @@ struct Connect: View { .foregroundColor(Color.gray) .padding([.top]) .swipeActions { - if bleManager.isSubscribed { + if bleManager.allowDisconnect { Button(role: .destructive) { if let connectedPeripheral = bleManager.connectedPeripheral, connectedPeripheral.peripheral.state == .connected { @@ -127,7 +127,7 @@ struct Connect: View { Text("Short Name: \(node?.user?.shortName ?? "?")") Text("Long Name: \(node?.user?.longName?.addingVariationSelectors ?? "Unknown".localized)") Text("BLE RSSI: \(connectedPeripheral.rssi)") - if bleManager.isSubscribed { + if bleManager.allowDisconnect { Button(role: .destructive) { if let connectedPeripheral = bleManager.connectedPeripheral, connectedPeripheral.peripheral.state == .connected {