From 70340fa18f974db4671158ee63d0227a5bf4bc62 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 24 May 2025 00:33:27 -0700 Subject: [PATCH] Fix some linting and ben writing C# warnings --- .../AppIntents/DisconnectNodeIntent.swift | 1 - Meshtastic/AppIntents/ShortcutsProvider.swift | 1 - Meshtastic/Extensions/UserDefaults.swift | 2 +- Meshtastic/Helpers/BLEManager.swift | 5 ----- Meshtastic/Helpers/LocationsHandler.swift | 1 - Meshtastic/Helpers/MeshPackets.swift | 1 - Meshtastic/MeshtasticApp.swift | 17 ++++++++--------- Meshtastic/Views/Helpers/BatteryCompact.swift | 5 +---- .../Views/Helpers/LoRaSignalStrength.swift | 1 - Meshtastic/Views/Messages/UserMessageList.swift | 3 +-- Meshtastic/Views/Nodes/NodeList.swift | 1 - .../Views/Settings/Config/LoRaConfig.swift | 1 - Meshtastic/Views/Settings/UserConfig.swift | 2 +- 13 files changed, 12 insertions(+), 29 deletions(-) diff --git a/Meshtastic/AppIntents/DisconnectNodeIntent.swift b/Meshtastic/AppIntents/DisconnectNodeIntent.swift index 2e9986d0..4f3b4b33 100644 --- a/Meshtastic/AppIntents/DisconnectNodeIntent.swift +++ b/Meshtastic/AppIntents/DisconnectNodeIntent.swift @@ -13,7 +13,6 @@ struct DisconnectNodeIntent: AppIntent { static var description: IntentDescription = "Disconnect the currently connected node" - func perform() async throws -> some IntentResult { if !BLEManager.shared.isConnected { throw AppIntentErrors.AppIntentError.notConnected diff --git a/Meshtastic/AppIntents/ShortcutsProvider.swift b/Meshtastic/AppIntents/ShortcutsProvider.swift index fcc9ffec..d87c06b1 100644 --- a/Meshtastic/AppIntents/ShortcutsProvider.swift +++ b/Meshtastic/AppIntents/ShortcutsProvider.swift @@ -32,7 +32,6 @@ struct ShortcutsProvider: AppShortcutsProvider { "Send a \(.applicationName) group message"], shortTitle: "Group Message", systemImageName: "message") - AppShortcut(intent: DisconnectNodeIntent(), phrases: ["Disconnect \(.applicationName) node", "Disconnect my \(.applicationName) node", diff --git a/Meshtastic/Extensions/UserDefaults.swift b/Meshtastic/Extensions/UserDefaults.swift index 71313597..11539ab2 100644 --- a/Meshtastic/Extensions/UserDefaults.swift +++ b/Meshtastic/Extensions/UserDefaults.swift @@ -119,7 +119,7 @@ extension UserDefaults { @UserDefault(.enableMapPointsOfInterest, defaultValue: false) static var enableMapPointsOfInterest: Bool - + @UserDefault(.enableMapShowFavorites, defaultValue: false) static var enableMapShowFavorites: Bool diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 5fa57408..050958e0 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -181,11 +181,9 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate DispatchQueue.main.async { [weak self] in guard let self = self else { return } guard let connectedPeripheral = self.connectedPeripheral else { return } - if self.mqttProxyConnected { self.mqttManager.mqttClientProxy?.disconnect() } - self.automaticallyReconnect = reconnect self.centralManager?.cancelPeripheralConnection(connectedPeripheral.peripheral) self.FROMRADIO_characteristic = nil @@ -1810,13 +1808,11 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate if let nodeInfoData = try? contact.user.serializedData() { dataNodeMessage.payload = nodeInfoData dataNodeMessage.portnum = PortNum.nodeinfoApp - var nodeMeshPacket = MeshPacket() nodeMeshPacket.id = UInt32.random(in: UInt32(UInt8.max).. Int64 { var adminPacket = AdminMessage() adminPacket.setOwner = config diff --git a/Meshtastic/Helpers/LocationsHandler.swift b/Meshtastic/Helpers/LocationsHandler.swift index f7166f70..15bb390a 100644 --- a/Meshtastic/Helpers/LocationsHandler.swift +++ b/Meshtastic/Helpers/LocationsHandler.swift @@ -142,7 +142,6 @@ import CoreData Logger.services.info("📍 [App] Falling back to last known location (age: \(Int(Date().timeIntervalSince1970 - timestamp)) seconds)") return CLLocationCoordinate2D(latitude: lat, longitude: lon) } - // Fallback 2: Default location Logger.services.warning("📍 [App] No Location and no last known location, something is really wrong. Teleporting user to Apple Park") return DefaultLocation diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index fbf64ab9..fe290aa0 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -1058,7 +1058,6 @@ func textMessageAppPacket( } } - func waypointPacket (packet: MeshPacket, context: NSManagedObjectContext) { let logString = String.localizedStringWithFormat("Waypoint Packet received from node: %@".localized, String(packet.from)) diff --git a/Meshtastic/MeshtasticApp.swift b/Meshtastic/MeshtasticApp.swift index 9e763aed..57605580 100644 --- a/Meshtastic/MeshtasticApp.swift +++ b/Meshtastic/MeshtasticApp.swift @@ -61,10 +61,9 @@ struct MeshtasticAppleApp: App { Logger.mesh.debug("URL received \(userActivity, privacy: .public)") self.incomingUrl = userActivity.webpageURL self.saveChannels = false - if (self.incomingUrl?.absoluteString.lowercased().contains("meshtastic.org/v/#") == true) { + if self.incomingUrl?.absoluteString.lowercased().contains("meshtastic.org/v/#") == true { handleContactUrl(url: self.incomingUrl!) - } - else if (self.incomingUrl?.absoluteString.lowercased().contains("meshtastic.org/e/#") == true) { + } else if self.incomingUrl?.absoluteString.lowercased().contains("meshtastic.org/e/#") == true { if let components = self.incomingUrl?.absoluteString.components(separatedBy: "#") { self.addChannels = Bool(self.incomingUrl?["add"] ?? "false") ?? false if (self.incomingUrl?.absoluteString.lowercased().contains("?")) != nil { @@ -153,19 +152,19 @@ struct MeshtasticAppleApp: App { let components = self.incomingUrl?.absoluteString.components(separatedBy: "#") ?? [] // Extract contact information from the URL if let contactData = components.last { - + let decodedString = contactData.base64urlToBase64() if let decodedData = Data(base64Encoded: decodedString) { do { let contact = try MeshtasticProtobufs.SharedContact(serializedBytes: decodedData) - + // Show an alert to confirm adding the contact let alertController = UIAlertController( title: "Add Contact", message: "Would you like to add \(contact.user.longName) as a contact?", preferredStyle: .alert ) - + alertController.addAction(UIAlertAction( title: "Yes", style: .default, @@ -174,13 +173,13 @@ struct MeshtasticAppleApp: App { Logger.services.debug("Contact added from URL: \(success ? "success" : "failed")") } )) - + alertController.addAction(UIAlertAction( title: "No", style: .cancel, handler: nil )) - + // Present the alert if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, let rootViewController = windowScene.windows.first?.rootViewController { @@ -189,7 +188,7 @@ struct MeshtasticAppleApp: App { Logger.services.debug("Contact data extracted from URL: \(contactData, privacy: .public)") } catch { Logger.services.error("Failed to parse contact data: \(error.localizedDescription, privacy: .public)") - + // Show error alert to user if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, let rootViewController = windowScene.windows.first?.rootViewController { diff --git a/Meshtastic/Views/Helpers/BatteryCompact.swift b/Meshtastic/Views/Helpers/BatteryCompact.swift index f2142534..f04a5c99 100644 --- a/Meshtastic/Views/Helpers/BatteryCompact.swift +++ b/Meshtastic/Views/Helpers/BatteryCompact.swift @@ -19,7 +19,6 @@ struct BatteryCompact: View { // Check for plugged in state let isPluggedIn = batteryLevel > 100 let isCharging = batteryLevel == 100 - // Battery icon selection based on level if isPluggedIn { Image(systemName: "powerplug") @@ -64,7 +63,6 @@ struct BatteryCompact: View { .symbolRenderingMode(.multicolor) .accessibilityHidden(true) } - // Battery text label if isPluggedIn { Text("PWD") @@ -89,7 +87,6 @@ struct BatteryCompact: View { .foregroundColor(color) .symbolRenderingMode(.multicolor) .accessibilityHidden(true) - Text(verbatim: "?") .foregroundStyle(.secondary) .font(font) @@ -100,7 +97,7 @@ struct BatteryCompact: View { .accessibilityElement(children: .ignore) .accessibilityLabel(NSLocalizedString("Battery Level", comment: "VoiceOver label for battery gauge")) // Set appropriate value based on the battery state using a computed property - .accessibilityValue(batteryLevel.map { level in + .accessibilityValue(batteryLevel.map { level in if level > 100 { // Plugged in - same as PWD visual indicator return "Plugged in".localized diff --git a/Meshtastic/Views/Helpers/LoRaSignalStrength.swift b/Meshtastic/Views/Helpers/LoRaSignalStrength.swift index b58e8987..2a8fc3e7 100644 --- a/Meshtastic/Views/Helpers/LoRaSignalStrength.swift +++ b/Meshtastic/Views/Helpers/LoRaSignalStrength.swift @@ -65,7 +65,6 @@ struct LoRaSignalStrengthMeter_Previews: PreviewProvider { LoRaSignalStrengthMeter(snr: -26.0, rssi: -128, preset: ModemPresets.longFast, compact: true) .padding(.bottom) }.padding() - HStack { // Good LoRaSignalStrengthMeter(snr: -1, rssi: -114, preset: ModemPresets.longFast, compact: false) diff --git a/Meshtastic/Views/Messages/UserMessageList.swift b/Meshtastic/Views/Messages/UserMessageList.swift index ce9b0f33..2a4756fd 100644 --- a/Meshtastic/Views/Messages/UserMessageList.swift +++ b/Meshtastic/Views/Messages/UserMessageList.swift @@ -24,7 +24,7 @@ struct UserMessageList: View { @State private var hasReachedBottom = false @State private var gotFirstUnreadMessage: Bool = false @State private var messageToHighlight: Int64 = 0 - + var body: some View { VStack { ScrollViewReader { scrollView in @@ -51,7 +51,6 @@ struct UserMessageList: View { messageToHighlight = messageNum } scrollView.scrollTo(messageNum, anchor: .center) - // Reset highlight after delay Task { try? await Task.sleep(nanoseconds: 1_000_000_000) // 1 second diff --git a/Meshtastic/Views/Nodes/NodeList.swift b/Meshtastic/Views/Nodes/NodeList.swift index e3a91032..b0d602c2 100644 --- a/Meshtastic/Views/Nodes/NodeList.swift +++ b/Meshtastic/Views/Nodes/NodeList.swift @@ -364,7 +364,6 @@ struct NodeList: View { Logger.services.info("NodeList directly updated from notification for node: \(nodeNum, privacy: .public)") } } - Task { await searchNodeList() } diff --git a/Meshtastic/Views/Settings/Config/LoRaConfig.swift b/Meshtastic/Views/Settings/Config/LoRaConfig.swift index 1aae6ea4..452da960 100644 --- a/Meshtastic/Views/Settings/Config/LoRaConfig.swift +++ b/Meshtastic/Views/Settings/Config/LoRaConfig.swift @@ -248,7 +248,6 @@ struct LoRaConfig: View { /// 2.5 Administration with session passkey let expiration = node.sessionExpiration ?? Date() if expiration < Date() || node.loRaConfig == nil { - Logger.mesh.info("⚙️ Empty or expired lora config requesting via PKI admin") if connectedNode.user != nil && node.user != nil { _ = bleManager.requestLoRaConfig(fromUser: connectedNode.user!, toUser: node.user!, adminIndex: connectedNode.myInfo?.adminIndex ?? 0) diff --git a/Meshtastic/Views/Settings/UserConfig.swift b/Meshtastic/Views/Settings/UserConfig.swift index db64233e..1ffa4ce1 100644 --- a/Meshtastic/Views/Settings/UserConfig.swift +++ b/Meshtastic/Views/Settings/UserConfig.swift @@ -184,7 +184,7 @@ struct UserConfig: View { } else { var ham = HamParameters() ham.shortName = shortName - //ham.isUnmessagable = isUnmessagable + // ham.isUnmessagable = isUnmessagable ham.callSign = longName ham.txPower = Int32(txPower) ham.frequency = overrideFrequency