diff --git a/Meshtastic/Views/MapKitMap/WaypointFormMapKit.swift b/Meshtastic/Views/MapKitMap/WaypointFormMapKit.swift index f2451a28..ed48e1a4 100644 --- a/Meshtastic/Views/MapKitMap/WaypointFormMapKit.swift +++ b/Meshtastic/Views/MapKitMap/WaypointFormMapKit.swift @@ -72,14 +72,14 @@ struct WaypointFormMapKit: View { axis: .vertical ) .foregroundColor(Color.gray) - .onChange(of: description, perform: { _ in + .onChange(of: description) { var totalBytes = description.utf8.count // Only mess with the value if it is too big while totalBytes > 100 { description = String(description.dropLast()) totalBytes = description.utf8.count } - }) + } } HStack { Text("Icon") @@ -87,7 +87,7 @@ struct WaypointFormMapKit: View { EmojiOnlyTextField(text: $icon, placeholder: "Select an emoji") .font(.title) .focused($iconIsFocused) - .onChange(of: icon) { value in + .onChange(of: icon) { _, value in // If you have anything other than emojis in your string make it empty if !value.onlyEmojis() { diff --git a/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift b/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift index 9b163154..71d62590 100644 --- a/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift +++ b/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift @@ -98,7 +98,7 @@ struct WaypointForm: View { EmojiOnlyTextField(text: $icon, placeholder: "Select an emoji") .font(.title) .focused($iconIsFocused) - .onChange(of: icon) { value in + .onChange(of: icon) { _, value in // If you have anything other than emojis in your string make it empty if !value.onlyEmojis() { diff --git a/Meshtastic/Views/Settings/Config/BluetoothConfig.swift b/Meshtastic/Views/Settings/Config/BluetoothConfig.swift index bf036aca..37f989a5 100644 --- a/Meshtastic/Views/Settings/Config/BluetoothConfig.swift +++ b/Meshtastic/Views/Settings/Config/BluetoothConfig.swift @@ -121,14 +121,14 @@ struct BluetoothConfig: View { } } } - .onChange(of: enabled) { - if $0 != node?.bluetoothConfig?.enabled { hasChanges = true } + .onChange(of: enabled) { oldEnabled, newEnabled in + if oldEnabled != newEnabled && newEnabled != node?.bluetoothConfig?.enabled { hasChanges = true } } - .onChange(of: mode) { - if $0 != node?.bluetoothConfig?.mode ?? -1 { hasChanges = true } + .onChange(of: mode) { oldNode, newNode in + if oldNode != newNode && newNode != node?.bluetoothConfig?.mode ?? -1 { hasChanges = true } } - .onChange(of: fixedPin) { newFixedPin in - if newFixedPin != String(node?.bluetoothConfig?.fixedPin ?? -1) { hasChanges = true } + .onChange(of: fixedPin) { oldFixedPin, newFixedPin in + if oldFixedPin != newFixedPin && newFixedPin != String(node?.bluetoothConfig?.fixedPin ?? -1) { hasChanges = true } } } func setBluetoothValues() { diff --git a/Meshtastic/Views/Settings/Config/DeviceConfig.swift b/Meshtastic/Views/Settings/Config/DeviceConfig.swift index 9d20782c..f5fca283 100644 --- a/Meshtastic/Views/Settings/Config/DeviceConfig.swift +++ b/Meshtastic/Views/Settings/Config/DeviceConfig.swift @@ -261,22 +261,20 @@ struct DeviceConfig: View { .onChange(of: rebroadcastMode) { oldRebroadcastMode, newRebroadcastMode in if oldRebroadcastMode != newRebroadcastMode && newRebroadcastMode != node?.deviceConfig?.rebroadcastMode ?? -1 { hasChanges = true } } - .onChange(of: nodeInfoBroadcastSecs) { newNodeInfoBroadcastSecs in - if newNodeInfoBroadcastSecs != node?.deviceConfig?.nodeInfoBroadcastSecs ?? -1 { hasChanges = true } + .onChange(of: nodeInfoBroadcastSecs) { oldNodeInfoBroadcastSecs, newNodeInfoBroadcastSecs in + if oldNodeInfoBroadcastSecs != newNodeInfoBroadcastSecs && newNodeInfoBroadcastSecs != node?.deviceConfig?.nodeInfoBroadcastSecs ?? -1 { hasChanges = true } } - .onChange(of: doubleTapAsButtonPress) { - if $0 != node?.deviceConfig?.doubleTapAsButtonPress { hasChanges = true } + .onChange(of: doubleTapAsButtonPress) { oldDoubleTapAsButtonPress, newDoubleTapAsButtonPress in + if oldDoubleTapAsButtonPress != newDoubleTapAsButtonPress && newDoubleTapAsButtonPress != node?.deviceConfig?.doubleTapAsButtonPress ?? false { hasChanges = true } } - .onChange(of: tripleClickAsAdHocPing) { - if $0 != node?.deviceConfig?.tripleClickAsAdHocPing { hasChanges = true } + .onChange(of: tripleClickAsAdHocPing) { oldTripleClickAsAdHocPing, newTripleClickAsAdHocPing in + if oldTripleClickAsAdHocPing != newTripleClickAsAdHocPing && newTripleClickAsAdHocPing != node?.deviceConfig?.tripleClickAsAdHocPing ?? false { hasChanges = true } } - .onChange(of: tzdef) { newTzdef in - if newTzdef != node?.deviceConfig?.tzdef { hasChanges = true } + .onChange(of: tzdef) { oldTzdef, newTzdef in + if oldTzdef != newTzdef && newTzdef != node?.deviceConfig?.tzdef { hasChanges = true } } - .onChange(of: ledHeartbeatEnabled) { newLedHeartbeatEnabled in - if node != nil && node?.deviceConfig != nil { - if newLedHeartbeatEnabled != node!.deviceConfig!.ledHeartbeatEnabled { hasChanges = true } - } + .onChange(of: ledHeartbeatEnabled) { oldLedHeartbeatEnabled, newLedHeartbeatEnabled in + if oldLedHeartbeatEnabled != newLedHeartbeatEnabled && newLedHeartbeatEnabled != node?.deviceConfig?.ledHeartbeatEnabled ?? false { hasChanges = true } } } func setDeviceValues() { diff --git a/Meshtastic/Views/Settings/Config/DisplayConfig.swift b/Meshtastic/Views/Settings/Config/DisplayConfig.swift index 1e9781a6..07975419 100644 --- a/Meshtastic/Views/Settings/Config/DisplayConfig.swift +++ b/Meshtastic/Views/Settings/Config/DisplayConfig.swift @@ -184,32 +184,32 @@ struct DisplayConfig: View { } } } - .onChange(of: screenOnSeconds) { newScreenSecs in - if newScreenSecs != node?.displayConfig?.screenOnSeconds ?? -1 { hasChanges = true } + .onChange(of: screenOnSeconds) { oldScreenSecs, newScreenSecs in + if oldScreenSecs != newScreenSecs && newScreenSecs != node?.displayConfig?.screenOnSeconds ?? -1 { hasChanges = true } } - .onChange(of: screenCarouselInterval) { newCarouselSecs in - if newCarouselSecs != node?.displayConfig?.screenCarouselInterval ?? -1 { hasChanges = true } + .onChange(of: screenCarouselInterval) { oldCarouselSecs, newCarouselSecs in + if oldCarouselSecs != newCarouselSecs && newCarouselSecs != node?.displayConfig?.screenCarouselInterval ?? -1 { hasChanges = true } } - .onChange(of: compassNorthTop) { - if $0 != node?.displayConfig?.compassNorthTop { hasChanges = true } + .onChange(of: compassNorthTop) { oldCompassNorthTop, newCompassNorthTop in + if oldCompassNorthTop != newCompassNorthTop && newCompassNorthTop != node?.displayConfig?.compassNorthTop { hasChanges = true } } - .onChange(of: wakeOnTapOrMotion) { - if $0 != node?.displayConfig?.wakeOnTapOrMotion { hasChanges = true } + .onChange(of: wakeOnTapOrMotion) { oldWakeOnTapOrMotion, newWakeOnTapOrMotion in + if oldWakeOnTapOrMotion != newWakeOnTapOrMotion && newWakeOnTapOrMotion != node?.displayConfig?.wakeOnTapOrMotion { hasChanges = true } } - .onChange(of: gpsFormat) { newGpsFormat in - if newGpsFormat != node?.displayConfig?.gpsFormat ?? -1 { hasChanges = true } + .onChange(of: gpsFormat) { oldGpsFormat, newGpsFormat in + if oldGpsFormat != newGpsFormat && newGpsFormat != node?.displayConfig?.gpsFormat ?? -1 { hasChanges = true } } - .onChange(of: flipScreen) { - if $0 != node?.displayConfig?.flipScreen { hasChanges = true } + .onChange(of: flipScreen) { oldFlipScreen, newFlipScreen in + if oldFlipScreen != newFlipScreen && newFlipScreen != node?.displayConfig?.flipScreen { hasChanges = true } } - .onChange(of: oledType) { newOledType in - if newOledType != node?.displayConfig?.oledType ?? -1 { hasChanges = true } + .onChange(of: oledType) { oldOledType, newOledType in + if oldOledType != newOledType && newOledType != node?.displayConfig?.oledType ?? -1 { hasChanges = true } } - .onChange(of: displayMode) { newDisplayMode in - if newDisplayMode != node?.displayConfig?.displayMode ?? -1 { hasChanges = true } + .onChange(of: displayMode) { oldDisplayMode, newDisplayMode in + if oldDisplayMode != newDisplayMode && newDisplayMode != node?.displayConfig?.displayMode ?? -1 { hasChanges = true } } - .onChange(of: units) { newUnits in - if newUnits != node?.displayConfig?.units ?? -1 { hasChanges = true } + .onChange(of: units) { oldUnits, newUnits in + if oldUnits != newUnits && newUnits != node?.displayConfig?.units ?? -1 { hasChanges = true } } } func setDisplayValues() { diff --git a/Meshtastic/Views/Settings/Config/LoRaConfig.swift b/Meshtastic/Views/Settings/Config/LoRaConfig.swift index 13623ee3..4c12c598 100644 --- a/Meshtastic/Views/Settings/Config/LoRaConfig.swift +++ b/Meshtastic/Views/Settings/Config/LoRaConfig.swift @@ -259,47 +259,47 @@ struct LoRaConfig: View { } } } - .onChange(of: region) { newRegion in + .onChange(of: region) { _, newRegion in if newRegion != node?.loRaConfig?.regionCode ?? -1 { hasChanges = true } } - .onChange(of: usePreset) { - if $0 != node?.loRaConfig?.usePreset { hasChanges = true } + .onChange(of: usePreset) { _, newPreset in + if newPreset != node?.loRaConfig?.usePreset { hasChanges = true } } - .onChange(of: modemPreset) { newModemPreset in + .onChange(of: modemPreset) { _, newModemPreset in if newModemPreset != node?.loRaConfig?.modemPreset ?? -1 { hasChanges = true } } - .onChange(of: hopLimit) { newHopLimit in + .onChange(of: hopLimit) { _, newHopLimit in if newHopLimit != node?.loRaConfig?.hopLimit ?? -1 { hasChanges = true } } - .onChange(of: channelNum) { newChannelNum in + .onChange(of: channelNum) { _, newChannelNum in if newChannelNum != node?.loRaConfig?.channelNum ?? -1 { hasChanges = true } } - .onChange(of: bandwidth) { newBandwidth in + .onChange(of: bandwidth) { _, newBandwidth in if newBandwidth != node?.loRaConfig?.bandwidth ?? -1 { hasChanges = true } } - .onChange(of: codingRate) { newCodingRate in + .onChange(of: codingRate) { _, newCodingRate in if newCodingRate != node?.loRaConfig?.codingRate ?? -1 { hasChanges = true } } - .onChange(of: spreadFactor) { newSpreadFactor in + .onChange(of: spreadFactor) { _, newSpreadFactor in if newSpreadFactor != node?.loRaConfig?.spreadFactor ?? -1 { hasChanges = true } } - .onChange(of: rxBoostedGain) { - if $0 != node?.loRaConfig?.sx126xRxBoostedGain { hasChanges = true } + .onChange(of: rxBoostedGain) { _, newRxBoostedGain in + if newRxBoostedGain != node?.loRaConfig?.sx126xRxBoostedGain { hasChanges = true } } - .onChange(of: overrideFrequency) { newOverrideFrequency in + .onChange(of: overrideFrequency) { _, newOverrideFrequency in if newOverrideFrequency != node?.loRaConfig?.overrideFrequency { hasChanges = true } } - .onChange(of: txPower) { newTxPower in + .onChange(of: txPower) { _, newTxPower in if newTxPower != node?.loRaConfig?.txPower ?? -1 { hasChanges = true } } - .onChange(of: txEnabled) { - if $0 != node?.loRaConfig?.txEnabled { hasChanges = true } + .onChange(of: txEnabled) { _, newTxEnabled in + if newTxEnabled != node?.loRaConfig?.txEnabled { hasChanges = true } } - .onChange(of: ignoreMqtt) { - if $0 != node?.loRaConfig?.ignoreMqtt { hasChanges = true } + .onChange(of: ignoreMqtt) { _, newIgnoreMqtt in + if newIgnoreMqtt != node?.loRaConfig?.ignoreMqtt { hasChanges = true } } - .onChange(of: okToMqtt) { - if $0 != node?.loRaConfig?.okToMqtt { hasChanges = true } + .onChange(of: okToMqtt) { _, newOkToMqtt in + if newOkToMqtt != node?.loRaConfig?.okToMqtt { hasChanges = true } } } func setLoRaValues() { diff --git a/Meshtastic/Views/Settings/Config/Module/AmbientLightingConfig.swift b/Meshtastic/Views/Settings/Config/Module/AmbientLightingConfig.swift index 5e82da1b..fc82a4ca 100644 --- a/Meshtastic/Views/Settings/Config/Module/AmbientLightingConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/AmbientLightingConfig.swift @@ -106,20 +106,14 @@ struct AmbientLightingConfig: View { } } } - .onChange(of: ledState) { - if let val = node?.ambientLightingConfig?.ledState { - hasChanges = $0 != val - } + .onChange(of: ledState) { _, newLedState in + if newLedState != node?.ambientLightingConfig?.ledState { hasChanges = true } } - .onChange(of: current) { - if let val = node?.ambientLightingConfig?.current { - hasChanges = $0 != val - } + .onChange(of: current) { _, newCurrent in + if newCurrent != node?.ambientLightingConfig?.current ?? 10 { hasChanges = true } } - .onChange(of: color) { c in - if color != c { - hasChanges = true - } + .onChange(of: color) { oldColor, newColor in + if oldColor != newColor { hasChanges = true } } } } diff --git a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift index 699d22d4..4f580b2a 100644 --- a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift @@ -283,55 +283,35 @@ struct CannedMessagesConfig: View { hasChanges = true } - .onChange(of: enabled) { - if let val = node?.cannedMessageConfig?.enabled { - hasChanges = $0 != val - } + .onChange(of: enabled) { _, newEnabled in + if newEnabled != node?.cannedMessageConfig?.enabled { hasChanges = true } } - .onChange(of: sendBell) { - if let val = node?.cannedMessageConfig?.sendBell { - hasChanges = $0 != val - } + .onChange(of: sendBell) { _, newSendBell in + if newSendBell != node?.cannedMessageConfig?.sendBell { hasChanges = true } } - .onChange(of: rotary1Enabled) { - if let val = node?.cannedMessageConfig?.rotary1Enabled { - hasChanges = $0 != val - } + .onChange(of: rotary1Enabled) { _, newRotary1Enabled in + if newRotary1Enabled != node?.cannedMessageConfig?.rotary1Enabled { hasChanges = true } } - .onChange(of: updown1Enabled) { - if let val = node?.cannedMessageConfig?.updown1Enabled { - hasChanges = $0 != val - } + .onChange(of: updown1Enabled) { _, newUpdown1Enabled in + if newUpdown1Enabled != node?.cannedMessageConfig?.updown1Enabled { hasChanges = true } } - .onChange(of: inputbrokerPinA) { newPinA in - if node != nil && node!.cannedMessageConfig != nil { - if newPinA != node!.cannedMessageConfig!.inputbrokerPinA { hasChanges = true } - } + .onChange(of: inputbrokerPinA) { _, newPinA in + if newPinA != node?.cannedMessageConfig?.inputbrokerPinA ?? -1 { hasChanges = true } } - .onChange(of: inputbrokerPinB) { newPinB in - if node != nil && node!.cannedMessageConfig != nil { - if newPinB != node!.cannedMessageConfig!.inputbrokerPinB { hasChanges = true } - } + .onChange(of: inputbrokerPinB) { _, newPinB in + if newPinB != node?.cannedMessageConfig?.inputbrokerPinB ?? -1 { hasChanges = true } } - .onChange(of: inputbrokerPinPress) { newPinPress in - if node != nil && node!.cannedMessageConfig != nil { - if newPinPress != node!.cannedMessageConfig!.inputbrokerPinPress { hasChanges = true } - } + .onChange(of: inputbrokerPinPress) { _, newPinPress in + if newPinPress != node?.cannedMessageConfig?.inputbrokerPinPress ?? -1 { hasChanges = true } } - .onChange(of: inputbrokerEventCw) { newKeyA in - if node != nil && node!.cannedMessageConfig != nil { - if newKeyA != node!.cannedMessageConfig!.inputbrokerEventCw { hasChanges = true } - } + .onChange(of: inputbrokerEventCw) { _, newKeyA in + if newKeyA != node?.cannedMessageConfig?.inputbrokerEventCw ?? -1 { hasChanges = true } } - .onChange(of: inputbrokerEventCcw) { newKeyB in - if node != nil && node!.cannedMessageConfig != nil { - if newKeyB != node!.cannedMessageConfig!.inputbrokerEventCcw { hasChanges = true } - } + .onChange(of: inputbrokerEventCcw) { _, newKeyB in + if newKeyB != node?.cannedMessageConfig?.inputbrokerEventCcw ?? -1 { hasChanges = true } } - .onChange(of: inputbrokerEventPress) { newKeyPress in - if node != nil && node!.cannedMessageConfig != nil { - if newKeyPress != node!.cannedMessageConfig!.inputbrokerEventPress { hasChanges = true } - } + .onChange(of: inputbrokerEventPress) { _, newKeyPress in + if newKeyPress != node?.cannedMessageConfig?.inputbrokerEventPress ?? -1 { hasChanges = true } } } } diff --git a/Meshtastic/Views/Settings/Config/Module/DetectionSensorConfig.swift b/Meshtastic/Views/Settings/Config/Module/DetectionSensorConfig.swift index 6305dd98..eb50a80f 100644 --- a/Meshtastic/Views/Settings/Config/Module/DetectionSensorConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/DetectionSensorConfig.swift @@ -91,14 +91,14 @@ struct DetectionSensorConfig: View { .foregroundColor(.gray) .autocapitalization(.none) .disableAutocorrection(true) - .onChange(of: name, perform: { _ in + .onChange(of: name) { var totalBytes = name.utf8.count // Only mess with the value if it is too big while totalBytes > 20 { name = String(name.dropLast()) totalBytes = name.utf8.count } - }) + } } .listRowSeparator(.hidden) Text("Friendly name used to format message sent to mesh. Example: A name \"Motion\" would result in a message \"Motion detected\"") @@ -210,47 +210,31 @@ struct DetectionSensorConfig: View { } } } - .onChange(of: enabled) { - if let val = node?.detectionSensorConfig?.enabled { - hasChanges = $0 != val - } + .onChange(of: enabled) { _, newEnabled in + if newEnabled != node?.detectionSensorConfig?.enabled { hasChanges = true } } - .onChange(of: sendBell) { - if let val = node?.detectionSensorConfig?.sendBell { - hasChanges = $0 != val - } + .onChange(of: sendBell) { _, newSendBell in + if newSendBell != node?.detectionSensorConfig?.sendBell { hasChanges = true } } - .onChange(of: detectionTriggeredHigh) { newDetectionTriggeredHigh in - if node != nil && node?.detectionSensorConfig != nil { - if newDetectionTriggeredHigh != node!.detectionSensorConfig!.detectionTriggeredHigh { hasChanges = true } - } + .onChange(of: detectionTriggeredHigh) { _, newDetectionTriggeredHigh in + if newDetectionTriggeredHigh != node?.detectionSensorConfig?.detectionTriggeredHigh { hasChanges = true } } - .onChange(of: usePullup) { - if let val = node?.detectionSensorConfig?.usePullup { - hasChanges = $0 != val - } + .onChange(of: usePullup) { _, newUsePullup in + if newUsePullup != node?.detectionSensorConfig?.usePullup { hasChanges = true } } - .onChange(of: name) { newName in - if node != nil && node?.detectionSensorConfig != nil { - if newName != node!.detectionSensorConfig!.name { hasChanges = true } - } + .onChange(of: name) { _, newName in + if newName != node?.detectionSensorConfig?.name ?? "" { hasChanges = true } } - .onChange(of: monitorPin) { newMonitorPin in - if node != nil && node?.detectionSensorConfig != nil { - if newMonitorPin != node!.detectionSensorConfig!.monitorPin { hasChanges = true } - } + .onChange(of: monitorPin) { _, newMonitorPin in + if newMonitorPin != node?.detectionSensorConfig?.monitorPin ?? 0 { hasChanges = true } } - .onChange(of: minimumBroadcastSecs) { newMinimumBroadcastSecs in - if node != nil && node?.detectionSensorConfig != nil { - if newMinimumBroadcastSecs != node!.detectionSensorConfig!.minimumBroadcastSecs { hasChanges = true } - } + .onChange(of: minimumBroadcastSecs) { _, newMinimumBroadcastSecs in + if newMinimumBroadcastSecs != node?.detectionSensorConfig?.minimumBroadcastSecs ?? 0 { hasChanges = true } } - .onChange(of: stateBroadcastSecs) { newStateBroadcastSecs in - if node != nil && node?.detectionSensorConfig != nil { - if newStateBroadcastSecs != node!.detectionSensorConfig!.stateBroadcastSecs { hasChanges = true } - } + .onChange(of: stateBroadcastSecs) { _, newStateBroadcastSecs in + if newStateBroadcastSecs != node?.detectionSensorConfig?.stateBroadcastSecs ?? 0 { hasChanges = true } } - .onChange(of: detectionNotificationsEnabled) { newDetectionNotificationsEnabled in + .onChange(of: detectionNotificationsEnabled) { _, newDetectionNotificationsEnabled in UserDefaults.enableDetectionNotifications = newDetectionNotificationsEnabled } } diff --git a/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift b/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift index 57c3a672..a0f14c7f 100644 --- a/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift @@ -220,80 +220,50 @@ struct ExternalNotificationConfig: View { } } } - .onChange(of: enabled) { - if let val = node?.externalNotificationConfig?.enabled { - hasChanges = $0 != val - } + .onChange(of: enabled) { _, newEnabled in + if newEnabled != node?.externalNotificationConfig?.enabled { hasChanges = true } } - .onChange(of: alertBell) { - if let val = node?.externalNotificationConfig?.alertBell { - hasChanges = $0 != val - } + .onChange(of: alertBell) { _, newAlertBell in + if newAlertBell != node?.externalNotificationConfig?.alertBell { hasChanges = true } } - .onChange(of: alertBellBuzzer) { - if let val = node?.externalNotificationConfig?.alertBellBuzzer { - hasChanges = $0 != val - } + .onChange(of: alertBellBuzzer) { _, newAlertBellBuzzer in + if newAlertBellBuzzer != node?.externalNotificationConfig?.alertBellBuzzer { hasChanges = true } } - .onChange(of: alertBellVibra) { - if let val = node?.externalNotificationConfig?.alertBellVibra { - hasChanges = $0 != val - } + .onChange(of: alertBellVibra) { _, newAlertBellVibra in + if newAlertBellVibra != node?.externalNotificationConfig?.alertBellVibra { hasChanges = true } } - .onChange(of: alertMessage) { - if let val = node?.externalNotificationConfig?.alertMessage { - hasChanges = $0 != val - } + .onChange(of: alertMessage) { _, newAlertMessage in + if newAlertMessage != node?.externalNotificationConfig?.alertMessage { hasChanges = true } } - .onChange(of: alertMessageBuzzer) { - if let val = node?.externalNotificationConfig?.alertMessageBuzzer { - hasChanges = $0 != val - } + .onChange(of: alertMessageBuzzer) { _, newAlertMessageBuzzer in + if newAlertMessageBuzzer != node?.externalNotificationConfig?.alertMessageBuzzer { hasChanges = true } } - .onChange(of: alertMessageVibra) { - if let val = node?.externalNotificationConfig?.alertMessageVibra { - hasChanges = $0 != val - } + .onChange(of: alertMessageVibra) { _, newAlertMessageVibra in + if newAlertMessageVibra != node?.externalNotificationConfig?.alertMessageVibra { hasChanges = true } } - .onChange(of: active) { - if let val = node?.externalNotificationConfig?.active { - hasChanges = $0 != val - } + .onChange(of: active) { _, newActive in + if newActive != node?.externalNotificationConfig?.active { hasChanges = true } } - .onChange(of: output) { newOutput in - if node != nil && node!.externalNotificationConfig != nil { - if newOutput != node!.externalNotificationConfig!.output { hasChanges = true } - } + .onChange(of: output) { _, newOutput in + if newOutput != node?.externalNotificationConfig?.output ?? -1 { hasChanges = true } } - .onChange(of: output) { newOutputBuzzer in - if node != nil && node!.externalNotificationConfig != nil { - if newOutputBuzzer != node!.externalNotificationConfig!.outputBuzzer { hasChanges = true } - } + .onChange(of: output) { _, newOutputBuzzer in + if newOutputBuzzer != node?.externalNotificationConfig?.outputBuzzer ?? -1 { hasChanges = true } } - .onChange(of: output) { newOutputVibra in - if node != nil && node!.externalNotificationConfig != nil { - if newOutputVibra != node!.externalNotificationConfig!.outputVibra { hasChanges = true } - } + .onChange(of: output) { _, newOutputVibra in + if newOutputVibra != node?.externalNotificationConfig?.outputVibra ?? -1 { hasChanges = true } } - .onChange(of: outputMilliseconds) { newOutputMs in - if node != nil && node!.externalNotificationConfig != nil { - if newOutputMs != node!.externalNotificationConfig!.outputMilliseconds { hasChanges = true } - } + .onChange(of: outputMilliseconds) { _, newOutputMs in + if newOutputMs != node?.externalNotificationConfig?.outputMilliseconds ?? -1 { hasChanges = true } } - .onChange(of: usePWM) { - if let val = node?.externalNotificationConfig?.usePWM { - hasChanges = $0 != val - } + .onChange(of: usePWM) { _, newPWM in + if newPWM != node?.externalNotificationConfig?.usePWM { hasChanges = true } } - .onChange(of: nagTimeout) { newNagTimeout in - if node != nil && node!.externalNotificationConfig != nil { - if newNagTimeout != node!.externalNotificationConfig!.nagTimeout { hasChanges = true } - } + .onChange(of: nagTimeout) { _, newNagTimeout in + if newNagTimeout != node?.externalNotificationConfig?.nagTimeout ?? -1 { hasChanges = true } } - .onChange(of: useI2SAsBuzzer) { - if let val = node?.externalNotificationConfig?.useI2SAsBuzzer { - hasChanges = $0 != val - } + .onChange(of: useI2SAsBuzzer) { _, newUseI2SAsBuzzer in + if newUseI2SAsBuzzer != node?.externalNotificationConfig?.useI2SAsBuzzer { hasChanges = true } } } func setExternalNotificationValues() { diff --git a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift index 67bbc248..50eb5806 100644 --- a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift @@ -262,24 +262,20 @@ struct MQTTConfig: View { ) } ) - .onChange(of: enabled) { - if $0 != node?.mqttConfig?.enabled { hasChanges = true } + .onChange(of: enabled) { _, newEnabled in + if newEnabled != node?.mqttConfig?.enabled { hasChanges = true } } - .onChange(of: proxyToClientEnabled) { newProxyToClientEnabled in + .onChange(of: proxyToClientEnabled) { _, newProxyToClientEnabled in if newProxyToClientEnabled { jsonEnabled = false } if newProxyToClientEnabled != node?.mqttConfig?.proxyToClientEnabled { hasChanges = true } } - .onChange(of: address) { newAddress in - if node != nil && node?.mqttConfig != nil { - if newAddress != node!.mqttConfig!.address { hasChanges = true } - } + .onChange(of: address) { _, newAddress in + if newAddress != node?.mqttConfig?.address ?? "" { hasChanges = true } } .onChange(of: username) { newUsername in - if node != nil && node?.mqttConfig != nil { - if newUsername != node!.mqttConfig!.username { hasChanges = true } - } + if newUsername != node?.mqttConfig?.username ?? "" { hasChanges = true } } .onChange(of: password) { newPassword in if node != nil && node?.mqttConfig != nil { @@ -291,26 +287,26 @@ struct MQTTConfig: View { if newRoot != node!.mqttConfig!.root { hasChanges = true } } } - .onChange(of: selectedTopic) { newSelectedTopic in + .onChange(of: selectedTopic) { _, newSelectedTopic in root = newSelectedTopic } - .onChange(of: encryptionEnabled) { - if $0 != node?.mqttConfig?.encryptionEnabled { hasChanges = true } + .onChange(of: encryptionEnabled) { _, newEncryptionEnabled in + if newEncryptionEnabled != node?.mqttConfig?.encryptionEnabled { hasChanges = true } } - .onChange(of: jsonEnabled) { newJsonEnabled in + .onChange(of: jsonEnabled) { _, newJsonEnabled in if newJsonEnabled { proxyToClientEnabled = false } if newJsonEnabled != node?.mqttConfig?.jsonEnabled { hasChanges = true } } - .onChange(of: tlsEnabled) { newTlsEnabled in + .onChange(of: tlsEnabled) { _, newTlsEnabled in if address.lowercased() == "mqtt.meshtastic.org" { tlsEnabled = false } else { if newTlsEnabled != node?.mqttConfig?.tlsEnabled { hasChanges = true } } } - .onChange(of: mqttConnected) { newMqttConnected in + .onChange(of: mqttConnected) { _, newMqttConnected in if newMqttConnected == false { if bleManager.mqttProxyConnected { bleManager.mqttManager.disconnect() @@ -321,8 +317,8 @@ struct MQTTConfig: View { } } } - .onChange(of: mapReportingEnabled) { - if $0 != node?.mqttConfig?.mapReportingEnabled { hasChanges = true } + .onChange(of: mapReportingEnabled) { _, newMapReportingEnabled in + if newMapReportingEnabled != node?.mqttConfig?.mapReportingEnabled { hasChanges = true } } .onChange(of: mapPublishIntervalSecs) { newMapPublishIntervalSecs in if node != nil && node?.mqttConfig != nil { diff --git a/Meshtastic/Views/Settings/Config/Module/RangeTestConfig.swift b/Meshtastic/Views/Settings/Config/Module/RangeTestConfig.swift index 872294d8..ae4797fc 100644 --- a/Meshtastic/Views/Settings/Config/Module/RangeTestConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/RangeTestConfig.swift @@ -102,14 +102,14 @@ struct RangeTestConfig: View { } } } - .onChange(of: enabled) { - if $0 != node?.rangeTestConfig?.enabled { hasChanges = true } + .onChange(of: enabled) { _, newEnabled in + if newEnabled != node?.rangeTestConfig?.enabled { hasChanges = true } } - .onChange(of: save) { - if $0 != node?.rangeTestConfig?.save { hasChanges = true } + .onChange(of: save) { _, newSave in + if newSave != node?.rangeTestConfig?.save { hasChanges = true } } - .onChange(of: sender) { - if $0 != node?.rangeTestConfig?.sender ?? -1 { hasChanges = true } + .onChange(of: sender) { _, newSender in + if newSender != node?.rangeTestConfig?.sender ?? -1 { hasChanges = true } } } } diff --git a/Meshtastic/Views/Settings/Config/Module/RtttlConfig.swift b/Meshtastic/Views/Settings/Config/Module/RtttlConfig.swift index 772b6b98..2e0931a7 100644 --- a/Meshtastic/Views/Settings/Config/Module/RtttlConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/RtttlConfig.swift @@ -31,14 +31,14 @@ struct RtttlConfig: View { .foregroundColor(.gray) .autocapitalization(.none) .disableAutocorrection(true) - .onChange(of: ringtone, perform: { _ in + .onChange(of: ringtone) { var totalBytes = ringtone.utf8.count // Only mess with the value if it is too big while totalBytes > 228 { ringtone = String(ringtone.dropLast()) totalBytes = ringtone.utf8.count } - }) + } .foregroundColor(.gray) } .keyboardType(.default) @@ -93,7 +93,7 @@ struct RtttlConfig: View { } } } - .onChange(of: ringtone) { newRingtone in + .onChange(of: ringtone) { _, newRingtone in if node != nil && node!.rtttlConfig != nil { if newRingtone != node!.rtttlConfig!.ringtone { hasChanges = true } } diff --git a/Meshtastic/Views/Settings/Config/NetworkConfig.swift b/Meshtastic/Views/Settings/Config/NetworkConfig.swift index b79740e2..8cebde85 100644 --- a/Meshtastic/Views/Settings/Config/NetworkConfig.swift +++ b/Meshtastic/Views/Settings/Config/NetworkConfig.swift @@ -151,8 +151,8 @@ struct NetworkConfig: View { } } } - .onChange(of: wifiEnabled) { - if $0 != node?.networkConfig?.wifiEnabled { hasChanges = true } + .onChange(of: wifiEnabled) { _, newEnabled in + if newEnabled != node?.networkConfig?.wifiEnabled { hasChanges = true } } .onChange(of: wifiSsid) { _, newSSID in if newSSID != node?.networkConfig?.wifiSsid { hasChanges = true } @@ -160,11 +160,11 @@ struct NetworkConfig: View { .onChange(of: wifiPsk) { _, newPsk in if newPsk != node?.networkConfig?.wifiPsk { hasChanges = true } } - .onChange(of: wifiMode) { - if $0 != node?.networkConfig?.wifiMode ?? -1 { hasChanges = true } + .onChange(of: wifiMode) { _, newMode in + if newMode != node?.networkConfig?.wifiMode ?? -1 { hasChanges = true } } - .onChange(of: ethEnabled) { - if $0 != node?.networkConfig?.ethEnabled { hasChanges = true } + .onChange(of: ethEnabled) { _, newEthEnabled in + if newEthEnabled != node?.networkConfig?.ethEnabled { hasChanges = true } } } func setNetworkValues() { diff --git a/Meshtastic/Views/Settings/Config/PositionConfig.swift b/Meshtastic/Views/Settings/Config/PositionConfig.swift index 541146cc..fe61d1fa 100644 --- a/Meshtastic/Views/Settings/Config/PositionConfig.swift +++ b/Meshtastic/Views/Settings/Config/PositionConfig.swift @@ -411,37 +411,37 @@ struct PositionConfig: View { } } } - .onChange(of: gpsMode) { newGpsMode in + .onChange(of: gpsMode) { _, newGpsMode in if newGpsMode != node?.positionConfig?.gpsMode ?? 0 { hasChanges = true } } - .onChange(of: rxGpio) { newRxGpio in + .onChange(of: rxGpio) { _, newRxGpio in if newRxGpio != node?.positionConfig?.rxGpio ?? 0 { hasChanges = true } } - .onChange(of: txGpio) { newTxGpio in + .onChange(of: txGpio) { _, newTxGpio in if newTxGpio != node?.positionConfig?.txGpio ?? 0 { hasChanges = true } } - .onChange(of: gpsEnGpio) { newGpsEnGpio in + .onChange(of: gpsEnGpio) { _, newGpsEnGpio in if newGpsEnGpio != node?.positionConfig?.gpsEnGpio ?? 0 { hasChanges = true } } - .onChange(of: smartPositionEnabled) { newSmartPositionEnabled in + .onChange(of: smartPositionEnabled) { _, newSmartPositionEnabled in if newSmartPositionEnabled != node?.positionConfig?.smartPositionEnabled { hasChanges = true } } - .onChange(of: positionBroadcastSeconds) { newPositionBroadcastSeconds in + .onChange(of: positionBroadcastSeconds) { _, newPositionBroadcastSeconds in if newPositionBroadcastSeconds != node?.positionConfig?.positionBroadcastSeconds ?? 0 { hasChanges = true } } - .onChange(of: broadcastSmartMinimumIntervalSecs) { newBroadcastSmartMinimumIntervalSecs in + .onChange(of: broadcastSmartMinimumIntervalSecs) { _, newBroadcastSmartMinimumIntervalSecs in if newBroadcastSmartMinimumIntervalSecs != node?.positionConfig?.broadcastSmartMinimumIntervalSecs ?? 0 { hasChanges = true } } - .onChange(of: broadcastSmartMinimumDistance) { newBroadcastSmartMinimumDistance in + .onChange(of: broadcastSmartMinimumDistance) { _, newBroadcastSmartMinimumDistance in if newBroadcastSmartMinimumDistance != node?.positionConfig?.broadcastSmartMinimumDistance ?? 0 { hasChanges = true } } - .onChange(of: gpsUpdateInterval) { newGpsUpdateInterval in + .onChange(of: gpsUpdateInterval) { _, newGpsUpdateInterval in if newGpsUpdateInterval != node?.positionConfig?.gpsUpdateInterval ?? 0 { hasChanges = true } } } func handlePositionFlagtChanges() { - guard let positionConfig = node?.positionConfig else { return } + guard (node?.positionConfig) != nil else { return } let pf = PositionFlags(rawValue: self.positionFlags) hasChanges = pf.contains(.Altitude) || diff --git a/Meshtastic/Views/Settings/Config/PowerConfig.swift b/Meshtastic/Views/Settings/Config/PowerConfig.swift index b50368ab..822fd1e0 100644 --- a/Meshtastic/Views/Settings/Config/PowerConfig.swift +++ b/Meshtastic/Views/Settings/Config/PowerConfig.swift @@ -168,11 +168,11 @@ struct PowerConfig: View { .onChange(of: waitBluetoothSecs) { oldWaitBluetoothSecs, newWaitBluetoothSecs in if oldWaitBluetoothSecs != newWaitBluetoothSecs && newWaitBluetoothSecs != node?.powerConfig?.waitBluetoothSecs ?? -1 { hasChanges = true } } - .onChange(of: lsSecs) { - if $0 != node?.powerConfig?.lsSecs ?? -1 { hasChanges = true } + .onChange(of: lsSecs) { _, newLsSecs in + if newLsSecs != node?.powerConfig?.lsSecs ?? -1 { hasChanges = true } } - .onChange(of: minWakeSecs) { - if $0 != node?.powerConfig?.minWakeSecs ?? -1 { hasChanges = true } + .onChange(of: minWakeSecs) { _, newMinWakeSecs in + if newMinWakeSecs != node?.powerConfig?.minWakeSecs ?? -1 { hasChanges = true } } SaveConfigButton(node: node, hasChanges: $hasChanges) { diff --git a/Meshtastic/Views/Settings/Config/SecurityConfig.swift b/Meshtastic/Views/Settings/Config/SecurityConfig.swift index c7abe54b..75b69463 100644 --- a/Meshtastic/Views/Settings/Config/SecurityConfig.swift +++ b/Meshtastic/Views/Settings/Config/SecurityConfig.swift @@ -106,17 +106,17 @@ struct SecurityConfig: View { name: "\(bleManager.connectedPeripheral?.shortName ?? "?")" ) }) - .onChange(of: isManaged) { - if $0 != node?.securityConfig?.isManaged { hasChanges = true } + .onChange(of: isManaged) { _, newIsManaged in + if newIsManaged != node?.securityConfig?.isManaged { hasChanges = true } } - .onChange(of: serialEnabled) { - if $0 != node?.securityConfig?.serialEnabled { hasChanges = true } + .onChange(of: serialEnabled) { _, newSerialEnabled in + if newSerialEnabled != node?.securityConfig?.serialEnabled { hasChanges = true } } - .onChange(of: debugLogApiEnabled) { - if $0 != node?.securityConfig?.debugLogApiEnabled { hasChanges = true } + .onChange(of: debugLogApiEnabled) { _, newDebugLogApiEnabled in + if newDebugLogApiEnabled != node?.securityConfig?.debugLogApiEnabled { hasChanges = true } } - .onChange(of: adminChannelEnabled) { - if $0 != node?.securityConfig?.adminChannelEnabled { hasChanges = true } + .onChange(of: adminChannelEnabled) { _, newAdminChannelEnabled in + if newAdminChannelEnabled != node?.securityConfig?.adminChannelEnabled { hasChanges = true } } .onChange(of: publicKey) { let tempKey = Data(base64Encoded: publicKey) ?? Data()