From aaf6ee66eb1e32688d8a134125f683c199622960 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Mon, 20 Jun 2022 23:48:47 -0700 Subject: [PATCH 1/2] Only allow editing of loraconfig if there are changes --- .../Views/Settings/LoRaConfig.swift | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/MeshtasticApple/Views/Settings/LoRaConfig.swift b/MeshtasticApple/Views/Settings/LoRaConfig.swift index 19e16043..08b89f05 100644 --- a/MeshtasticApple/Views/Settings/LoRaConfig.swift +++ b/MeshtasticApple/Views/Settings/LoRaConfig.swift @@ -188,6 +188,10 @@ struct LoRaConfig: View { var node: NodeInfoEntity @State private var isPresentingSaveConfirm: Bool = false + @State var initialLoad: Bool = true + @State var loadComplete: Bool = false + + @State var region = 0 @State var modemPreset = 0 @State var hopLimit = 0 @@ -280,30 +284,38 @@ struct LoRaConfig: View { }) .onAppear { - self.bleManager.context = context - } - .task { - do { + if self.initialLoad{ + + self.bleManager.context = context print("got hops \(node.loRaConfig?.hopLimit ?? 0)") self.hopLimit = Int(node.loRaConfig?.hopLimit ?? 0) self.region = Int(node.loRaConfig?.regionCode ?? 0) self.modemPreset = Int(node.loRaConfig?.modemPreset ?? 0) self.hasChanges = false - } catch { - print("Failed to load node data") + self.initialLoad = false + self.loadComplete = true } } .onChange(of: region) { newRegion in - hasChanges = true + if newRegion != node.loRaConfig!.regionCode { + + hasChanges = true + } } .onChange(of: modemPreset) { newModemPreset in - hasChanges = true + if newModemPreset != node.loRaConfig!.modemPreset { + + hasChanges = true + } } .onChange(of: hopLimit) { newHopLimit in - hasChanges = true + if newHopLimit != node.loRaConfig!.hopLimit { + + hasChanges = true + } } .navigationViewStyle(StackNavigationViewStyle()) From 7a75a3199a2f93d61ff0a46680cde8f993b5d7f0 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Mon, 20 Jun 2022 23:50:59 -0700 Subject: [PATCH 2/2] delete loadComplete that does nothing --- MeshtasticApple/Views/Settings/LoRaConfig.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/MeshtasticApple/Views/Settings/LoRaConfig.swift b/MeshtasticApple/Views/Settings/LoRaConfig.swift index 08b89f05..7bef9ffa 100644 --- a/MeshtasticApple/Views/Settings/LoRaConfig.swift +++ b/MeshtasticApple/Views/Settings/LoRaConfig.swift @@ -189,8 +189,6 @@ struct LoRaConfig: View { @State private var isPresentingSaveConfirm: Bool = false @State var initialLoad: Bool = true - @State var loadComplete: Bool = false - @State var region = 0 @State var modemPreset = 0 @@ -293,7 +291,6 @@ struct LoRaConfig: View { self.modemPreset = Int(node.loRaConfig?.modemPreset ?? 0) self.hasChanges = false self.initialLoad = false - self.loadComplete = true } } .onChange(of: region) { newRegion in