From 5c57d38ee6f7f5bf9982ae67c39abb179bc8dea9 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 9 Jul 2024 18:29:59 -0700 Subject: [PATCH] Update channel url query string location and support both formats --- Meshtastic/MeshtasticApp.swift | 29 +++++++++++++++---- Meshtastic/Views/Settings/ShareChannels.swift | 2 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Meshtastic/MeshtasticApp.swift b/Meshtastic/MeshtasticApp.swift index b00fab92..578f16d4 100644 --- a/Meshtastic/MeshtasticApp.swift +++ b/Meshtastic/MeshtasticApp.swift @@ -40,11 +40,18 @@ struct MeshtasticAppleApp: App { if (self.incomingUrl?.absoluteString.lowercased().contains("meshtastic.org/e/#")) != nil { if let components = self.incomingUrl?.absoluteString.components(separatedBy: "#") { - guard let cs = components.last!.components(separatedBy: "?").first else { - return - } - self.channelSettings = cs self.addChannels = Bool(self.incomingUrl?["add"] ?? "false") ?? false + if ((self.incomingUrl?.absoluteString.lowercased().contains("?")) != nil) { + guard let cs = components.last!.components(separatedBy: "?").first else { + return + } + self.channelSettings = cs + } else { + guard let cs = components.first else { + return + } + self.channelSettings = cs + } Logger.services.debug("Add Channel \(self.addChannels)") } self.saveChannels = true @@ -60,7 +67,19 @@ struct MeshtasticAppleApp: App { self.incomingUrl = url if url.absoluteString.lowercased().contains("meshtastic.org/e/#") { if let components = self.incomingUrl?.absoluteString.components(separatedBy: "#") { - self.channelSettings = components.last! + self.addChannels = Bool(self.incomingUrl?["add"] ?? "false") ?? false + if ((self.incomingUrl?.absoluteString.lowercased().contains("?")) != nil) { + guard let cs = components.last!.components(separatedBy: "?").first else { + return + } + self.channelSettings = cs + } else { + guard let cs = components.first else { + return + } + self.channelSettings = cs + } + Logger.services.debug("Add Channel \(self.addChannels)") } self.saveChannels = true Logger.mesh.debug("User wants to open a Channel Settings URL: \(self.incomingUrl?.absoluteString ?? "No QR Code Link")") diff --git a/Meshtastic/Views/Settings/ShareChannels.swift b/Meshtastic/Views/Settings/ShareChannels.swift index 51d066eb..3859693e 100644 --- a/Meshtastic/Views/Settings/ShareChannels.swift +++ b/Meshtastic/Views/Settings/ShareChannels.swift @@ -319,7 +319,7 @@ struct ShareChannels: View { guard let settingsString = try? channelSet.serializedData().base64EncodedString() else { return } - channelsUrl = ("https://meshtastic.org/e/#" + settingsString.base64ToBase64url() + (replaceChannels ? "" : "?add=true")) + channelsUrl = ("https://meshtastic.org/e/\(replaceChannels ? "" : "?add=true")#" + settingsString.base64ToBase64url()) } } }