From bd666a742c5c6c75d0f796496b32359f7d24e27a Mon Sep 17 00:00:00 2001 From: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com> Date: Thu, 5 Jun 2025 08:24:17 -0700 Subject: [PATCH] More graceful failures --- Localizable.xcstrings | 3 +++ .../CoreData/WaypointEntityExtension.swift | 2 +- Meshtastic/Helpers/BLEManager.swift | 2 +- .../Nodes/Helpers/Map/WaypointForm.swift | 19 ++++++++++++++++--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Localizable.xcstrings b/Localizable.xcstrings index 7f283f03..e6a7809f 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -34355,6 +34355,9 @@ } } } + }, + "Waypoiny Failed to Send" : { + }, "Weather Conditions" : { "localizations" : { diff --git a/Meshtastic/Extensions/CoreData/WaypointEntityExtension.swift b/Meshtastic/Extensions/CoreData/WaypointEntityExtension.swift index 240e6d76..4f2923eb 100644 --- a/Meshtastic/Extensions/CoreData/WaypointEntityExtension.swift +++ b/Meshtastic/Extensions/CoreData/WaypointEntityExtension.swift @@ -58,7 +58,7 @@ extension WaypointEntity: MKAnnotation { @MainActor public var coordinate: CLLocationCoordinate2D { get { - waypointCoordinate ?? LocationsHandler.currentLocation + waypointCoordinate ?? LocationsHandler.DefaultLocation } set { latitudeI = Int32(newValue.latitude * 1e7) diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 050958e0..59571549 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -1183,7 +1183,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate } public func sendWaypoint(waypoint: Waypoint) -> Bool { - if waypoint.latitudeI == 373346000 && waypoint.longitudeI == -1220090000 { + if waypoint.latitudeI == 0 && waypoint.longitudeI == 0 { return false } var success = false diff --git a/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift b/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift index 57320259..e813b854 100644 --- a/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift +++ b/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift @@ -30,6 +30,7 @@ struct WaypointForm: View { @State private var lockedTo: Int64 = 0 @State private var detents: Set = [.medium, .fraction(0.85)] @State private var selectedDetent: PresentationDetent = .medium + @State private var waypointFailedAlert: Bool = false var body: some View { NavigationStack { @@ -47,7 +48,7 @@ struct WaypointForm: View { .textSelection(.enabled) .foregroundColor(.secondary) .font(.caption) - + Button { let currentLoc = LocationsHandler.currentLocation waypoint.coordinate.longitude = currentLoc.longitude @@ -80,6 +81,7 @@ struct WaypointForm: View { name = String(name.dropLast()) totalBytes = name.utf8.count } + waypoint.name = name.count > 0 ? name : "Dropped Pin" } } HStack { @@ -175,8 +177,8 @@ struct WaypointForm: View { if bleManager.sendWaypoint(waypoint: newWaypoint) { dismiss() } else { - dismiss() Logger.mesh.warning("Send waypoint failed") + waypointFailedAlert = true } } else { Logger.mesh.warning("Send waypoint failed, node not connected") @@ -241,8 +243,8 @@ struct WaypointForm: View { } dismiss() } else { - dismiss() Logger.mesh.warning("Send waypoint failed") + waypointFailedAlert = true } }) } @@ -376,6 +378,17 @@ struct WaypointForm: View { } } } + .alert("Waypoiny Failed to Send", isPresented: $waypointFailedAlert) { + Button("OK", role: .cancel) { + bleManager.context.delete(waypoint) + do { + try bleManager.context.save() + } catch { + bleManager.context.rollback() + } + dismiss() + } + } .onDisappear { if waypoint.id == 0 { // New, unsent waypoint created by the user: delete it