Protect against weird channel index problems

This commit is contained in:
Garth Vander Houwen 2023-01-03 23:05:35 -08:00
parent 3ee7777c06
commit 8c19fa0fc4
2 changed files with 16 additions and 2 deletions

View file

@ -46,7 +46,7 @@ struct AboutMeshtastic: View {
Link("Documentation", destination: URL(string: "https://meshtastic.org/docs/getting-started")!)
.font(.title2)
}
Text("Meshtastic Copyright(c) Meshtastic LLC")
Text("Meshtastic® Copyright Meshtastic LLC")
.font(.caption)
}
}

View file

@ -91,7 +91,7 @@ struct Channels: View {
Button {
let key = generateChannelKey(size: 32)
channelName = ""
channelIndex = Int32(node!.myInfo!.channels!.array.count)
channelIndex = Int32((node!.myInfo!.channels!.array.count) - 1)
channelRole = 2
channelKey = key
uplink = false
@ -247,6 +247,20 @@ struct Channels: View {
channel.settings.psk = Data(base64Encoded: channelKey) ?? Data()
channel.settings.uplinkEnabled = uplink
channel.settings.downlinkEnabled = downlink
} else {
if channelIndex <= node!.myInfo!.channels?.count ?? 0 {
let channelEntity = node!.myInfo!.channels?[Int(channelIndex)] as! ChannelEntity
context.delete(channelEntity)
do {
try context.save()
print("💾 Deleted Channel: \(channel.settings.name)")
} catch {
context.rollback()
let nsError = error as NSError
print("💥 Unresolved Core Data error in the channel editor. Error: \(nsError)")
}
}
}
let adminMessageId = bleManager.saveChannel(channel: channel, fromUser: node!.user!, toUser: node!.user!)