From dfb23c9b070710e9612db6600d5875f11245d1c5 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 30 Mar 2025 22:23:32 -0700 Subject: [PATCH] Restore confirmation dialog when connecting to a new radio --- Localizable.xcstrings | 6 ++++++ Meshtastic/Views/Bluetooth/Connect.swift | 23 ++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Localizable.xcstrings b/Localizable.xcstrings index b18b2c18..6f303009 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -5634,6 +5634,9 @@ } } } + }, + "Connect to new radio?" : { + }, "connected" : { "localizations" : { @@ -5842,6 +5845,9 @@ } } } + }, + "Connecting to a new radio will clear all app data on the phone." : { + }, "Connection Attempt %lld of 10" : { "localizations" : { diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index 72b1a6ae..81672c10 100644 --- a/Meshtastic/Views/Bluetooth/Connect.swift +++ b/Meshtastic/Views/Bluetooth/Connect.swift @@ -24,6 +24,7 @@ struct Connect: View { @State var isUnsetRegion = false @State var invalidFirmwareVersion = false @State var liveActivityStarted = false + @State var presentingSwitchPreferredPeripheral = false @State var selectedPeripherialId = "" init () { @@ -214,10 +215,11 @@ struct Connect: View { if let connectedPeripheral = bleManager.connectedPeripheral, connectedPeripheral.peripheral.state == CBPeripheralState.connected { bleManager.disconnectPeripheral() } - clearCoreDataDatabase(context: context, includeRoutes: false) + presentingSwitchPreferredPeripheral = true + selectedPeripherialId = peripheral.peripheral.identifier.uuidString + } else { + self.bleManager.connectTo(peripheral: peripheral.peripheral) } - UserDefaults.preferredPeripheralId = selectedPeripherialId - self.bleManager.connectTo(peripheral: peripheral.peripheral) }) { Text(peripheral.name).font(.callout) } @@ -228,6 +230,21 @@ struct Connect: View { }.padding([.bottom, .top]) } } + .confirmationDialog("Connecting to a new radio will clear all app data on the phone.", isPresented: $presentingSwitchPreferredPeripheral, titleVisibility: .visible) { + Button("Connect to new radio?", role: .destructive) { + UserDefaults.preferredPeripheralId = selectedPeripherialId + UserDefaults.preferredPeripheralNum = 0 + if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.state == CBPeripheralState.connected { + bleManager.disconnectPeripheral() + } + clearCoreDataDatabase(context: context, includeRoutes: false) + let radio = bleManager.peripherals.first(where: { $0.peripheral.identifier.uuidString == selectedPeripherialId }) + if radio != nil { + bleManager.connectTo(peripheral: radio!.peripheral) + } + } + } + .textCase(nil) } } else {