From 8c19fa0fc4e83339e8dcb2b66df00b10acd44837 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 3 Jan 2023 23:05:35 -0800 Subject: [PATCH] Protect against weird channel index problems --- Meshtastic/Views/Settings/About.swift | 2 +- Meshtastic/Views/Settings/Channels.swift | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Meshtastic/Views/Settings/About.swift b/Meshtastic/Views/Settings/About.swift index 32745f11..43e67809 100644 --- a/Meshtastic/Views/Settings/About.swift +++ b/Meshtastic/Views/Settings/About.swift @@ -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) } } diff --git a/Meshtastic/Views/Settings/Channels.swift b/Meshtastic/Views/Settings/Channels.swift index 7d115fc6..b335064e 100644 --- a/Meshtastic/Views/Settings/Channels.swift +++ b/Meshtastic/Views/Settings/Channels.swift @@ -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!)