mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
83 lines
2 KiB
Swift
83 lines
2 KiB
Swift
//
|
|
// SaveChannelQRCode.swift
|
|
// Meshtastic
|
|
//
|
|
// Copyright(c) Garth Vander Houwen 7/13/22.
|
|
//
|
|
import SwiftUI
|
|
|
|
struct SaveChannelQRCode: View {
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
var channelSetLink: String
|
|
var addChannels: Bool = false
|
|
var bleManager: BLEManager
|
|
@State var showError: Bool = false
|
|
@State var connectedToDevice = false
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Text("\(addChannels ? "Add" : "Replace all") Channels?")
|
|
.font(.title)
|
|
Text("These settings will \(addChannels ? "add" : "replace all") channels. The current LoRa Config will be replaced, if there are substantial changes to the LoRa config the device will reboot")
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.foregroundColor(.gray)
|
|
.font(.title3)
|
|
.padding()
|
|
|
|
if showError {
|
|
Text("Channels being added from the QR code did not save. When adding channels the names must be unique.")
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.foregroundColor(.red)
|
|
.font(.callout)
|
|
.padding()
|
|
}
|
|
HStack {
|
|
if !showError {
|
|
Button {
|
|
let success = bleManager.saveChannelSet(base64UrlString: channelSetLink, addChannels: addChannels)
|
|
if success {
|
|
dismiss()
|
|
} else {
|
|
showError = true
|
|
}
|
|
} label: {
|
|
Label("save", systemImage: "square.and.arrow.down")
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.buttonBorderShape(.capsule)
|
|
.controlSize(.large)
|
|
.padding()
|
|
.disabled(!connectedToDevice)
|
|
#if targetEnvironment(macCatalyst)
|
|
Button {
|
|
dismiss()
|
|
} label: {
|
|
Label("Cancel", systemImage: "xmark")
|
|
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.buttonBorderShape(.capsule)
|
|
.controlSize(.large)
|
|
.padding()
|
|
#endif
|
|
} else {
|
|
Button {
|
|
dismiss()
|
|
} label: {
|
|
Label("Cancel", systemImage: "xmark")
|
|
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.buttonBorderShape(.capsule)
|
|
.controlSize(.large)
|
|
.padding()
|
|
}
|
|
}
|
|
}
|
|
.onAppear {
|
|
connectedToDevice = bleManager.connectToPreferredPeripheral()
|
|
}
|
|
}
|
|
}
|