diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index f295c628..6243313b 100644 --- a/Meshtastic Client.xcodeproj/project.pbxproj +++ b/Meshtastic Client.xcodeproj/project.pbxproj @@ -672,7 +672,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.27.4; + MARKETING_VERSION = 1.27.6; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = YES; @@ -699,7 +699,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.27.4; + MARKETING_VERSION = 1.27.6; 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 bea36862..b5e59994 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -31,6 +31,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph @Published var lastConnectionError: String @Published var isSwitchedOn = false + @Published var isScanning = false @Published var peripherals = [Peripheral]() var timeoutTimer: Timer? @@ -71,6 +72,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph if central.state == .poweredOn { isSwitchedOn = true + startScanning() } else { @@ -84,6 +86,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph if isSwitchedOn { centralManager.scanForPeripherals(withServices: [meshtasticServiceCBUUID], options: nil) + self.isScanning = self.centralManager.isScanning print("Scanning Started") } } @@ -94,6 +97,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph if centralManager.isScanning { self.centralManager.stopScan() + self.isScanning = self.centralManager.isScanning print("Stopped Scanning") } } @@ -108,7 +112,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph guard let context = timer.userInfo as? [String: String] else { return } let name = context["name", default: "Unknown"] - timeoutTimerCount += 1 + self.timeoutTimerCount += 1 if timeoutTimerCount == 6 { @@ -123,8 +127,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph print("BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Time(s): \(name)") if meshLoggingEnabled { Logger.log("BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Time(s): \(name)") } - timeoutTimer?.invalidate() - timeoutTimerCount = 0 + self.timeoutTimer?.invalidate() + self.timeoutTimerCount = 0 } else { print("BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Time(s): \(name)") @@ -174,10 +178,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph let peripheralIndex = peripherals.firstIndex(where: { $0.id == newPeripheral.id }) if peripheralIndex != nil { - - if self.meshData.nodes[peripheralIndex!].myInfo != nil { - newPeripheral.myInfo = self.meshData.nodes[peripheralIndex!].myInfo - } + + newPeripheral.myInfo = peripherals.first(where: { $0.id == newPeripheral.id })?.myInfo peripherals.remove(at: peripheralIndex!) peripherals.append(newPeripheral) print("Updating peripheral: \(peripheralName)"); diff --git a/MeshtasticClient/MeshtasticClientApp.swift b/MeshtasticClient/MeshtasticClientApp.swift index 571ab864..0209ca6e 100644 --- a/MeshtasticClient/MeshtasticClientApp.swift +++ b/MeshtasticClient/MeshtasticClientApp.swift @@ -1,10 +1,3 @@ -// -// MeshtasticClientApp.swift -// MeshtasticClient -// -// Created by Garth Vander Houwen on 8/18/21. -// - import SwiftUI @main diff --git a/MeshtasticClient/Views/Bluetooth/Connect.swift b/MeshtasticClient/Views/Bluetooth/Connect.swift index 8cc8040d..46e7c457 100644 --- a/MeshtasticClient/Views/Bluetooth/Connect.swift +++ b/MeshtasticClient/Views/Bluetooth/Connect.swift @@ -57,11 +57,13 @@ struct Connect: View { Text(String(bleManager.connectedPeripheral.peripheral.name ?? "Unknown")).font(.title2) } - Text("Model: ").font(.caption)+Text(bleManager.connectedNode?.user.hwModel ?? "(null)").font(.caption).foregroundColor(Color.gray) if bleManager.connectedNode != nil { - Text("BLE Name: ").font(.caption)+Text(bleManager.connectedPeripheral.name).font(.caption).foregroundColor(Color.gray) + Text("Model: ").font(.caption)+Text(bleManager.connectedNode?.user.hwModel ?? "(null)").font(.caption).foregroundColor(Color.gray) + } + Text("BLE Name: ").font(.caption)+Text(bleManager.connectedPeripheral.name).font(.caption).foregroundColor(Color.gray) + if bleManager.connectedPeripheral.myInfo != nil { + Text("FW Version: ").font(.caption)+Text(bleManager.connectedPeripheral.myInfo?.firmwareVersion ?? "(null)").font(.caption).foregroundColor(Color.gray) } - Text("FW Version: ").font(.caption)+Text(bleManager.connectedPeripheral.myInfo?.firmwareVersion ?? "(null)").font(.caption).foregroundColor(Color.gray) } Spacer() @@ -87,7 +89,8 @@ struct Connect: View { } else { - if bleManager.connectedNode != nil { + if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.identifier.uuidString == userSettings.preferredPeripheralId { + userSettings.preferredPeripheralId = "" userSettings.preferredPeripheralName = "" } @@ -167,6 +170,7 @@ struct Connect: View { .font(.caption) .foregroundColor(.gray) } + .disabled(self.bleManager.isScanning) .padding() .background(Color(.systemGray6)) .clipShape(Capsule()) @@ -179,6 +183,7 @@ struct Connect: View { .font(.caption) .foregroundColor(.gray) } + .disabled(!self.bleManager.isScanning) .padding() .background(Color(.systemGray6)) .clipShape(Capsule()) @@ -219,8 +224,7 @@ struct Connect_Previews: PreviewProvider { static var previews: some View { Connect() - .environmentObject(MeshData()) + .environmentObject(BLEManager()) - } } diff --git a/MeshtasticClient/Views/Nodes/NodeDetail.swift b/MeshtasticClient/Views/Nodes/NodeDetail.swift index b7a2b659..637e9a0a 100644 --- a/MeshtasticClient/Views/Nodes/NodeDetail.swift +++ b/MeshtasticClient/Views/Nodes/NodeDetail.swift @@ -8,6 +8,8 @@ import MapKit import CoreLocation struct NodeDetail: View { + + @EnvironmentObject var bleManager :BLEManager var node: NodeInfoModel @@ -156,6 +158,11 @@ struct NodeDetail: View { } }.navigationTitle(node.user.longName) .navigationBarTitleDisplayMode(.inline) + .navigationBarItems(trailing: + + ZStack { + ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedNode != nil) ? bleManager.connectedNode.user.shortName : ((bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.name : "Unknown") ) + }) }.ignoresSafeArea(.all, edges: [.leading, .trailing]) } } diff --git a/MeshtasticClient/Views/Nodes/NodeList.swift b/MeshtasticClient/Views/Nodes/NodeList.swift index 64ef1a21..ee5a28f4 100644 --- a/MeshtasticClient/Views/Nodes/NodeList.swift +++ b/MeshtasticClient/Views/Nodes/NodeList.swift @@ -83,9 +83,6 @@ struct NodeList: View { .navigationTitle("All Nodes") .onAppear( perform: { - if bleManager.meshData.nodes.count == 0 { - bleManager.meshData.load() - } if UIDevice.current.userInterfaceIdiom == .pad { if bleManager.meshData.nodes.count > 0 { selection = "0" diff --git a/MeshtasticClient/Views/Nodes/NodeMap.swift b/MeshtasticClient/Views/Nodes/NodeMap.swift index 5820fd4f..eb7f25a0 100644 --- a/MeshtasticClient/Views/Nodes/NodeMap.swift +++ b/MeshtasticClient/Views/Nodes/NodeMap.swift @@ -56,11 +56,14 @@ struct NodeMap: View { } .navigationTitle("Mesh Map") .navigationBarTitleDisplayMode(.inline) + .navigationBarItems(trailing: + + ZStack { + ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedNode != nil) ? bleManager.connectedNode.user.shortName : ((bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.name : "Unknown") ) + }) + } .navigationViewStyle(StackNavigationViewStyle()) - .onAppear{ - bleManager.meshData.load() - } } } diff --git a/MeshtasticClient/Views/Nodes/NodeRow.swift b/MeshtasticClient/Views/Nodes/NodeRow.swift index 8b5313b1..8cba7fd2 100644 --- a/MeshtasticClient/Views/Nodes/NodeRow.swift +++ b/MeshtasticClient/Views/Nodes/NodeRow.swift @@ -59,7 +59,7 @@ struct NodeRow: View { } struct NodeRow_Previews: PreviewProvider { - static var nodes = MeshData().nodes + static var nodes = BLEManager().meshData.nodes static var previews: some View { Group { diff --git a/MeshtasticClient/Views/Settings/AppSettings.swift b/MeshtasticClient/Views/Settings/AppSettings.swift index 8ea6cfd7..4f9ade5c 100644 --- a/MeshtasticClient/Views/Settings/AppSettings.swift +++ b/MeshtasticClient/Views/Settings/AppSettings.swift @@ -68,7 +68,7 @@ class UserSettings: ObservableObject { self.preferredPeripheralId = UserDefaults.standard.object(forKey: "preferredPeripheralId") as? String ?? "" self.provideLocation = UserDefaults.standard.object(forKey: "provideLocation") as? Bool ?? false self.keyboardType = UserDefaults.standard.object(forKey: "keyboardType") as? Int ?? 0 - self.meshActivityLog = UserDefaults.standard.object(forKey: "meshActivityLog") as? Bool ?? false + self.meshActivityLog = UserDefaults.standard.object(forKey: "meshActivityLog") as? Bool ?? true } } @@ -93,9 +93,9 @@ struct AppSettings: View { Section(header: Text("USER DETAILS")) { //HStack { - //Label("Name", systemImage: "person.crop.rectangle.fill") - //TextField("Username", text: $userSettings.meshtasticUsername) - //.foregroundColor(.gray) + // Label("Name", systemImage: "person.crop.rectangle.fill") + // TextField("Username", text: $userSettings.meshtasticUsername) + // .foregroundColor(.gray) //} //.listRowSeparator(.visible) Toggle(isOn: $userSettings.provideLocation) { @@ -141,6 +141,11 @@ struct AppSettings: View { } } .navigationTitle("App Settings") + .navigationBarItems(trailing: + + ZStack { + ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedNode != nil) ? bleManager.connectedNode.user.shortName : ((bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.name : "Unknown") ) + }) } .navigationViewStyle(StackNavigationViewStyle()) }