From 09bd3059d7c7502ad521a3f1dee26d6e3df9f86d Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 22 Sep 2024 07:49:55 -0700 Subject: [PATCH 1/3] Imporoved length validation --- Meshtastic/Extensions/String.swift | 1 - .../Views/Messages/TextMessageField/TextMessageField.swift | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Meshtastic/Extensions/String.swift b/Meshtastic/Extensions/String.swift index 6255b151b..4e840a98f 100644 --- a/Meshtastic/Extensions/String.swift +++ b/Meshtastic/Extensions/String.swift @@ -91,5 +91,4 @@ extension String { let end = index(start, offsetBy: range.upperBound - range.lowerBound) return String(self[start ..< end]) } - } diff --git a/Meshtastic/Views/Messages/TextMessageField/TextMessageField.swift b/Meshtastic/Views/Messages/TextMessageField/TextMessageField.swift index 12b72ae96..7aded0f15 100644 --- a/Meshtastic/Views/Messages/TextMessageField/TextMessageField.swift +++ b/Meshtastic/Views/Messages/TextMessageField/TextMessageField.swift @@ -33,8 +33,9 @@ struct TextMessageField: View { .onChange(of: typingMessage, perform: { value in totalBytes = value.utf8.count // Only mess with the value if it is too big - if totalBytes > Self.maxbytes { + while totalBytes > Self.maxbytes { typingMessage = String(typingMessage.dropLast()) + totalBytes = typingMessage.utf8.count } }) .keyboardType(.default) From 25143ddf755487e2516937769c5c2951d1330703 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 22 Sep 2024 08:03:18 -0700 Subject: [PATCH 2/3] while --- .../Views/MapKitMap/WaypointFormMapKit.swift | 11 ++++++--- .../Nodes/Helpers/Map/WaypointForm.swift | 10 ++++---- .../Views/Settings/Channels/ChannelForm.swift | 5 ++-- .../Views/Settings/Config/DeviceConfig.swift | 6 ++--- .../Config/Module/CannedMessagesConfig.swift | 5 ++-- .../Config/Module/DetectionSensorConfig.swift | 6 ++--- .../Settings/Config/Module/MQTTConfig.swift | 23 ++++++++++--------- .../Settings/Config/Module/RtttlConfig.swift | 6 ++--- .../Views/Settings/Config/NetworkConfig.swift | 10 ++++---- Meshtastic/Views/Settings/Routes.swift | 6 ++--- Meshtastic/Views/Settings/UserConfig.swift | 8 ++++--- 11 files changed, 55 insertions(+), 41 deletions(-) diff --git a/Meshtastic/Views/MapKitMap/WaypointFormMapKit.swift b/Meshtastic/Views/MapKitMap/WaypointFormMapKit.swift index d5fd9c013..5fc5e2f42 100644 --- a/Meshtastic/Views/MapKitMap/WaypointFormMapKit.swift +++ b/Meshtastic/Views/MapKitMap/WaypointFormMapKit.swift @@ -52,8 +52,12 @@ struct WaypointFormMapKit: View { ) .foregroundColor(Color.gray) .onChange(of: name, perform: { _ in - let totalBytes = name.utf8.count + var totalBytes = name.utf8.count // Only mess with the value if it is too big + while totalBytes > 30 { + name = String(name.dropLast()) + totalBytes = name.utf8.count + } if totalBytes > 30 { name = String(name.dropLast()) } @@ -69,10 +73,11 @@ struct WaypointFormMapKit: View { ) .foregroundColor(Color.gray) .onChange(of: description, perform: { _ in - let totalBytes = description.utf8.count + var totalBytes = description.utf8.count // Only mess with the value if it is too big - if totalBytes > 100 { + while totalBytes > 100 { description = String(description.dropLast()) + totalBytes = description.utf8.count } }) } diff --git a/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift b/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift index 35916eb68..4261b0ccb 100644 --- a/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift +++ b/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift @@ -66,10 +66,11 @@ struct WaypointForm: View { ) .foregroundColor(Color.gray) .onChange(of: name, perform: { _ in - let totalBytes = name.utf8.count + var totalBytes = name.utf8.count // Only mess with the value if it is too big - if totalBytes > 30 { + while totalBytes > 30 { name = String(name.dropLast()) + totalBytes = name.utf8.count } }) } @@ -83,10 +84,11 @@ struct WaypointForm: View { ) .foregroundColor(Color.gray) .onChange(of: description, perform: { _ in - let totalBytes = description.utf8.count + var totalBytes = description.utf8.count // Only mess with the value if it is too big - if totalBytes > 100 { + while totalBytes > 100 { description = String(description.dropLast()) + totalBytes = description.utf8.count } }) } diff --git a/Meshtastic/Views/Settings/Channels/ChannelForm.swift b/Meshtastic/Views/Settings/Channels/ChannelForm.swift index e4930b7a4..72e17cef1 100644 --- a/Meshtastic/Views/Settings/Channels/ChannelForm.swift +++ b/Meshtastic/Views/Settings/Channels/ChannelForm.swift @@ -43,10 +43,11 @@ struct ChannelForm: View { .foregroundColor(Color.gray) .onChange(of: channelName, perform: { _ in channelName = channelName.replacing(" ", with: "") - let totalBytes = channelName.utf8.count + var totalBytes = channelName.utf8.count // Only mess with the value if it is too big - if totalBytes > 11 { + while totalBytes > 11 { channelName = String(channelName.dropLast()) + totalBytes = channelName.utf8.count } hasChanges = true }) diff --git a/Meshtastic/Views/Settings/Config/DeviceConfig.swift b/Meshtastic/Views/Settings/Config/DeviceConfig.swift index c78cb8458..f9efd066a 100644 --- a/Meshtastic/Views/Settings/Config/DeviceConfig.swift +++ b/Meshtastic/Views/Settings/Config/DeviceConfig.swift @@ -94,14 +94,14 @@ struct DeviceConfig: View { TextField("Time Zone", text: $tzdef, axis: .vertical) .foregroundColor(.gray) .onChange(of: tzdef, perform: { _ in - let totalBytes = tzdef.utf8.count + var totalBytes = tzdef.utf8.count // Only mess with the value if it is too big - if totalBytes > 63 { + while totalBytes > 63 { tzdef = String(tzdef.dropLast()) + totalBytes = tzdef.utf8.count } }) .foregroundColor(.gray) - } .keyboardType(.default) .disableAutocorrection(true) diff --git a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift index 5b94e8c31..568be9da4 100644 --- a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift @@ -73,10 +73,11 @@ struct CannedMessagesConfig: View { .disableAutocorrection(true) .onChange(of: messages, perform: { _ in - let totalBytes = messages.utf8.count + var totalBytes = messages.utf8.count // Only mess with the value if it is too big - if totalBytes > 198 { + while totalBytes > 198 { messages = String(messages.dropLast()) + totalBytes = messages.utf8.count } hasMessagesChanges = true }) diff --git a/Meshtastic/Views/Settings/Config/Module/DetectionSensorConfig.swift b/Meshtastic/Views/Settings/Config/Module/DetectionSensorConfig.swift index e67898ebb..6305dd988 100644 --- a/Meshtastic/Views/Settings/Config/Module/DetectionSensorConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/DetectionSensorConfig.swift @@ -92,11 +92,11 @@ struct DetectionSensorConfig: View { .autocapitalization(.none) .disableAutocorrection(true) .onChange(of: name, perform: { _ in - - let totalBytes = name.utf8.count + var totalBytes = name.utf8.count // Only mess with the value if it is too big - if totalBytes > 20 { + while totalBytes > 20 { name = String(name.dropLast()) + totalBytes = name.utf8.count } }) } diff --git a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift index 1996c7440..6b39b6496 100644 --- a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift @@ -124,10 +124,11 @@ struct MQTTConfig: View { TextField("Root Topic", text: $root) .foregroundColor(.gray) .onChange(of: root, perform: { _ in - let totalBytes = root.utf8.count + var totalBytes = root.utf8.count // Only mess with the value if it is too big - if totalBytes > 30 { + while totalBytes > 30 { root = String(root.dropLast()) + totalBytes = root.utf8.count } }) .foregroundColor(.gray) @@ -162,10 +163,11 @@ struct MQTTConfig: View { .autocapitalization(.none) .disableAutocorrection(true) .onChange(of: address, perform: { _ in - let totalBytes = address.utf8.count + var totalBytes = address.utf8.count // Only mess with the value if it is too big - if totalBytes > 62 { + while totalBytes > 62 { address = String(address.dropLast()) + totalBytes = address.utf8.count } hasChanges = true }) @@ -180,12 +182,11 @@ struct MQTTConfig: View { .autocapitalization(.none) .disableAutocorrection(true) .onChange(of: username, perform: { _ in - - let totalBytes = username.utf8.count - + var totalBytes = username.utf8.count // Only mess with the value if it is too big - if totalBytes > 62 { + while totalBytes > 62 { username = String(username.dropLast()) + totalBytes = username.utf8.count } hasChanges = true }) @@ -200,11 +201,11 @@ struct MQTTConfig: View { .autocapitalization(.none) .disableAutocorrection(true) .onChange(of: password, perform: { _ in - - let totalBytes = password.utf8.count + var totalBytes = password.utf8.count // Only mess with the value if it is too big - if totalBytes > 62 { + while totalBytes > 62 { password = String(password.dropLast()) + totalBytes = password.utf8.count } hasChanges = true }) diff --git a/Meshtastic/Views/Settings/Config/Module/RtttlConfig.swift b/Meshtastic/Views/Settings/Config/Module/RtttlConfig.swift index 46b02848a..772b6b98d 100644 --- a/Meshtastic/Views/Settings/Config/Module/RtttlConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/RtttlConfig.swift @@ -32,11 +32,11 @@ struct RtttlConfig: View { .autocapitalization(.none) .disableAutocorrection(true) .onChange(of: ringtone, perform: { _ in - - let totalBytes = ringtone.utf8.count + var totalBytes = ringtone.utf8.count // Only mess with the value if it is too big - if totalBytes > 228 { + while totalBytes > 228 { ringtone = String(ringtone.dropLast()) + totalBytes = ringtone.utf8.count } }) .foregroundColor(.gray) diff --git a/Meshtastic/Views/Settings/Config/NetworkConfig.swift b/Meshtastic/Views/Settings/Config/NetworkConfig.swift index 928bad579..198ad1a07 100644 --- a/Meshtastic/Views/Settings/Config/NetworkConfig.swift +++ b/Meshtastic/Views/Settings/Config/NetworkConfig.swift @@ -46,10 +46,11 @@ struct NetworkConfig: View { .autocapitalization(.none) .disableAutocorrection(true) .onChange(of: wifiSsid, perform: { _ in - let totalBytes = wifiSsid.utf8.count + var totalBytes = wifiSsid.utf8.count // Only mess with the value if it is too big - if totalBytes > 32 { + while totalBytes > 32 { wifiSsid = String(wifiSsid.dropLast()) + totalBytes = wifiSsid.utf8.count } hasChanges = true }) @@ -63,10 +64,11 @@ struct NetworkConfig: View { .autocapitalization(.none) .disableAutocorrection(true) .onChange(of: wifiPsk, perform: { _ in - let totalBytes = wifiPsk.utf8.count + var totalBytes = wifiPsk.utf8.count // Only mess with the value if it is too big - if totalBytes > 63 { + while totalBytes > 63 { wifiPsk = String(wifiPsk.dropLast()) + totalBytes = wifiPsk.utf8.count } hasChanges = true }) diff --git a/Meshtastic/Views/Settings/Routes.swift b/Meshtastic/Views/Settings/Routes.swift index 65be4fd31..314497e80 100644 --- a/Meshtastic/Views/Settings/Routes.swift +++ b/Meshtastic/Views/Settings/Routes.swift @@ -177,11 +177,11 @@ struct Routes: View { ) .foregroundColor(Color.gray) .onChange(of: name, perform: { _ in - let totalBytes = name.utf8.count + var totalBytes = name.utf8.count // Only mess with the value if it is too big - - if totalBytes > 100 { + while totalBytes > 100 { name = String(name.dropLast()) + totalBytes = name.utf8.count } }) diff --git a/Meshtastic/Views/Settings/UserConfig.swift b/Meshtastic/Views/Settings/UserConfig.swift index c67c70bfa..72084954c 100644 --- a/Meshtastic/Views/Settings/UserConfig.swift +++ b/Meshtastic/Views/Settings/UserConfig.swift @@ -50,10 +50,11 @@ struct UserConfig: View { TextField("Long Name", text: $longName) .onChange(of: longName, perform: { _ in - let totalBytes = longName.utf8.count + var totalBytes = longName.utf8.count // Only mess with the value if it is too big - if totalBytes > (isLicensed ? 6 : 36) { + while totalBytes > (isLicensed ? 6 : 36) { longName = String(longName.dropLast()) + totalBytes = longName.utf8.count } }) } @@ -74,10 +75,11 @@ struct UserConfig: View { TextField("Short Name", text: $shortName) .foregroundColor(.gray) .onChange(of: shortName, perform: { _ in - let totalBytes = shortName.utf8.count + var totalBytes = shortName.utf8.count // Only mess with the value if it is too big if totalBytes > 4 { shortName = String(shortName.dropLast()) + totalBytes = shortName.utf8.count } }) .foregroundColor(.gray) From 2f7b087ff2ee9c5f20484fd46ac0054b26be60ec Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 22 Sep 2024 08:20:51 -0700 Subject: [PATCH 3/3] Remove local stats from bluetooth connect view as they don't update --- Localizable.xcstrings | 33 ------------------ Meshtastic/Views/Bluetooth/Connect.swift | 43 ------------------------ 2 files changed, 76 deletions(-) diff --git a/Localizable.xcstrings b/Localizable.xcstrings index 0ea544547..9650f2ca9 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -140,16 +140,6 @@ }, "%@%%" : { - }, - "%@%% %@%%" : { - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "new", - "value" : "%1$@%% %2$@%%" - } - } - } }, "%@°F" : { @@ -1428,16 +1418,6 @@ }, "Bad" : { - }, - "Bad Packets: %d %@%%" : { - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "new", - "value" : "Bad Packets: %1$d %2$@%%" - } - } - } }, "Bandwidth" : { @@ -16085,16 +16065,6 @@ }, "Override automatic OLED screen detection." : { - }, - "Packets: Sent: %d Received: %d" : { - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "new", - "value" : "Packets: Sent: %1$d Received: %2$d" - } - } - } }, "password" : { "localizations" : { @@ -22325,9 +22295,6 @@ } } } - }, - "Uptime: %@" : { - }, "Use a PWM output (like the RAK Buzzer) for tunes instead of an on/off output. This will ignore the output, output duration and active settings and use the device config buzzer GPIO option instead." : { diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index 911bf10ef..f7aaa7383 100644 --- a/Meshtastic/Views/Bluetooth/Connect.swift +++ b/Meshtastic/Views/Bluetooth/Connect.swift @@ -27,7 +27,6 @@ struct Connect: View { @State var invalidFirmwareVersion = false @State var liveActivityStarted = false @State var selectedPeripherialId = "" - @State var localStats: TelemetryEntity? init () { let notificationCenter = UNUserNotificationCenter.current() @@ -91,45 +90,6 @@ struct Connect: View { } } } - VStack { - if localStats != nil { - Divider() - if localStats?.numTotalNodes ?? 0 >= 100 { - Text("\(String(format: "Connected: %d nodes online", localStats?.numOnlineNodes ?? 0))") - .font(.callout) - .fontWeight(.medium) - .foregroundStyle(.secondary) - .fixedSize() - } else { - Text("\(String(format: "Connected: %d of %d nodes online", localStats?.numOnlineNodes ?? 0, localStats?.numTotalNodes ?? 0))") - .font(.callout) - .fontWeight(.medium) - .foregroundStyle(.secondary) - .fixedSize() - } - Text("\(String(format: "Ch. Util: %.2f", localStats?.channelUtilization ?? 0))% \(String(format: "Airtime: %.2f", localStats?.airUtilTx ?? 0))%") - .font(.caption) - .fontWeight(.medium) - .foregroundStyle(.secondary) - Text("Packets: Sent: \(localStats?.numPacketsTx ?? 0) Received: \(localStats?.numPacketsRx ?? 0)") - .font(.caption) - .fontWeight(.medium) - .foregroundStyle(.secondary) - let errorRate = (Double(localStats?.numPacketsRxBad ?? -1) / Double(localStats?.numPacketsRx ?? -1)) * 100 - Text("Bad Packets: \(localStats?.numPacketsRxBad ?? 0) \(String(format: "Error Rate: %.2f", errorRate))%") - .font(.caption) - .fontWeight(.medium) - .foregroundStyle(.secondary) - .fixedSize() - let now = Date.now - let later = now + TimeInterval(Double(localStats?.numPacketsRxBad ?? 0)) - let uptime = (now.. 0 && sub {