From 8d65985521ebf2c81584f4c1903b4281eed86c64 Mon Sep 17 00:00:00 2001 From: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com> Date: Wed, 4 Jun 2025 15:56:17 -0700 Subject: [PATCH] Updated send waypoint intent --- Localizable.xcstrings | 16 +++++++ .../AppIntents/SendWaypointIntent.swift | 48 ++++++++++++++----- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/Localizable.xcstrings b/Localizable.xcstrings index eec7ee0d..7f283f03 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -11388,6 +11388,9 @@ } } } + }, + "Expiration" : { + }, "Expire" : { "localizations" : { @@ -15747,6 +15750,12 @@ } } } + }, + "Latitude in degrees (e.g., 37.7749)" : { + + }, + "Latitude must be between -90 and 90 degrees" : { + }, "LED Heartbeat" : { "localizations" : { @@ -16055,6 +16064,7 @@ } }, "Location" : { + "extractionState" : "stale", "localizations" : { "de" : { "stringUnit" : { @@ -16493,6 +16503,12 @@ } } } + }, + "Longitude in degrees (e.g., -122.4194)" : { + + }, + "Longitude must be between -180 and 180 degrees" : { + }, "LoRa" : { "localizations" : { diff --git a/Meshtastic/AppIntents/SendWaypointIntent.swift b/Meshtastic/AppIntents/SendWaypointIntent.swift index 4352c548..e41732db 100644 --- a/Meshtastic/AppIntents/SendWaypointIntent.swift +++ b/Meshtastic/AppIntents/SendWaypointIntent.swift @@ -11,6 +11,8 @@ import AppIntents import MeshtasticProtobufs struct SendWaypointIntent: AppIntent { + + var defaultDate = Date.now.addingTimeInterval(60 * 480) static var title = LocalizedStringResource("Send a Waypoint") @@ -23,13 +25,24 @@ struct SendWaypointIntent: AppIntent { @Parameter(title: "Emoji", default: "📍") var emojiParameter: String? - @Parameter(title: "Location") - var locationParameter: CLPlacemark + // Replace CLPlacemark with latitude and longitude parameters + @Parameter(title: "Latitude", description: "Latitude in degrees (e.g., 37.7749)") + var latitudeParameter: Double + + @Parameter(title: "Longitude", description: "Longitude in degrees (e.g., -122.4194)") + var longitudeParameter: Double + + @Parameter(title: "Locked", default: false) + var isLocked: Bool + + @Parameter(title: "Expiration") + var expiration: Date? func perform() async throws -> some IntentResult { if !BLEManager.shared.isConnected { throw AppIntentErrors.AppIntentError.notConnected } + // Provide default values if parameters are nil let name = nameParameter ?? "Dropped Pin" let description = descriptionParameter ?? "" @@ -50,24 +63,35 @@ struct SendWaypointIntent: AppIntent { throw $emojiParameter.needsValueError("Must be a single emoji") } + // Validate latitude and longitude + guard abs(latitudeParameter) <= 90 else { + throw $latitudeParameter.needsValueError("Latitude must be between -90 and 90 degrees") + } + guard abs(longitudeParameter) <= 180 else { + throw $longitudeParameter.needsValueError("Longitude must be between -180 and 180 degrees") + } + var newWaypoint = Waypoint() - if let latitude = locationParameter.location?.coordinate.latitude { - newWaypoint.latitudeI = Int32(latitude * 10_000_000) - } - - if let longitude = locationParameter.location?.coordinate.longitude { - newWaypoint.longitudeI = Int32(longitude * 10_000_000) - } + // Set latitude and longitude directly + newWaypoint.latitudeI = Int32(latitudeParameter * 10_000_000) + newWaypoint.longitudeI = Int32(longitudeParameter * 10_000_000) newWaypoint.id = UInt32.random(in: UInt32(UInt8.max).. Bool { - // This regex pattern is for matching a single emoji let emojiPattern = "^([\\p{So}\\p{Cn}])$" let regex = try? NSRegularExpression(pattern: emojiPattern, options: []) let matches = regex?.matches(in: emoji, options: [], range: NSRange(location: 0, length: emoji.utf16.count)) - return matches?.count == 1 } }