From f2aea53ab61ba04d0146d71debb157bd5698c59f Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 10 Dec 2023 12:38:01 -0800 Subject: [PATCH] Location cleanup --- Meshtastic/Helpers/BLEManager.swift | 12 ++++++-- .../Views/Nodes/Helpers/NodeListItem.swift | 30 ++++++++++++++----- Meshtastic/Views/Settings/RouteRecorder.swift | 9 ++---- Meshtastic/Views/Settings/Settings.swift | 1 - 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index c82b4796..8f38858b 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -41,6 +41,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate let emptyNodeNum: UInt32 = 4294967295 let mqttManager = MqttClientProxyManager.shared var wantRangeTestPackets = false + var wantStoreAndForwardPackets = false /* Meshtastic Service Details */ var TORADIO_characteristic: CBCharacteristic! var FROMRADIO_characteristic: CBCharacteristic! @@ -607,13 +608,17 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate case .serialApp: MeshLogger.log("🕸️ MESH PACKET received for Serial App UNHANDLED \((try? decodedInfo.packet.jsonString()) ?? "JSON Decode Failure")") case .storeForwardApp: - storeAndForwardPacket(packet: decodedInfo.packet, connectedNodeNum: (self.connectedPeripheral != nil ? connectedPeripheral.num : 0), context: context!) + if wantStoreAndForwardPackets { + storeAndForwardPacket(packet: decodedInfo.packet, connectedNodeNum: (self.connectedPeripheral != nil ? connectedPeripheral.num : 0), context: context!) + } else { + MeshLogger.log("🕸️ MESH PACKET received for Store and Forward App - Store and Forward is disabled.") + } case .rangeTestApp: if wantRangeTestPackets && !UserDefaults.blockRangeTest { textMessageAppPacket(packet: decodedInfo.packet, blockRangeTest: false, connectedNode: (self.connectedPeripheral != nil ? connectedPeripheral.num : 0), context: context!) } else { - MeshLogger.log("🕸️ MESH PACKET received for Range Test App UNHANDLED \((try? decodedInfo.packet.jsonString()) ?? "JSON Decode Failure")") + MeshLogger.log("🕸️ MESH PACKET received for Range Test App Range testing is disabled.") } case .telemetryApp: if !invalidVersion { telemetryPacket(packet: decodedInfo.packet, connectedNode: (self.connectedPeripheral != nil ? connectedPeripheral.num : 0), context: context!) } @@ -719,6 +724,9 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate if fetchedNodeInfo.count == 1 && fetchedNodeInfo[0].rangeTestConfig?.enabled == true { wantRangeTestPackets = true; } + if fetchedNodeInfo.count == 1 && fetchedNodeInfo[0].storeForwardConfig?.enabled == true { + wantStoreAndForwardPackets = true; + } } catch { print("Failed to find a node info for the connected node") diff --git a/Meshtastic/Views/Nodes/Helpers/NodeListItem.swift b/Meshtastic/Views/Nodes/Helpers/NodeListItem.swift index a5b5a3db..2fb63b53 100644 --- a/Meshtastic/Views/Nodes/Helpers/NodeListItem.swift +++ b/Meshtastic/Views/Nodes/Helpers/NodeListItem.swift @@ -55,14 +55,28 @@ struct NodeListItem: View { if node.positions?.count ?? 0 > 0 && connectedNode != node.num { HStack { let lastPostion = node.positions!.reversed()[0] as! PositionEntity - let myCoord = CLLocation(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude) - if lastPostion.nodeCoordinate != nil && myCoord.coordinate.longitude != LocationHelper.DefaultLocation.longitude && myCoord.coordinate.latitude != LocationHelper.DefaultLocation.latitude { - let nodeCoord = CLLocation(latitude: lastPostion.nodeCoordinate!.latitude, longitude: lastPostion.nodeCoordinate!.longitude) - let metersAway = nodeCoord.distance(from: myCoord) - Image(systemName: "lines.measurement.horizontal") - .font(.callout) - .symbolRenderingMode(.hierarchical) - DistanceText(meters: metersAway).font(.callout) + if #available(iOS 17.0, macOS 14.0, *) { + let myCoord = CLLocation(latitude: LocationsHandler.shared.lastLocation.coordinate.latitude, longitude: LocationsHandler.shared.lastLocation.coordinate.longitude) + if lastPostion.nodeCoordinate != nil && myCoord.coordinate.longitude != LocationsHandler.DefaultLocation.longitude && myCoord.coordinate.latitude != LocationsHandler.DefaultLocation.latitude { + let nodeCoord = CLLocation(latitude: lastPostion.nodeCoordinate!.latitude, longitude: lastPostion.nodeCoordinate!.longitude) + let metersAway = nodeCoord.distance(from: myCoord) + Image(systemName: "lines.measurement.horizontal") + .font(.callout) + .symbolRenderingMode(.hierarchical) + DistanceText(meters: metersAway).font(.callout) + } + + } else { + + let myCoord = CLLocation(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude) + if lastPostion.nodeCoordinate != nil && myCoord.coordinate.longitude != LocationHelper.DefaultLocation.longitude && myCoord.coordinate.latitude != LocationHelper.DefaultLocation.latitude { + let nodeCoord = CLLocation(latitude: lastPostion.nodeCoordinate!.latitude, longitude: lastPostion.nodeCoordinate!.longitude) + let metersAway = nodeCoord.distance(from: myCoord) + Image(systemName: "lines.measurement.horizontal") + .font(.callout) + .symbolRenderingMode(.hierarchical) + DistanceText(meters: metersAway).font(.callout) + } } } } diff --git a/Meshtastic/Views/Settings/RouteRecorder.swift b/Meshtastic/Views/Settings/RouteRecorder.swift index eb9ba679..3a168866 100644 --- a/Meshtastic/Views/Settings/RouteRecorder.swift +++ b/Meshtastic/Views/Settings/RouteRecorder.swift @@ -37,7 +37,7 @@ struct RouteRecorder: View { @State var isShowingDetails = false @State var timer: Timer? @Namespace var namespace - @Namespace var mapscope + @Namespace var routerecorderscope @State var timeElapsed: TimerDisplayObject = TimerDisplayObject() @State var timerDisplay = Timer.publish(every: 1, on: .main, in: .common).autoconnect() @@ -45,7 +45,7 @@ struct RouteRecorder: View { VStack { VStack { VStack { - Map(position: $position, scope: mapscope) { + Map(position: $position, scope: routerecorderscope) { UserAnnotation() // ForEach(locations, id: \.id) { location in // Marker(location.name, systemImage: location.icon, coordinate: location.location) @@ -53,6 +53,7 @@ struct RouteRecorder: View { // } } } + .mapScope(routerecorderscope) .mapControls { MapUserLocationButton() MapCompass() @@ -62,10 +63,6 @@ struct RouteRecorder: View { .mapStyle(.hybrid(elevation: .realistic, showsTraffic: true)) .transition(.slide) .mapControlVisibility(.visible) - .task { - print("this is running") - locationsHandler.startLocationUpdates() - } .safeAreaInset(edge: .bottom) { ZStack { VStack { diff --git a/Meshtastic/Views/Settings/Settings.swift b/Meshtastic/Views/Settings/Settings.swift index f8daa9e8..83e00e32 100644 --- a/Meshtastic/Views/Settings/Settings.swift +++ b/Meshtastic/Views/Settings/Settings.swift @@ -313,7 +313,6 @@ struct Settings: View { } } .onAppear { - selection = SettingsSidebar.about if self.bleManager.context == nil { self.bleManager.context = context }