From 25ca292c55e9c9bb29dd047785a7d0383ec6f3ab Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Thu, 12 Jun 2025 08:43:07 -0700 Subject: [PATCH] Add option to reset keys and ble bonds to factory reset --- Localizable.xcstrings | 123 ++---------------- Meshtastic/Helpers/BLEManager.swift | 8 +- .../Views/Settings/Config/DeviceConfig.swift | 14 +- 3 files changed, 29 insertions(+), 116 deletions(-) diff --git a/Localizable.xcstrings b/Localizable.xcstrings index ccf11c60..9ea910d4 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -2809,34 +2809,6 @@ } } }, - "All device and app data will be deleted." : { - "localizations" : { - "it" : { - "stringUnit" : { - "state" : "translated", - "value" : "Tutti i dati del dispositivo e delle app verranno eliminati." - } - }, - "sr" : { - "stringUnit" : { - "state" : "translated", - "value" : "Сви подаци о уређају и апликацији ће бити избрисани." - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "所有设备以及 App 数据都会被删除。" - } - }, - "zh-Hant-TW" : { - "stringUnit" : { - "state" : "translated", - "value" : "全部的設備及App資料將會被刪除。" - } - } - } - }, "Allow incoming device control over the insecure legacy admin channel." : { "localizations" : { "de" : { @@ -8139,6 +8111,12 @@ } } } + }, + "Delete all config, keys and BLE bonds? " : { + + }, + "Delete all config? " : { + }, "Delete all device metrics?" : { "localizations" : { @@ -10719,64 +10697,10 @@ } } }, - "Enabling Ethernet will disable the bluetooth connection to the app." : { - "localizations" : { - "it" : { - "stringUnit" : { - "state" : "translated", - "value" : "Abilitando l'Ethernet si disabilita la connessione bluetooth all'applicazione." - } - }, - "sr" : { - "stringUnit" : { - "state" : "translated", - "value" : "Омогућавање етернета ће онемогућити блутут везу са апликацијом." - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "启用以太网将禁用应用程序的蓝牙连接。" - } - }, - "zh-Hant-TW" : { - "stringUnit" : { - "state" : "translated", - "value" : "啟用乙太網路後,將會停用與應用程式的藍牙連線。" - } - } - } + "Enabling Ethernet will disable the bluetooth connection to the app. TCP node connections are not available on Apple devices." : { + }, - "Enabling WiFi will disable the bluetooth connection to the app." : { - "extractionState" : "stale", - "localizations" : { - "it" : { - "stringUnit" : { - "state" : "translated", - "value" : "L'attivazione del WiFi disabilita la connessione bluetooth all'applicazione." - } - }, - "sr" : { - "stringUnit" : { - "state" : "translated", - "value" : "Омогућавање ВајФаја ће онемогућити блутут везу са апликацијом." - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "启用 WiFi 将禁用应用程序的蓝牙连接。" - } - }, - "zh-Hant-TW" : { - "stringUnit" : { - "state" : "translated", - "value" : "啟用 Wi-Fi 後,將會停用與應用程式的藍牙連線。" - } - } - } - }, - "Enabling WiFi will disable the bluetooth connection to the app. TCP node connections are not available on apple devices." : { + "Enabling WiFi will disable the bluetooth connection to the app. TCP node connections are not available on Apple devices." : { }, "Encoder Press Event" : { @@ -11677,33 +11601,8 @@ } } }, - "Factory reset your device and app? " : { - "localizations" : { - "de" : { - "stringUnit" : { - "state" : "translated", - "value" : "Gerät und App auf Werkseinstellungen zurücksetzen?" - } - }, - "it" : { - "stringUnit" : { - "state" : "translated", - "value" : "Resettare il dispositivo e l'applicazione? " - } - }, - "sr" : { - "stringUnit" : { - "state" : "translated", - "value" : "Вратите уређај и апликацију на фабричка подешавања?" - } - }, - "zh-Hant-TW" : { - "stringUnit" : { - "state" : "translated", - "value" : "要將您的裝置與應用程式恢復原廠設定嗎?" - } - } - } + "Factory reset will delete device and app data." : { + }, "Failed to encode message content" : { "localizations" : { diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index ff822e90..c1dc7023 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -1532,9 +1532,13 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate return false } - public func sendFactoryReset(fromUser: UserEntity, toUser: UserEntity) -> Bool { + public func sendFactoryReset(fromUser: UserEntity, toUser: UserEntity, resetDevice: Bool = false) -> Bool { var adminPacket = AdminMessage() - adminPacket.factoryResetConfig = 5 + if resetDevice { + adminPacket.factoryResetDevice = 5 + } else { + adminPacket.factoryResetConfig = 5 + } if fromUser != toUser { adminPacket.sessionPasskey = toUser.userNode?.sessionPasskey ?? Data() } diff --git a/Meshtastic/Views/Settings/Config/DeviceConfig.swift b/Meshtastic/Views/Settings/Config/DeviceConfig.swift index cd812e5d..bb9b6916 100644 --- a/Meshtastic/Views/Settings/Config/DeviceConfig.swift +++ b/Meshtastic/Views/Settings/Config/DeviceConfig.swift @@ -204,11 +204,11 @@ struct DeviceConfig: View { .controlSize(.regular) .padding(.trailing) .confirmationDialog( - "All device and app data will be deleted.", + "Factory reset will delete device and app data.", isPresented: $isPresentingFactoryResetConfirm, titleVisibility: .visible ) { - Button("Factory reset your device and app? ", role: .destructive) { + Button("Delete all config? ", role: .destructive) { if bleManager.sendFactoryReset(fromUser: node!.user!, toUser: node!.user!) { DispatchQueue.main.asyncAfter(deadline: .now() + 1) { bleManager.disconnectPeripheral() @@ -218,6 +218,16 @@ struct DeviceConfig: View { Logger.mesh.error("Factory Reset Failed") } } + Button("Delete all config, keys and BLE bonds? ", role: .destructive) { + if bleManager.sendFactoryReset(fromUser: node!.user!, toUser: node!.user!, resetDevice: true) { + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + bleManager.disconnectPeripheral() + clearCoreDataDatabase(context: context, includeRoutes: false) + } + } else { + Logger.mesh.error("Factory Reset Failed") + } + } } } }