diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index 42409586..7c72e556 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -46,6 +46,7 @@ DD8169FF272476C700F4AB02 /* LogDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8169FE272476C700F4AB02 /* LogDocument.swift */; }; DD836AE726F6B38600ABCC23 /* Connect.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD836AE626F6B38600ABCC23 /* Connect.swift */; }; DD86D40A287F04F100BAEB7A /* InvalidVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD86D409287F04F100BAEB7A /* InvalidVersion.swift */; }; + DD86D40C287F401000BAEB7A /* SaveChannelQRCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD86D40B287F401000BAEB7A /* SaveChannelQRCode.swift */; }; DD882F5D2772E4640005BF05 /* Contacts.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD882F5C2772E4640005BF05 /* Contacts.swift */; }; DD8EBF43285058FA00426DCA /* DisplayConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8EBF42285058FA00426DCA /* DisplayConfig.swift */; }; DD90860C26F684AF00DC5189 /* BatteryIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD90860B26F684AF00DC5189 /* BatteryIcon.swift */; }; @@ -137,6 +138,7 @@ DD8169FE272476C700F4AB02 /* LogDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogDocument.swift; sourceTree = ""; }; DD836AE626F6B38600ABCC23 /* Connect.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Connect.swift; sourceTree = ""; }; DD86D409287F04F100BAEB7A /* InvalidVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InvalidVersion.swift; sourceTree = ""; }; + DD86D40B287F401000BAEB7A /* SaveChannelQRCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SaveChannelQRCode.swift; sourceTree = ""; }; DD882F5C2772E4640005BF05 /* Contacts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Contacts.swift; sourceTree = ""; }; DD8EBF42285058FA00426DCA /* DisplayConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayConfig.swift; sourceTree = ""; }; DD90860A26F645B700DC5189 /* Meshtastic.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Meshtastic.entitlements; sourceTree = ""; }; @@ -254,6 +256,7 @@ DD8169FA271F1F3A00F4AB02 /* MeshLog.swift */, DD8169FE272476C700F4AB02 /* LogDocument.swift */, DD6B85A728009258000ACD6B /* ShareChannel.swift */, + DD86D40B287F401000BAEB7A /* SaveChannelQRCode.swift */, DDCE4E2B2869F92900BE9F8F /* UserConfig.swift */, DD0F791A28713C8A00A6FDAD /* AdminMessageList.swift */, DD61937A2863876A00E59241 /* Config */, @@ -658,6 +661,7 @@ C9A88B55278B503C00BD810A /* MapViewModule.swift in Sources */, DD2553592855B52700E55709 /* PositionConfig.swift in Sources */, DDAF8C6326ED0A230058C060 /* admin.pb.swift in Sources */, + DD86D40C287F401000BAEB7A /* SaveChannelQRCode.swift in Sources */, C9483F6D2773017500998F6B /* MapView.swift in Sources */, DDAF8C5826ED07FD0058C060 /* mesh.pb.swift in Sources */, DD8169FB271F1F3A00F4AB02 /* MeshLog.swift in Sources */, diff --git a/Meshtastic/MeshtasticApp.swift b/Meshtastic/MeshtasticApp.swift index bdcdf610..2564dfd0 100644 --- a/Meshtastic/MeshtasticApp.swift +++ b/Meshtastic/MeshtasticApp.swift @@ -11,6 +11,9 @@ struct MeshtasticAppleApp: App { @ObservedObject private var bleManager: BLEManager = BLEManager.shared @ObservedObject private var userSettings: UserSettings = UserSettings() + @State var saveQR = false + @State var channelUrl = "" + @Environment(\.scenePhase) var scenePhase var body: some Scene { @@ -19,16 +22,23 @@ struct MeshtasticAppleApp: App { .environment(\.managedObjectContext, persistenceController.container.viewContext) .environmentObject(bleManager) .environmentObject(userSettings) + .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { userActivity in - print("QR Code URL received from the Camera \(userActivity)") - guard let url = userActivity.webpageURL else { - return - } + print("QR Code URL received from the Camera \(userActivity)") + guard let url = userActivity.webpageURL else { + return + } - print("User wants to open URL: \(url)") + print("User wants to open URL: \(url)") + channelUrl = url.absoluteString + saveQR = true } + .sheet(isPresented: $saveQR) { + + SaveChannelQRCode(channelHash: channelUrl) + } .onOpenURL(perform: { (url) in //we are expecting a .mbtiles map file that contains raster data @@ -56,6 +66,7 @@ struct MeshtasticAppleApp: App { } }) } + .onChange(of: scenePhase) { (newScenePhase) in switch newScenePhase { case .background: diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index 5c3cc3b1..53ea4be8 100644 --- a/Meshtastic/Views/Bluetooth/Connect.swift +++ b/Meshtastic/Views/Bluetooth/Connect.swift @@ -267,6 +267,8 @@ struct Connect: View { InvalidVersion(errorText: "1.3 ALPHA PREVIEW this version of the app supports only version \(minimumVersion) and above. Your device has been disconnected.") } + + .onChange(of: firmwareVersion) { iv in bleManager.disconnectPeripheral() diff --git a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift index 2ec4d5d1..103fabf1 100644 --- a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift @@ -270,6 +270,7 @@ struct CannedMessagesConfig: View { } .disabled(configPreset > 0) } + .disabled(bleManager.connectedPeripheral == nil) Button { diff --git a/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift b/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift index 503e90cd..e54f3617 100644 --- a/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift @@ -129,6 +129,7 @@ struct ExternalNotificationConfig: View { .font(.caption) } } + .disabled(bleManager.connectedPeripheral == nil) Button { diff --git a/Meshtastic/Views/Settings/Config/Module/RangeTestConfig.swift b/Meshtastic/Views/Settings/Config/Module/RangeTestConfig.swift index 21763cc5..077b4d14 100644 --- a/Meshtastic/Views/Settings/Config/Module/RangeTestConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/RangeTestConfig.swift @@ -80,13 +80,13 @@ struct RangeTestConfig: View { Label("Save", systemImage: "square.and.arrow.down.fill") } .toggleStyle(SwitchToggleStyle(tint: .accentColor)) - .disabled(!(node!.myInfo?.hasWifi ?? false)) + .disabled(!(node != nil && node!.myInfo?.hasWifi ?? false)) Text("Saves a CSV with the range test message details, currently only available on ESP32 devices with a web server.") .font(.caption) } } - .disabled(!(node!.myInfo?.hasWifi ?? false)) + .disabled(!(node != nil && node!.myInfo?.hasWifi ?? false)) Button { diff --git a/Meshtastic/Views/Settings/Config/Module/SerialConfig.swift b/Meshtastic/Views/Settings/Config/Module/SerialConfig.swift index dad8e7e0..b4432798 100644 --- a/Meshtastic/Views/Settings/Config/Module/SerialConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/SerialConfig.swift @@ -272,7 +272,7 @@ struct SerialConfig: View { .font(.caption) } } - .disabled(!(node!.myInfo?.hasWifi ?? false)) + .disabled(!(node != nil && node!.myInfo?.hasWifi ?? false)) Button { diff --git a/Meshtastic/Views/Settings/Config/Module/TelemetryConfig.swift b/Meshtastic/Views/Settings/Config/Module/TelemetryConfig.swift index 94dc8fb5..8818d68b 100644 --- a/Meshtastic/Views/Settings/Config/Module/TelemetryConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/TelemetryConfig.swift @@ -280,6 +280,7 @@ struct TelemetryConfig: View { .font(.caption) } } + .disabled(bleManager.connectedPeripheral == nil) Button { diff --git a/Meshtastic/Views/Settings/SaveChannelQRCode.swift b/Meshtastic/Views/Settings/SaveChannelQRCode.swift new file mode 100644 index 00000000..7d9246a6 --- /dev/null +++ b/Meshtastic/Views/Settings/SaveChannelQRCode.swift @@ -0,0 +1,40 @@ +// +// SaveChannelQRCode.swift +// Meshtastic +// +// Copyright(c) Garth Vander Houwen 7/13/22. +// +import SwiftUI + +struct SaveChannelQRCode: View { + + @State var channelHash: String = "empty hash" + + var body: some View { + + // Show an error if there is no e/ or other validation problems + + VStack { + + Text("Save Channel Settings?") + .font(.title) + + Text("The settings embedded in this QR code will replace the current settings on your radio.") + .foregroundColor(.gray) + .font(.callout) + .padding() + + Text(channelHash) + .font(.title2) + .padding() + + Text("Blah blah.") + .font(.callout) + .padding() + + + Text("This is forever") + .padding() + } + } +}