From 9b50626ebe0a3141180771becde45902b4754454 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 18 Aug 2024 10:00:15 -0700 Subject: [PATCH] Clean up admin drop down --- .../CoreData/NodeInfoEntityExtension.swift | 9 +++++++++ .../Views/Settings/Config/SecurityConfig.swift | 3 +++ Meshtastic/Views/Settings/Settings.swift | 13 ++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Meshtastic/Extensions/CoreData/NodeInfoEntityExtension.swift b/Meshtastic/Extensions/CoreData/NodeInfoEntityExtension.swift index eb0086c7..c7a03e33 100644 --- a/Meshtastic/Extensions/CoreData/NodeInfoEntityExtension.swift +++ b/Meshtastic/Extensions/CoreData/NodeInfoEntityExtension.swift @@ -58,6 +58,15 @@ extension NodeInfoEntity { } return false } + + var canRemoteAdmin: Bool { + if !(securityConfig?.adminKey?.isEmpty ?? true) { + return true + } else { + let adminChannel = myInfo?.channels?.filter { ($0 as AnyObject).name?.lowercased() == "admin" } + return adminChannel?.count ?? 0 > 0 + } + } } public func createNodeInfo(num: Int64, context: NSManagedObjectContext) -> NodeInfoEntity { diff --git a/Meshtastic/Views/Settings/Config/SecurityConfig.swift b/Meshtastic/Views/Settings/Config/SecurityConfig.swift index 642a8fb7..81672a15 100644 --- a/Meshtastic/Views/Settings/Config/SecurityConfig.swift +++ b/Meshtastic/Views/Settings/Config/SecurityConfig.swift @@ -120,6 +120,9 @@ struct SecurityConfig: View { .onChange(of: adminChannelEnabled) { if $0 != node?.securityConfig?.adminChannelEnabled { hasChanges = true } } + .onChange(of: adminKey) { _ in + hasChanges = true + } SaveConfigButton(node: node, hasChanges: $hasChanges) { guard let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral.num, context: context), diff --git a/Meshtastic/Views/Settings/Settings.swift b/Meshtastic/Views/Settings/Settings.swift index 85aafd8f..3bf91f3c 100644 --- a/Meshtastic/Views/Settings/Settings.swift +++ b/Meshtastic/Views/Settings/Settings.swift @@ -348,13 +348,13 @@ struct Settings: View { if !(node?.deviceConfig?.isManaged ?? false) { if bleManager.connectedPeripheral != nil { Section("Configure") { - if hasAdmin { + if node?.canRemoteAdmin ?? false { Picker("Configuring Node", selection: $selectedNode) { if selectedNode == 0 { Text("Connect to a Node").tag(0) } - ForEach(nodes) { node in + /// Connected Node if node.num == bleManager.connectedPeripheral?.num ?? 0 { Label { Text("BLE: \(node.user?.longName ?? "unknown".localized)") @@ -362,7 +362,14 @@ struct Settings: View { Image(systemName: "antenna.radiowaves.left.and.right") } .tag(Int(node.num)) - } else if node.metadata != nil { + } else if node.canRemoteAdmin { /// Nodes using the new PKI system + Label { + Text("Remote: \(node.user?.longName ?? "unknown".localized)") + } icon: { + Image(systemName: "av.remote") + } + .tag(Int(node.num)) + } else if node.metadata != nil { /// Nodes using the old admin system Label { Text("Remote: \(node.user?.longName ?? "unknown".localized)") } icon: {