From ce4eec79006dc2493f59ef79d9eb95f3ed8abf9f Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 17 Oct 2021 20:30:04 -0700 Subject: [PATCH] V 1.26.1 Fixed connectedNode not being set bug by matching via bluetooth device name and user.id, cleanup for app settings --- Meshtastic Client.xcodeproj/project.pbxproj | 4 ++-- MeshtasticClient/Helpers/BLEManager.swift | 13 ++++++++---- .../Views/Bluetooth/Connect.swift | 4 ++-- .../Views/Helpers/BatteryIcon.swift | 10 ++++----- .../Views/Helpers/CircleText.swift | 2 +- .../Views/Messages/Channels.swift | 2 +- .../Views/Messages/Messages.swift | 4 ++-- MeshtasticClient/Views/Nodes/NodeDetail.swift | 16 +++++++------- MeshtasticClient/Views/Nodes/NodeMap.swift | 2 +- MeshtasticClient/Views/Nodes/NodeRow.swift | 4 ++-- .../Views/Settings/AppSettings.swift | 21 ++++++++++++------- 11 files changed, 47 insertions(+), 35 deletions(-) diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index a2756562..aed9fcf3 100644 --- a/Meshtastic Client.xcodeproj/project.pbxproj +++ b/Meshtastic Client.xcodeproj/project.pbxproj @@ -660,7 +660,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.26.0; + MARKETING_VERSION = 1.26.1; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = YES; @@ -687,7 +687,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.26.0; + MARKETING_VERSION = 1.26.1; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = YES; diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift index d2b1690a..ff848752 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -118,6 +118,11 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph peripheral.delegate = self connectedPeripheral = peripherals.filter({ $0.peripheral.identifier == peripheral.identifier }).first + let deviceName = peripheral.name ?? "" + + let peripheralLast4: String = String(deviceName.suffix(4)) + + connectedNode = meshData.nodes.first(where: { $0.user.id.contains(peripheralLast4) }) lastConnectedPeripheral = peripheral.identifier.uuidString peripheral.discoverServices([meshtasticServiceCBUUID]) print("Peripheral connected: " + peripheral.name!) @@ -339,10 +344,10 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph // Since the data is from the device itself we save all myInfo objects since they are always the most up to date if connectedNode != nil { connectedNode.myInfo = myInfoModel - //connectedNode.update(from: connectedNode.data) - let nodeIndex = meshData.nodes.firstIndex(where: { $0.id == decodedInfo.myInfo.myNodeNum }) - meshData.nodes.remove(at: nodeIndex!) - meshData.nodes.append(connectedNode) + connectedNode.update(from: connectedNode.data) + // let nodeIndex = meshData.nodes.firstIndex(where: { $0.id == decodedInfo.myInfo.myNodeNum }) + // meshData.nodes.remove(at: nodeIndex!) + // meshData.nodes.append(connectedNode) meshData.save() print("Saved a myInfo for \(decodedInfo.myInfo.myNodeNum)") // connectedNode.update(from: connectedNode.data) } diff --git a/MeshtasticClient/Views/Bluetooth/Connect.swift b/MeshtasticClient/Views/Bluetooth/Connect.swift index 46e5c1ae..2a7776fb 100644 --- a/MeshtasticClient/Views/Bluetooth/Connect.swift +++ b/MeshtasticClient/Views/Bluetooth/Connect.swift @@ -55,7 +55,7 @@ struct Connect: View { Text("Preferred").font(.caption2) Text("Radio").font(.caption2) Toggle("Preferred Radio", isOn: $isPreferredRadio) - .toggleStyle(SwitchToggleStyle(tint: .green)) + .toggleStyle(SwitchToggleStyle(tint: .accentColor)) .labelsHidden() .onChange(of: isPreferredRadio) { value in if value { @@ -91,7 +91,7 @@ struct Connect: View { bleManager.disconnectDevice() } } label: { - Label("Delete", systemImage: "antenna.radiowaves.left.and.right.slash") + Label("Disconnect", systemImage: "antenna.radiowaves.left.and.right.slash") } } //.padding() diff --git a/MeshtasticClient/Views/Helpers/BatteryIcon.swift b/MeshtasticClient/Views/Helpers/BatteryIcon.swift index cf106f61..8a67e957 100644 --- a/MeshtasticClient/Views/Helpers/BatteryIcon.swift +++ b/MeshtasticClient/Views/Helpers/BatteryIcon.swift @@ -54,15 +54,15 @@ struct BatteryIcon: View { struct BatteryIcon_Previews: PreviewProvider { static var previews: some View { - BatteryIcon(batteryLevel: 100, font: .title2, color: Color.blue) + BatteryIcon(batteryLevel: 100, font: .title2, color: Color.accentColor) .previewLayout(.fixed(width: 75, height: 75)) - BatteryIcon(batteryLevel: 99, font: .title2, color: Color.blue) + BatteryIcon(batteryLevel: 99, font: .title2, color: Color.accentColor) .previewLayout(.fixed(width: 75, height: 75)) - BatteryIcon(batteryLevel: 74, font: .title2, color: Color.blue) + BatteryIcon(batteryLevel: 74, font: .title2, color: Color.accentColor) .previewLayout(.fixed(width: 75, height: 75)) - BatteryIcon(batteryLevel: 49, font: .title2, color: Color.blue) + BatteryIcon(batteryLevel: 49, font: .title2, color: Color.accentColor) .previewLayout(.fixed(width: 75, height: 75)) - BatteryIcon(batteryLevel: 14, font: .title2, color: Color.blue) + BatteryIcon(batteryLevel: 14, font: .title2, color: Color.accentColor) .previewLayout(.fixed(width: 75, height: 75)) } } diff --git a/MeshtasticClient/Views/Helpers/CircleText.swift b/MeshtasticClient/Views/Helpers/CircleText.swift index bf9f0d2a..de7c8548 100644 --- a/MeshtasticClient/Views/Helpers/CircleText.swift +++ b/MeshtasticClient/Views/Helpers/CircleText.swift @@ -22,7 +22,7 @@ struct CircleText: View { struct CircleText_Previews: PreviewProvider { static var previews: some View { - CircleText(text: "RDN", color: Color.blue) + CircleText(text: "RDN", color: Color.accentColor) .previewLayout(.fixed(width: 300, height: 100)) } } diff --git a/MeshtasticClient/Views/Messages/Channels.swift b/MeshtasticClient/Views/Messages/Channels.swift index d14c2ca5..2b09666e 100644 --- a/MeshtasticClient/Views/Messages/Channels.swift +++ b/MeshtasticClient/Views/Messages/Channels.swift @@ -23,7 +23,7 @@ struct Channels: View { .font(.system(size: 62)) .symbolRenderingMode(.hierarchical) .padding(.trailing) - .foregroundColor(Color.blue) + .foregroundColor(.accentColor) Text("Primary") .font(.largeTitle) diff --git a/MeshtasticClient/Views/Messages/Messages.swift b/MeshtasticClient/Views/Messages/Messages.swift index 316f55ee..0d2c6c82 100644 --- a/MeshtasticClient/Views/Messages/Messages.swift +++ b/MeshtasticClient/Views/Messages/Messages.swift @@ -50,7 +50,7 @@ struct Messages: View { HStack (alignment: .top) { - CircleText(text: message.fromUserShortName, color: currentUser ? Color.blue : Color(.darkGray)).padding(.all, 5) + CircleText(text: message.fromUserShortName, color: currentUser ? .accentColor : Color(.darkGray)).padding(.all, 5) .gesture(LongPressGesture(minimumDuration: 2) .onEnded {_ in print("I want to delete message: \(message.messageId)") @@ -150,7 +150,7 @@ struct Messages: View { .frame(width: 130) .padding(5) .font(.subheadline) - .accentColor(Color.blue) + .accentColor(.accentColor) } } .padding(.horizontal, 8) diff --git a/MeshtasticClient/Views/Nodes/NodeDetail.swift b/MeshtasticClient/Views/Nodes/NodeDetail.swift index 6d885096..55742b09 100644 --- a/MeshtasticClient/Views/Nodes/NodeDetail.swift +++ b/MeshtasticClient/Views/Nodes/NodeDetail.swift @@ -39,7 +39,7 @@ struct NodeDetail: View { MapAnnotation( coordinate: location.coordinate, content: { - CircleText(text: node.user.shortName, color: Color.blue) + CircleText(text: node.user.shortName, color: .accentColor) } ) }.frame(idealWidth: bounds.size.width, minHeight: bounds.size.height / 2) @@ -57,7 +57,7 @@ struct NodeDetail: View { VStack(alignment: .center) { Text("AKA").font(.title2).fixedSize() - CircleText(text: node.user.shortName, color: Color.blue) + CircleText(text: node.user.shortName, color: .accentColor) .offset(y:10) } .padding([.leading, .trailing, .bottom]) @@ -67,7 +67,7 @@ struct NodeDetail: View { Image(systemName: "waveform.path") .font(.title) - .foregroundColor(.blue) + .foregroundColor(.accentColor) .symbolRenderingMode(.hierarchical) Text("SNR").font(.title2).fixedSize() Text(String(node.snr ?? 0)) @@ -77,7 +77,7 @@ struct NodeDetail: View { Divider() } VStack(alignment: .center) { - BatteryIcon(batteryLevel: node.position.batteryLevel, font: .title, color: Color.blue) + BatteryIcon(batteryLevel: node.position.batteryLevel, font: .title, color: .accentColor) if node.position.batteryLevel != nil && node.position.batteryLevel! > 0 { Text("Battery").font(.title2).fixedSize() Text(String(node.position.batteryLevel!) + "%") @@ -109,7 +109,7 @@ struct NodeDetail: View { HStack{ - Image(systemName: "clock").font(.title2).foregroundColor(.blue) + Image(systemName: "clock").font(.title2).foregroundColor(.accentColor) let lastHeard = Date(timeIntervalSince1970: TimeInterval(node.lastHeard)) Text("Last Heard: \(lastHeard, style: .relative) ago").font(.title3) }.padding() @@ -118,7 +118,7 @@ struct NodeDetail: View { if node.position.coordinate != nil { HStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/, spacing: 14) { - Image(systemName: "mappin").font(.title).foregroundColor(.blue) + Image(systemName: "mappin").font(.title).foregroundColor(.accentColor) VStack(alignment: .leading) { Text("Latitude").font(.headline) Text(String(node.position.latitude ?? 0)).font(.caption).foregroundColor(.gray) @@ -139,7 +139,7 @@ struct NodeDetail: View { HStack (alignment: .center) { VStack { HStack{ - Image(systemName: "person").font(.title3).foregroundColor(.blue) + Image(systemName: "person").font(.title3).foregroundColor(.accentColor) Text("Unique Id:").font(.title3) } Text(node.user.id).font(.headline).foregroundColor(.gray) @@ -147,7 +147,7 @@ struct NodeDetail: View { Divider() VStack { HStack { - Image(systemName: "number").font(.title3).foregroundColor(.blue) + Image(systemName: "number").font(.title3).foregroundColor(.accentColor) Text("Node Number:").font(.title3) } Text(String(node.num)).font(.headline).foregroundColor(.gray) diff --git a/MeshtasticClient/Views/Nodes/NodeMap.swift b/MeshtasticClient/Views/Nodes/NodeMap.swift index 8fb76a74..32f49982 100644 --- a/MeshtasticClient/Views/Nodes/NodeMap.swift +++ b/MeshtasticClient/Views/Nodes/NodeMap.swift @@ -52,7 +52,7 @@ struct NodeMap: View { MapAnnotation( coordinate: location.position.coordinate!, content: { - CircleText(text: location.user.shortName, color: Color.blue) + CircleText(text: location.user.shortName, color: .accentColor) } ) } diff --git a/MeshtasticClient/Views/Nodes/NodeRow.swift b/MeshtasticClient/Views/Nodes/NodeRow.swift index 989b4e66..8b5313b1 100644 --- a/MeshtasticClient/Views/Nodes/NodeRow.swift +++ b/MeshtasticClient/Views/Nodes/NodeRow.swift @@ -9,7 +9,7 @@ struct NodeRow: View { HStack() { - CircleText(text: node.user.shortName, color: Color.blue).offset(y: 1).padding(.trailing, 5) + CircleText(text: node.user.shortName, color: Color.accentColor).offset(y: 1).padding(.trailing, 5) .offset(x: -15) if UIDevice.current.userInterfaceIdiom == .pad { @@ -25,7 +25,7 @@ struct NodeRow: View { HStack (alignment: .bottom){ - Image(systemName: "clock.badge.checkmark.fill").font(.headline).foregroundColor(.blue).symbolRenderingMode(.hierarchical) + Image(systemName: "clock.badge.checkmark.fill").font(.headline).foregroundColor(.accentColor).symbolRenderingMode(.hierarchical) if UIDevice.current.userInterfaceIdiom == .pad { diff --git a/MeshtasticClient/Views/Settings/AppSettings.swift b/MeshtasticClient/Views/Settings/AppSettings.swift index 17038e6d..2d4ec137 100644 --- a/MeshtasticClient/Views/Settings/AppSettings.swift +++ b/MeshtasticClient/Views/Settings/AppSettings.swift @@ -78,29 +78,36 @@ struct AppSettings: View { GeometryReader { bounds in - Form { + List { Section(header: Text("USER DETAILS")) { - HStack{ + HStack { - Text("User Name") + Label("Name", systemImage: "person.crop.rectangle.fill") TextField("Username", text: $userSettings.username) .foregroundColor(.gray) } + .listRowSeparator(.visible) Toggle(isOn: $userSettings.provideLocation) { - Text("Provide location to mesh") + Label("Provide location to mesh", systemImage: "location.circle.fill") } + .toggleStyle(SwitchToggleStyle(tint: .accentColor)) .listRowSeparator(.visible) - Text("Preferred Radio") + Label("Preferred Radio", systemImage: "flipphone") .listRowSeparator(.hidden) Text(userSettings.preferredPeripheralName) .foregroundColor(.gray) - Text("The preferred radio will automatically reconnect if it becomes disconnected and is still within range. This device is assumed to be the primary radio used for messaging.").font(.caption2).foregroundColor(.gray) + Text("This option is set via the preferred radio toggle for the connected device on the bluetooth tab.") + .font(.caption) + .listRowSeparator(.hidden) + Text("The preferred radio will automatically reconnect if it becomes disconnected and is still within range. This device is assumed to be the primary radio used for messaging.") + .font(.caption2) + .foregroundColor(.gray) } Section(header: Text("MESSAGING OPTIONS")) { - + Picker("Keyboard Type", selection: $userSettings.keyboardType) { ForEach(KeyboardType.allCases) { kb in Text(kb.description)