From 09dfc902664119edc21425740c9c9ca2e09b1770 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 7 Jul 2024 09:40:06 -0700 Subject: [PATCH] Fix disable channel crash, use a switch to make generate qr code more readable --- Localizable.xcstrings | 2 +- Meshtastic/Views/Settings/Channels.swift | 3 +- .../Views/Settings/SaveChannelQRCode.swift | 2 +- Meshtastic/Views/Settings/ShareChannels.swift | 42 +++++++++++++++++-- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Localizable.xcstrings b/Localizable.xcstrings index 1e056d2f..ce93458d 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -20839,7 +20839,7 @@ "There has been no response to a request for device metadata over the admin channel for this node." : { }, - "These settings will %@ channels. The current LoRa Config will be replaced. After everything saves your device will reboot." : { + "These settings will %@ channels. The current LoRa Config will be replaced, if there are substantial changes to the LoRa config the device will reboot" : { }, "Thirty Minutes" : { diff --git a/Meshtastic/Views/Settings/Channels.swift b/Meshtastic/Views/Settings/Channels.swift index 2021b536..816c6eb1 100644 --- a/Meshtastic/Views/Settings/Channels.swift +++ b/Meshtastic/Views/Settings/Channels.swift @@ -172,7 +172,8 @@ struct Channels: View { return } if mutableChannels.contains(selectedChannel as Any) { - mutableChannels.replaceObject(at: Int(channel.index), with: selectedChannel as Any) + let replaceChannel = mutableChannels.first(where: { selectedChannel?.psk == ($0 as AnyObject).psk && selectedChannel?.name == ($0 as AnyObject).name}) + mutableChannels.replaceObject(at: mutableChannels.index(of: replaceChannel as Any), with: selectedChannel as Any) } else { mutableChannels.add(selectedChannel as Any) } diff --git a/Meshtastic/Views/Settings/SaveChannelQRCode.swift b/Meshtastic/Views/Settings/SaveChannelQRCode.swift index c00a3c59..fee7877b 100644 --- a/Meshtastic/Views/Settings/SaveChannelQRCode.swift +++ b/Meshtastic/Views/Settings/SaveChannelQRCode.swift @@ -20,7 +20,7 @@ struct SaveChannelQRCode: 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. After everything saves your device will reboot.") + 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) diff --git a/Meshtastic/Views/Settings/ShareChannels.swift b/Meshtastic/Views/Settings/ShareChannels.swift index 1eeebb7c..51d066eb 100644 --- a/Meshtastic/Views/Settings/ShareChannels.swift +++ b/Meshtastic/Views/Settings/ShareChannels.swift @@ -270,9 +270,45 @@ struct ShareChannels: View { loRaConfig.ignoreMqtt = node?.loRaConfig?.ignoreMqtt ?? false channelSet.loraConfig = loRaConfig if node?.myInfo?.channels != nil && node?.myInfo?.channels?.count ?? 0 > 0 { - for ch in node?.myInfo?.channels?.array as? [ChannelEntity] ?? [] { - if ch.role > 0, ch.index == 0 && includeChannel0 || ch.index == 1 && includeChannel1 || ch.index == 2 && includeChannel2 || ch.index == 3 && includeChannel3 || - ch.index == 4 && includeChannel4 || ch.index == 5 && includeChannel5 || ch.index == 6 && includeChannel6 || ch.index == 7 && includeChannel7 { + for ch in node?.myInfo?.channels?.array as? [ChannelEntity] ?? [] where ch.role > 0 { + var includeChannel = false + switch ch.index { + case 0: + if includeChannel0 { + includeChannel = true + } + case 1: + if includeChannel1 { + includeChannel = true + } + case 2: + if includeChannel2 { + includeChannel = true + } + case 3: + if includeChannel3 { + includeChannel = true + } + case 4: + if includeChannel4 { + includeChannel = true + } + case 5: + if includeChannel5 { + includeChannel = true + } + case 6: + if includeChannel6 { + includeChannel = true + } + case 7: + if includeChannel7 { + includeChannel = true + } + default: + includeChannel = false + } + if includeChannel { var channelSettings = ChannelSettings() channelSettings.name = ch.name! channelSettings.psk = ch.psk!