From bb4cd7b0b208072f2106ef70ec62411fe20b7829 Mon Sep 17 00:00:00 2001 From: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com> Date: Mon, 5 May 2025 17:21:08 -0700 Subject: [PATCH 1/3] Fixed waypoints --- Meshtastic/Extensions/UserDefaults.swift | 2 +- .../Map/MapContent/MeshMapContent.swift | 2 +- .../Map/MapContent/NodeMapContent.swift | 2 +- .../Nodes/Helpers/Map/WaypointForm.swift | 88 ++++++++++++------- 4 files changed, 60 insertions(+), 34 deletions(-) diff --git a/Meshtastic/Extensions/UserDefaults.swift b/Meshtastic/Extensions/UserDefaults.swift index e1ca67f9..87bfe3f2 100644 --- a/Meshtastic/Extensions/UserDefaults.swift +++ b/Meshtastic/Extensions/UserDefaults.swift @@ -98,7 +98,7 @@ extension UserDefaults { @UserDefault(.meshMapDistance, defaultValue: 800000) static var meshMapDistance: Double - @UserDefault(.enableMapWaypoints, defaultValue: false) + @UserDefault(.enableMapWaypoints, defaultValue: true) static var enableMapWaypoints: Bool @UserDefault(.enableMapRecentering, defaultValue: false) diff --git a/Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift b/Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift index 6a0374f2..2ca86652 100644 --- a/Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift +++ b/Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift @@ -20,7 +20,7 @@ struct MeshMapContent: MapContent { @Binding var selectedMapLayer: MapLayer // Map Configuration @Binding var selectedPosition: PositionEntity? - @AppStorage("enableMapWaypoints") private var showWaypoints = false + @AppStorage("enableMapWaypoints") private var showWaypoints = true @Binding var selectedWaypoint: WaypointEntity? @FetchRequest(fetchRequest: PositionEntity.allPositionsFetchRequest(), animation: .easeIn) diff --git a/Meshtastic/Views/Nodes/Helpers/Map/MapContent/NodeMapContent.swift b/Meshtastic/Views/Nodes/Helpers/Map/MapContent/NodeMapContent.swift index c9fbf95a..2d157979 100644 --- a/Meshtastic/Views/Nodes/Helpers/Map/MapContent/NodeMapContent.swift +++ b/Meshtastic/Views/Nodes/Helpers/Map/MapContent/NodeMapContent.swift @@ -16,7 +16,7 @@ struct NodeMapContent: MapContent { /// Map State User Defaults @AppStorage("meshMapShowNodeHistory") private var showNodeHistory = false @AppStorage("meshMapShowRouteLines") private var showRouteLines = false - @AppStorage("enableMapWaypoints") private var showWaypoints = false + @AppStorage("enableMapWaypoints") private var showWaypoints = true @AppStorage("enableMapConvexHull") private var showConvexHull = false @AppStorage("enableMapTraffic") private var showTraffic: Bool = false @AppStorage("enableMapPointsOfInterest") private var showPointsOfInterest: Bool = false diff --git a/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift b/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift index 736c2114..9eb42c23 100644 --- a/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift +++ b/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift @@ -134,40 +134,44 @@ struct WaypointForm: View { .scrollDismissesKeyboard(.immediately) HStack { Button { - /// Send a new or exiting waypoint - var newWaypoint = Waypoint() - if waypoint.id == 0 { - newWaypoint.id = UInt32.random(in: UInt32(UInt8.max).. 0 ? name : "Dropped Pin" - newWaypoint.description_p = description - // Unicode scalar value for the icon emoji string - let unicodeScalers = icon.unicodeScalars - // First element as an UInt32 - let unicode = unicodeScalers[unicodeScalers.startIndex].value - newWaypoint.icon = unicode - if locked { - if lockedTo == 0 { - newWaypoint.lockedTo = UInt32(bleManager.connectedPeripheral!.num) + if bleManager.isConnected { + /// Send a new or exiting waypoint + var newWaypoint = Waypoint() + if waypoint.id == 0 { + newWaypoint.id = UInt32.random(in: UInt32(UInt8.max).. 0 ? name : "Dropped Pin" + newWaypoint.description_p = description + // Unicode scalar value for the icon emoji string + let unicodeScalers = icon.unicodeScalars + // First element as an UInt32 + let unicode = unicodeScalers[unicodeScalers.startIndex].value + newWaypoint.icon = unicode + if locked { + if lockedTo == 0 { + newWaypoint.lockedTo = UInt32(bleManager.connectedPeripheral!.num) + } else { + newWaypoint.lockedTo = UInt32(lockedTo) + } + } + if expires { + newWaypoint.expire = UInt32(expire.timeIntervalSince1970) + } else { + newWaypoint.expire = 0 + } + if bleManager.sendWaypoint(waypoint: newWaypoint) { + dismiss() + } else { + dismiss() + Logger.mesh.warning("Send waypoint failed") } - } - if expires { - newWaypoint.expire = UInt32(expire.timeIntervalSince1970) } else { - newWaypoint.expire = 0 - } - if bleManager.sendWaypoint(waypoint: newWaypoint) { - dismiss() - } else { - dismiss() - Logger.mesh.warning("Send waypoint failed") + Logger.mesh.warning("Send waypoint failed, node not connected") } } label: { Label("Send", systemImage: "arrow.up") @@ -179,6 +183,16 @@ struct WaypointForm: View { .padding(.bottom) Button(role: .cancel) { + if waypoint.id == 0 { + // New, unsent waypoint created by the user: delete it + bleManager.context.delete(waypoint) + do { + try bleManager.context.save() + } catch { + bleManager.context.rollback() + Logger.mesh.error("Failed to save context on waypoint deletion: \(error)") + } + } dismiss() } label: { Label("Cancel", systemImage: "x.circle") @@ -364,6 +378,18 @@ struct WaypointForm: View { } } } + .onDisappear { + if waypoint.id == 0 { + // New, unsent waypoint created by the user: delete it + bleManager.context.delete(waypoint) + do { + try bleManager.context.save() + } catch { + bleManager.context.rollback() + Logger.mesh.error("Failed to save context on waypoint deletion: \(error)") + } + } + } .onAppear { if waypoint.id > 0 { let waypoint = getWaypoint(id: Int64(waypoint.id), context: bleManager.context) From afa5789fdfcc4ba6f7226c63d6e7783718c42688 Mon Sep 17 00:00:00 2001 From: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com> Date: Mon, 5 May 2025 22:06:08 -0700 Subject: [PATCH 2/3] Fix taping node circles and waypoints --- .../Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift b/Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift index 2ca86652..4bce572c 100644 --- a/Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift +++ b/Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift @@ -74,9 +74,9 @@ struct MeshMapContent: MapContent { } } } - .onTapGesture { _ in + .highPriorityGesture(TapGesture().onEnded { _ in selectedPosition = (selectedPosition == position ? nil : position) - } + }) } /// Node History and Route Lines for favorites if let nodePosition = position.nodePosition, @@ -186,7 +186,7 @@ struct MeshMapContent: MapContent { LazyVStack { ZStack { CircleText(text: String(UnicodeScalar(Int(waypoint.icon)) ?? "📍"), color: Color.orange, circleSize: 40) - .onTapGesture(perform: { _ in + .highPriorityGesture(TapGesture().onEnded { _ in selectedWaypoint = (selectedWaypoint == waypoint ? nil : waypoint) }) } From 46e0757f0368a6b0efaaff68b935bec6a040460f Mon Sep 17 00:00:00 2001 From: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com> Date: Mon, 5 May 2025 22:40:14 -0700 Subject: [PATCH 3/3] Only put delete if not sent logic in one place --- Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift b/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift index 9eb42c23..4f39a448 100644 --- a/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift +++ b/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift @@ -183,16 +183,6 @@ struct WaypointForm: View { .padding(.bottom) Button(role: .cancel) { - if waypoint.id == 0 { - // New, unsent waypoint created by the user: delete it - bleManager.context.delete(waypoint) - do { - try bleManager.context.save() - } catch { - bleManager.context.rollback() - Logger.mesh.error("Failed to save context on waypoint deletion: \(error)") - } - } dismiss() } label: { Label("Cancel", systemImage: "x.circle")