Fix a couple of lingering config view crashing if a device disconnects while on the view, hook up QR code deep link

This commit is contained in:
Garth Vander Houwen 2022-07-14 07:14:43 -07:00
parent 1d9a7c69f6
commit 1ecd094ef9
9 changed files with 68 additions and 8 deletions

View file

@ -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 = "<group>"; };
DD836AE626F6B38600ABCC23 /* Connect.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Connect.swift; sourceTree = "<group>"; };
DD86D409287F04F100BAEB7A /* InvalidVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InvalidVersion.swift; sourceTree = "<group>"; };
DD86D40B287F401000BAEB7A /* SaveChannelQRCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SaveChannelQRCode.swift; sourceTree = "<group>"; };
DD882F5C2772E4640005BF05 /* Contacts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Contacts.swift; sourceTree = "<group>"; };
DD8EBF42285058FA00426DCA /* DisplayConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayConfig.swift; sourceTree = "<group>"; };
DD90860A26F645B700DC5189 /* Meshtastic.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Meshtastic.entitlements; sourceTree = "<group>"; };
@ -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 */,

View file

@ -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:

View file

@ -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()

View file

@ -270,6 +270,7 @@ struct CannedMessagesConfig: View {
}
.disabled(configPreset > 0)
}
.disabled(bleManager.connectedPeripheral == nil)
Button {

View file

@ -129,6 +129,7 @@ struct ExternalNotificationConfig: View {
.font(.caption)
}
}
.disabled(bleManager.connectedPeripheral == nil)
Button {

View file

@ -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 {

View file

@ -272,7 +272,7 @@ struct SerialConfig: View {
.font(.caption)
}
}
.disabled(!(node!.myInfo?.hasWifi ?? false))
.disabled(!(node != nil && node!.myInfo?.hasWifi ?? false))
Button {

View file

@ -280,6 +280,7 @@ struct TelemetryConfig: View {
.font(.caption)
}
}
.disabled(bleManager.connectedPeripheral == nil)
Button {

View file

@ -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()
}
}
}