From 27a90c4dc4415768c62fcfe815020962afb596eb Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 27 Sep 2022 22:18:50 -0700 Subject: [PATCH 1/2] Fix assorted nulls --- .../Settings/Config/BluetoothConfig.swift | 6 +++--- .../Views/Settings/Config/DeviceConfig.swift | 6 +++--- .../Views/Settings/Config/DisplayConfig.swift | 8 ++++---- .../Views/Settings/Config/LoRaConfig.swift | 12 +++++------ .../Config/Module/CannedMessagesConfig.swift | 20 +++++++++---------- .../Module/ExternalNotificationConfig.swift | 12 +++++------ .../Settings/Config/Module/MQTTConfig.swift | 12 +++++------ .../Config/Module/RangeTestConfig.swift | 6 +++--- .../Settings/Config/Module/SerialConfig.swift | 14 ++++++------- .../Config/Module/TelemetryConfig.swift | 10 +++++----- .../Views/Settings/Config/NetworkConfig.swift | 9 +++++---- .../Settings/Config/PositionConfig.swift | 14 ++++++------- Meshtastic/Views/Settings/ShareChannels.swift | 13 +++++++----- 13 files changed, 73 insertions(+), 69 deletions(-) diff --git a/Meshtastic/Views/Settings/Config/BluetoothConfig.swift b/Meshtastic/Views/Settings/Config/BluetoothConfig.swift index daa6aacb..eda12586 100644 --- a/Meshtastic/Views/Settings/Config/BluetoothConfig.swift +++ b/Meshtastic/Views/Settings/Config/BluetoothConfig.swift @@ -137,9 +137,9 @@ struct BluetoothConfig: View { self.bleManager.context = context - self.enabled = node!.bluetoothConfig?.enabled ?? true - self.mode = Int(node!.bluetoothConfig?.mode ?? 0) - self.fixedPin = String(node!.bluetoothConfig?.fixedPin ?? 123456) + self.enabled = node?.bluetoothConfig?.enabled ?? true + self.mode = Int(node?.bluetoothConfig?.mode ?? 0) + self.fixedPin = String(node?.bluetoothConfig?.fixedPin ?? 123456) self.hasChanges = false self.initialLoad = false } diff --git a/Meshtastic/Views/Settings/Config/DeviceConfig.swift b/Meshtastic/Views/Settings/Config/DeviceConfig.swift index eca8960a..2ac06bac 100644 --- a/Meshtastic/Views/Settings/Config/DeviceConfig.swift +++ b/Meshtastic/Views/Settings/Config/DeviceConfig.swift @@ -141,9 +141,9 @@ struct DeviceConfig: View { self.bleManager.context = context - self.deviceRole = Int(node!.deviceConfig?.role ?? 0) - self.serialEnabled = (node!.deviceConfig?.serialEnabled ?? true) - self.debugLogEnabled = node!.deviceConfig?.debugLogEnabled ?? false + self.deviceRole = Int(node?.deviceConfig?.role ?? 0) + self.serialEnabled = (node?.deviceConfig?.serialEnabled ?? true) + self.debugLogEnabled = node?.deviceConfig?.debugLogEnabled ?? false self.hasChanges = false self.initialLoad = false } diff --git a/Meshtastic/Views/Settings/Config/DisplayConfig.swift b/Meshtastic/Views/Settings/Config/DisplayConfig.swift index 6a1e6e25..576aaca2 100644 --- a/Meshtastic/Views/Settings/Config/DisplayConfig.swift +++ b/Meshtastic/Views/Settings/Config/DisplayConfig.swift @@ -127,10 +127,10 @@ struct DisplayConfig: View { self.bleManager.context = context - self.gpsFormat = Int(node!.displayConfig?.gpsFormat ?? 0) - self.screenOnSeconds = Int(node!.displayConfig?.screenOnSeconds ?? 0) - self.screenCarouselInterval = Int(node!.displayConfig?.screenCarouselInterval ?? 0) - self.compassNorthTop = node!.displayConfig?.compassNorthTop ?? false + self.gpsFormat = Int(node?.displayConfig?.gpsFormat ?? 0) + self.screenOnSeconds = Int(node?.displayConfig?.screenOnSeconds ?? 0) + self.screenCarouselInterval = Int(node?.displayConfig?.screenCarouselInterval ?? 0) + self.compassNorthTop = node?.displayConfig?.compassNorthTop ?? false self.hasChanges = false self.initialLoad = false } diff --git a/Meshtastic/Views/Settings/Config/LoRaConfig.swift b/Meshtastic/Views/Settings/Config/LoRaConfig.swift index 1ddeed80..cbac1a28 100644 --- a/Meshtastic/Views/Settings/Config/LoRaConfig.swift +++ b/Meshtastic/Views/Settings/Config/LoRaConfig.swift @@ -125,12 +125,12 @@ struct LoRaConfig: View { if self.initialLoad{ - self.hopLimit = Int(node!.loRaConfig?.hopLimit ?? 0) - self.region = Int(node!.loRaConfig?.regionCode ?? 0) - self.usePreset = node!.loRaConfig?.usePreset ?? true - self.modemPreset = Int(node!.loRaConfig?.modemPreset ?? 0) - self.txEnabled = node!.loRaConfig?.txEnabled ?? true - self.txPower = Int(node!.loRaConfig?.txPower ?? 0) + self.hopLimit = Int(node?.loRaConfig?.hopLimit ?? 0) + self.region = Int(node?.loRaConfig?.regionCode ?? 0) + self.usePreset = node?.loRaConfig?.usePreset ?? true + self.modemPreset = Int(node?.loRaConfig?.modemPreset ?? 0) + self.txEnabled = node?.loRaConfig?.txEnabled ?? true + self.txPower = Int(node?.loRaConfig?.txPower ?? 0) self.hasChanges = false self.initialLoad = false diff --git a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift index ef2c77a1..ea86a66f 100644 --- a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift @@ -290,16 +290,16 @@ struct CannedMessagesConfig: View { if self.initialLoad{ self.bleManager.context = context - self.enabled = node!.cannedMessageConfig?.enabled ?? false - self.sendBell = node!.cannedMessageConfig?.sendBell ?? false - self.rotary1Enabled = node!.cannedMessageConfig?.rotary1Enabled ?? false - self.updown1Enabled = node!.cannedMessageConfig?.updown1Enabled ?? false - self.inputbrokerPinA = Int(node!.cannedMessageConfig?.inputbrokerPinA ?? 0) - self.inputbrokerPinB = Int(node!.cannedMessageConfig?.inputbrokerPinB ?? 0) - self.inputbrokerPinPress = Int(node!.cannedMessageConfig?.inputbrokerPinPress ?? 0) - self.inputbrokerEventCw = Int(node!.cannedMessageConfig?.inputbrokerEventCw ?? 0) - self.inputbrokerEventCcw = Int(node!.cannedMessageConfig?.inputbrokerEventCcw ?? 0) - self.inputbrokerEventPress = Int(node!.cannedMessageConfig?.inputbrokerEventPress ?? 0) + self.enabled = node?.cannedMessageConfig?.enabled ?? false + self.sendBell = node?.cannedMessageConfig?.sendBell ?? false + self.rotary1Enabled = node?.cannedMessageConfig?.rotary1Enabled ?? false + self.updown1Enabled = node?.cannedMessageConfig?.updown1Enabled ?? false + self.inputbrokerPinA = Int(node?.cannedMessageConfig?.inputbrokerPinA ?? 0) + self.inputbrokerPinB = Int(node?.cannedMessageConfig?.inputbrokerPinB ?? 0) + self.inputbrokerPinPress = Int(node?.cannedMessageConfig?.inputbrokerPinPress ?? 0) + self.inputbrokerEventCw = Int(node?.cannedMessageConfig?.inputbrokerEventCw ?? 0) + self.inputbrokerEventCcw = Int(node?.cannedMessageConfig?.inputbrokerEventCcw ?? 0) + self.inputbrokerEventPress = Int(node?.cannedMessageConfig?.inputbrokerEventPress ?? 0) self.hasChanges = false self.initialLoad = false } diff --git a/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift b/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift index 8f07eb67..7e2ad96b 100644 --- a/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift @@ -186,12 +186,12 @@ struct ExternalNotificationConfig: View { self.bleManager.context = context - self.enabled = node!.externalNotificationConfig?.enabled ?? false - self.alertBell = node!.externalNotificationConfig?.alertBell ?? false - self.alertMessage = node!.externalNotificationConfig?.alertMessage ?? false - self.active = node!.externalNotificationConfig?.active ?? false - self.output = Int(node!.externalNotificationConfig?.output ?? 0) - self.outputMilliseconds = Int(node!.externalNotificationConfig?.outputMilliseconds ?? 0) + self.enabled = node?.externalNotificationConfig?.enabled ?? false + self.alertBell = node?.externalNotificationConfig?.alertBell ?? false + self.alertMessage = node?.externalNotificationConfig?.alertMessage ?? false + self.active = node?.externalNotificationConfig?.active ?? false + self.output = Int(node?.externalNotificationConfig?.output ?? 0) + self.outputMilliseconds = Int(node?.externalNotificationConfig?.outputMilliseconds ?? 0) self.hasChanges = false self.initialLoad = false diff --git a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift index 7f5fd3d5..7e987ca4 100644 --- a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift @@ -196,12 +196,12 @@ struct MQTTConfig: View { self.bleManager.context = context - self.enabled = (node!.mqttConfig?.enabled ?? false) - self.address = node!.mqttConfig?.address ?? "" - self.username = node!.mqttConfig?.username ?? "" - self.password = node!.mqttConfig?.password ?? "" - self.encryptionEnabled = (node!.mqttConfig?.encryptionEnabled ?? false) - self.jsonEnabled = (node!.mqttConfig?.jsonEnabled ?? false) + self.enabled = (node?.mqttConfig?.enabled ?? false) + self.address = node?.mqttConfig?.address ?? "" + self.username = node?.mqttConfig?.username ?? "" + self.password = node?.mqttConfig?.password ?? "" + self.encryptionEnabled = (node?.mqttConfig?.encryptionEnabled ?? false) + self.jsonEnabled = (node?.mqttConfig?.jsonEnabled ?? false) self.hasChanges = false self.initialLoad = false diff --git a/Meshtastic/Views/Settings/Config/Module/RangeTestConfig.swift b/Meshtastic/Views/Settings/Config/Module/RangeTestConfig.swift index 95f9b280..8bb25733 100644 --- a/Meshtastic/Views/Settings/Config/Module/RangeTestConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/RangeTestConfig.swift @@ -146,9 +146,9 @@ struct RangeTestConfig: View { if self.initialLoad{ self.bleManager.context = context - self.enabled = node!.rangeTestConfig?.enabled ?? false - self.save = node!.rangeTestConfig?.save ?? false - self.sender = Int(node!.rangeTestConfig?.sender ?? 0) + self.enabled = node?.rangeTestConfig?.enabled ?? false + self.save = node?.rangeTestConfig?.save ?? false + self.sender = Int(node?.rangeTestConfig?.sender ?? 0) self.hasChanges = false self.initialLoad = false } diff --git a/Meshtastic/Views/Settings/Config/Module/SerialConfig.swift b/Meshtastic/Views/Settings/Config/Module/SerialConfig.swift index e4969649..2971b599 100644 --- a/Meshtastic/Views/Settings/Config/Module/SerialConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/SerialConfig.swift @@ -163,13 +163,13 @@ struct SerialConfig: View { self.bleManager.context = context - self.enabled = node!.serialConfig?.enabled ?? false - self.echo = node!.serialConfig?.echo ?? false - self.rxd = Int(node!.serialConfig?.rxd ?? 0) - self.txd = Int(node!.serialConfig?.txd ?? 0) - self.baudRate = Int(node!.serialConfig?.baudRate ?? 0) - self.timeout = Int(node!.serialConfig?.timeout ?? 0) - self.mode = Int(node!.serialConfig?.mode ?? 0) + self.enabled = node?.serialConfig?.enabled ?? false + self.echo = node?.serialConfig?.echo ?? false + self.rxd = Int(node?.serialConfig?.rxd ?? 0) + self.txd = Int(node?.serialConfig?.txd ?? 0) + self.baudRate = Int(node?.serialConfig?.baudRate ?? 0) + self.timeout = Int(node?.serialConfig?.timeout ?? 0) + self.mode = Int(node?.serialConfig?.mode ?? 0) self.hasChanges = false self.initialLoad = false diff --git a/Meshtastic/Views/Settings/Config/Module/TelemetryConfig.swift b/Meshtastic/Views/Settings/Config/Module/TelemetryConfig.swift index 70ac4680..c015b307 100644 --- a/Meshtastic/Views/Settings/Config/Module/TelemetryConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/TelemetryConfig.swift @@ -189,11 +189,11 @@ struct TelemetryConfig: View { if self.initialLoad{ self.bleManager.context = context - self.deviceUpdateInterval = Int(node!.telemetryConfig?.deviceUpdateInterval ?? 0) - self.environmentUpdateInterval = Int(node!.telemetryConfig?.environmentUpdateInterval ?? 0) - self.environmentMeasurementEnabled = node!.telemetryConfig?.environmentMeasurementEnabled ?? false - self.environmentScreenEnabled = node!.telemetryConfig?.environmentScreenEnabled ?? false - self.environmentDisplayFahrenheit = node!.telemetryConfig?.environmentDisplayFahrenheit ?? false + self.deviceUpdateInterval = Int(node?.telemetryConfig?.deviceUpdateInterval ?? 0) + self.environmentUpdateInterval = Int(node?.telemetryConfig?.environmentUpdateInterval ?? 0) + self.environmentMeasurementEnabled = node?.telemetryConfig?.environmentMeasurementEnabled ?? false + self.environmentScreenEnabled = node?.telemetryConfig?.environmentScreenEnabled ?? false + self.environmentDisplayFahrenheit = node?.telemetryConfig?.environmentDisplayFahrenheit ?? false self.hasChanges = false self.initialLoad = false } diff --git a/Meshtastic/Views/Settings/Config/NetworkConfig.swift b/Meshtastic/Views/Settings/Config/NetworkConfig.swift index a80e58e0..707fea69 100644 --- a/Meshtastic/Views/Settings/Config/NetworkConfig.swift +++ b/Meshtastic/Views/Settings/Config/NetworkConfig.swift @@ -22,6 +22,7 @@ struct NetworkConfig: View { @State var wifiSsid = "" @State var wifiPsk = "" @State var wifiMode = 0 + @State var ntpServer = "" var body: some View { @@ -162,10 +163,10 @@ struct NetworkConfig: View { self.bleManager.context = context - self.wifiEnabled = (node!.networkConfig?.wifiEnabled ?? false) - self.wifiSsid = node!.networkConfig?.wifiSsid ?? "" - self.wifiPsk = node!.networkConfig?.wifiPsk ?? "" - self.wifiMode = Int(node!.networkConfig?.wifiMode ?? 0) + self.wifiEnabled = (node?.networkConfig?.wifiEnabled ?? false) + self.wifiSsid = node?.networkConfig?.wifiSsid ?? "" + self.wifiPsk = node?.networkConfig?.wifiPsk ?? "" + self.wifiMode = Int(node?.networkConfig?.wifiMode ?? 0) self.hasChanges = false self.initialLoad = false diff --git a/Meshtastic/Views/Settings/Config/PositionConfig.swift b/Meshtastic/Views/Settings/Config/PositionConfig.swift index d750603e..24b2e00c 100644 --- a/Meshtastic/Views/Settings/Config/PositionConfig.swift +++ b/Meshtastic/Views/Settings/Config/PositionConfig.swift @@ -284,13 +284,13 @@ struct PositionConfig: View { if self.initialLoad{ self.bleManager.context = context - self.smartPositionEnabled = node!.positionConfig?.smartPositionEnabled ?? true - self.deviceGpsEnabled = node!.positionConfig?.deviceGpsEnabled ?? true - self.fixedPosition = node!.positionConfig?.fixedPosition ?? false - self.gpsUpdateInterval = Int(node!.positionConfig?.gpsUpdateInterval ?? 30) - self.gpsAttemptTime = Int(node!.positionConfig?.gpsAttemptTime ?? 30) - self.positionBroadcastSeconds = Int(node!.positionConfig?.positionBroadcastSeconds ?? 900) - self.positionFlags = Int(node!.positionConfig?.positionFlags ?? 3) + self.smartPositionEnabled = node?.positionConfig?.smartPositionEnabled ?? true + self.deviceGpsEnabled = node?.positionConfig?.deviceGpsEnabled ?? true + self.fixedPosition = node?.positionConfig?.fixedPosition ?? false + self.gpsUpdateInterval = Int(node?.positionConfig?.gpsUpdateInterval ?? 30) + self.gpsAttemptTime = Int(node?.positionConfig?.gpsAttemptTime ?? 30) + self.positionBroadcastSeconds = Int(node?.positionConfig?.positionBroadcastSeconds ?? 900) + self.positionFlags = Int(node?.positionConfig?.positionFlags ?? 3) let pf = PositionFlags(rawValue: self.positionFlags) diff --git a/Meshtastic/Views/Settings/ShareChannels.swift b/Meshtastic/Views/Settings/ShareChannels.swift index 03dca338..82dbb747 100644 --- a/Meshtastic/Views/Settings/ShareChannels.swift +++ b/Meshtastic/Views/Settings/ShareChannels.swift @@ -77,14 +77,17 @@ struct ShareChannels: View { } VStack { - Text("Number of Channels: \(node!.myInfo!.maxChannels)").font(.title2) + Text("Number of Channels: \(node?.myInfo?.maxChannels ?? 0)").font(.title2) - ForEach(node!.myInfo!.channels?.array.sorted(by: { ($0 as! ChannelEntity).index < ($1 as! ChannelEntity).index }) as! [ChannelEntity], id: \.self) { (channel: ChannelEntity) in + if node != nil { - VStack { + ForEach(node!.myInfo!.channels?.array.sorted(by: { ($0 as! ChannelEntity).index < ($1 as! ChannelEntity).index }) as! [ChannelEntity], id: \.self) { (channel: ChannelEntity) in - - Text("Channel: \(channel.index) Name: \(channel.name ?? "")") + VStack { + + + Text("Channel: \(channel.index) Name: \(channel.name ?? "")") + } } } } From 83fac42e3da5a27610b415e0b58e91f0fd78fafd Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 27 Sep 2022 22:20:04 -0700 Subject: [PATCH 2/2] remove disabled from settings --- Meshtastic/Views/Settings/Settings.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Meshtastic/Views/Settings/Settings.swift b/Meshtastic/Views/Settings/Settings.swift index f33bec77..ad33e119 100644 --- a/Meshtastic/Views/Settings/Settings.swift +++ b/Meshtastic/Views/Settings/Settings.swift @@ -210,7 +210,6 @@ struct Settings: View { // Store Forward Config - Not Working, TBEAM Only } - .disabled(!(bleManager.connectedPeripheral?.subscribed ?? true)) .onAppear { self.bleManager.context = context