Skip to content

Commit

Permalink
Fix disable channel crash, use a switch to make generate qr code more…
Browse files Browse the repository at this point in the history
… readable
  • Loading branch information
garthvh committed Jul 7, 2024
1 parent 4aa18c2 commit 09dfc90
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -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" : {
Expand Down
3 changes: 2 additions & 1 deletion Meshtastic/Views/Settings/Channels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Meshtastic/Views/Settings/SaveChannelQRCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 39 additions & 3 deletions Meshtastic/Views/Settings/ShareChannels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit 09dfc90

Please sign in to comment.