This commit is contained in:
Garth Vander Houwen 2024-04-03 00:04:46 -07:00
parent 2a38dbbb1c
commit 85b8c0b091
3 changed files with 12 additions and 12 deletions

View file

@ -1304,12 +1304,12 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
return 0
}
public func saveChannelSet(base64UrlString: String, addChannel: Bool = false) -> Bool {
public func saveChannelSet(base64UrlString: String, addChannels: Bool = false) -> Bool {
if isConnected {
var i: Int32 = 0
// Before we get started delete the existing channels from the myNodeInfo
if !addChannel {
if !addChannels {
tryClearExistingChannels()
} else {
// We are trying to add a channel so lets get the last index
@ -1318,7 +1318,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
do {
let fetchedMyInfo = try context?.fetch(fetchMyInfoRequest) as? [MyInfoEntity] ?? []
if fetchedMyInfo.count == 1 {
if addChannel {
if addChannels {
i = Int32(fetchedMyInfo[0].channels?.count ?? -1)
// Bail out if the index is negative or bigger than our max of 8
if i < 0 || i > 8 {

View file

@ -18,7 +18,7 @@ struct MeshtasticAppleApp: App {
@State var saveChannels = false
@State var incomingUrl: URL?
@State var channelSettings: String?
@State var addChannel = false
@State var addChannels = false
@StateObject var appState = AppState.shared
var body: some Scene {
@ -27,7 +27,7 @@ struct MeshtasticAppleApp: App {
.environment(\.managedObjectContext, persistenceController.container.viewContext)
.environmentObject(bleManager)
.sheet(isPresented: $saveChannels) {
SaveChannelQRCode(channelSetLink: channelSettings ?? "Empty Channel URL", addChannel: addChannel, bleManager: bleManager)
SaveChannelQRCode(channelSetLink: channelSettings ?? "Empty Channel URL", addChannels: addChannels, bleManager: bleManager)
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)
}
@ -42,8 +42,8 @@ struct MeshtasticAppleApp: App {
return
}
self.channelSettings = cs
self.addChannel = Bool(self.incomingUrl?["add"] ?? "false") ?? false
print("Add Channel \(self.addChannel)")
self.addChannels = Bool(self.incomingUrl?["add"] ?? "false") ?? false
print("Add Channel \(self.addChannels)")
}
self.saveChannels = true
print("User wants to open a Channel Settings URL: \(self.incomingUrl?.absoluteString ?? "No QR Code Link")")

View file

@ -11,23 +11,23 @@ struct SaveChannelQRCode: View {
@Environment(\.dismiss) private var dismiss
var channelSetLink: String
var addChannel: Bool = false
var addChannels: Bool = false
var bleManager: BLEManager
@State var connectedToDevice = false
var body: some View {
VStack {
Text("Save Channel Settings?")
Text("\(addChannels ? "Add" : "Replace all") Channels?")
.font(.title)
Text("These settings will replace the current LoRa Config and Channel Settings on your radio. After everything saves your device will reboot.")
Text("These settings will \(addChannels ? "add" : "replace all") channels. The current LoRa Config will be replaced. After everything saves your device will reboot.")
.foregroundColor(.gray)
.font(.callout)
.font(.title3)
.padding()
HStack {
Button {
let success = bleManager.saveChannelSet(base64UrlString: channelSetLink, addChannel: addChannel)
let success = bleManager.saveChannelSet(base64UrlString: channelSetLink, addChannels: addChannels)
if success {
dismiss()
}