diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index c760d63f..cb1f6722 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -1198,7 +1198,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https: //github.com/realm/SwiftLint\"\nfi\n"; + shellScript = "if [[ \"$(uname -m)\" == arm64 ]]\nthen\n export PATH=\"/opt/homebrew/bin:$PATH\"\nfi\n\nif command -v swiftlint >/dev/null 2>&1\nthen\n swiftlint\nelse\n echo \"warning: `swiftlint` command not found - See https://github.com/realm/SwiftLint#installation for installation instructions.\"\nfi\n"; }; /* End PBXShellScriptBuildPhase section */ @@ -1488,7 +1488,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; - ENABLE_USER_SCRIPT_SANDBOXING = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; diff --git a/Meshtastic/Enums/AppSettingsEnums.swift b/Meshtastic/Enums/AppSettingsEnums.swift index bbd91ce0..bfd8ce9e 100644 --- a/Meshtastic/Enums/AppSettingsEnums.swift +++ b/Meshtastic/Enums/AppSettingsEnums.swift @@ -60,7 +60,6 @@ enum MeshMapDistances: Double, CaseIterable, Identifiable { case twentyFiveHundredMiles = 4023360 case fiveThouandMiles = 8046720 case tenThousandMiles = 16093440 - var id: Double { self.rawValue } var description: String { let distanceFormatter = MKDistanceFormatter() diff --git a/Meshtastic/Export/WriteCsvFile.swift b/Meshtastic/Export/WriteCsvFile.swift index 335b8544..c43fe7a1 100644 --- a/Meshtastic/Export/WriteCsvFile.swift +++ b/Meshtastic/Export/WriteCsvFile.swift @@ -14,8 +14,7 @@ func telemetryToCsvFile(telemetry: [TelemetryEntity], metricsType: Int) -> Strin if metricsType == 0 { // Create Device Metrics Header csvString = "\("battery.level".localized), \("voltage".localized), \("channel.utilization".localized), \("airtime".localized), \("uptime".localized), \("timestamp".localized)" - for dm in telemetry { - if dm.metricsType == 0 { + for dm in telemetry where dm.metricsType == 0 { csvString += "\n" csvString += String(dm.batteryLevel) csvString += ", " @@ -28,26 +27,23 @@ func telemetryToCsvFile(telemetry: [TelemetryEntity], metricsType: Int) -> Strin csvString += String(dm.uptimeSeconds) csvString += ", " csvString += dm.time?.formattedDate(format: dateFormatString) ?? "unknown.age".localized - } } } else if metricsType == 1 { // Create Environment Telemetry Header csvString = "Temperature, Relative Humidity, Barometric Pressure, Indoor Air Quality, Gas Resistance, \("timestamp".localized)" - for dm in telemetry { - if dm.metricsType == 1 { - csvString += "\n" - csvString += String(dm.temperature.localeTemperature()) - csvString += ", " - csvString += String(dm.relativeHumidity) - csvString += ", " - csvString += String(dm.barometricPressure) - csvString += ", " - csvString += String(dm.iaq) - csvString += ", " - csvString += String(dm.gasResistance) - csvString += ", " - csvString += dm.time?.formattedDate(format: dateFormatString) ?? "unknown.age".localized - } + for dm in telemetry where dm.metricsType == 1 { + csvString += "\n" + csvString += String(dm.temperature.localeTemperature()) + csvString += ", " + csvString += String(dm.relativeHumidity) + csvString += ", " + csvString += String(dm.barometricPressure) + csvString += ", " + csvString += String(dm.iaq) + csvString += ", " + csvString += String(dm.gasResistance) + csvString += ", " + csvString += dm.time?.formattedDate(format: dateFormatString) ?? "unknown.age".localized } } return csvString diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 68267692..9c59a12f 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -10,13 +10,6 @@ import CocoaMQTT // --------------------------------------------------------------------------------------- class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate, ObservableObject { - private static var documentsFolder: URL { - do { - return try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) - } catch { - fatalError("Can't find documents directory.") - } - } var context: NSManagedObjectContext? static let shared = BLEManager() @@ -53,8 +46,6 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate let EOL_FROMRADIO_UUID = CBUUID(string: "0x8BA2BCC2-EE02-4A55-A531-C525C5E454D5") let FROMNUM_UUID = CBUUID(string: "0xED9DA18C-A800-4F66-A670-AA7547E34453") - let meshLog = documentsFolder.appendingPathComponent("meshlog.txt") - // MARK: init BLEManager override init() { self.lastConnectionError = "" @@ -284,11 +275,9 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate logger.error("🚫 Discover Services error \(error.localizedDescription)") } guard let services = peripheral.services else { return } - for service in services { - if service.uuid == meshtasticServiceCBUUID { - peripheral.discoverCharacteristics([TORADIO_UUID, FROMRADIO_UUID, FROMNUM_UUID], for: service) - logger.info("✅ BLE Service for Meshtastic discovered by \(peripheral.name ?? "Unknown")") - } + for service in services where service.uuid == meshtasticServiceCBUUID { + peripheral.discoverCharacteristics([TORADIO_UUID, FROMRADIO_UUID, FROMNUM_UUID], for: service) + logger.info("✅ BLE Service for Meshtastic discovered by \(peripheral.name ?? "Unknown")") } } @@ -359,10 +348,11 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate var toRadio: ToRadio! toRadio = ToRadio() toRadio.mqttClientProxyMessage = proxyMessage - let binaryData: Data = try! toRadio.serializedData() + guard let binaryData: Data = try? toRadio.serializedData() else { + return + } if connectedPeripheral?.peripheral.state ?? CBPeripheralState.disconnected == CBPeripheralState.connected { connectedPeripheral.peripheral.writeValue(binaryData, for: TORADIO_characteristic, type: .withResponse) - } } @@ -387,10 +377,15 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate meshPacket.channel = UInt32(adminIndex) meshPacket.wantAck = true var dataMessage = DataMessage() - dataMessage.payload = try! adminPacket.serializedData() - dataMessage.portnum = PortNum.adminApp - dataMessage.wantResponse = true - meshPacket.decoded = dataMessage + if let serializedData: Data = try? adminPacket.serializedData() { + dataMessage.payload = serializedData + dataMessage.portnum = PortNum.adminApp + dataMessage.wantResponse = true + meshPacket.decoded = dataMessage + } else { + return 0 + } + let messageDescription = "🛎️ Requested Device Metadata for node \(toUser.longName ?? "unknown".localized) by \(fromUser.longName ?? "unknown".localized)" if sendAdminMessageToRadio(meshPacket: meshPacket, adminDescription: messageDescription, fromUser: fromUser, toUser: toUser) { return Int64(meshPacket.id) @@ -411,16 +406,20 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate meshPacket.from = UInt32(fromNodeNum) meshPacket.wantAck = true var dataMessage = DataMessage() - dataMessage.payload = try! routePacket.serializedData() - dataMessage.portnum = PortNum.tracerouteApp - dataMessage.wantResponse = wantResponse - meshPacket.decoded = dataMessage - + if let serializedData: Data = try? routePacket.serializedData() { + dataMessage.payload = serializedData + dataMessage.portnum = PortNum.tracerouteApp + dataMessage.wantResponse = true + meshPacket.decoded = dataMessage + } else { + return false + } var toRadio: ToRadio! toRadio = ToRadio() toRadio.packet = meshPacket - let binaryData: Data = try! toRadio.serializedData() - + guard let binaryData: Data = try? toRadio.serializedData() else { + return false + } if connectedPeripheral?.peripheral.state ?? CBPeripheralState.disconnected == CBPeripheralState.connected { connectedPeripheral.peripheral.writeValue(binaryData, for: TORADIO_characteristic, type: .withResponse) success = true @@ -481,7 +480,9 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate var toRadio: ToRadio = ToRadio() configNonce += 1 toRadio.wantConfigID = configNonce - let binaryData: Data = try! toRadio.serializedData() + guard let binaryData: Data = try? toRadio.serializedData() else { + return + } connectedPeripheral!.peripheral.writeValue(binaryData, for: TORADIO_characteristic, type: .withResponse) // Either Read the config complete value or from num notify value guard connectedPeripheral != nil else { return } @@ -903,7 +904,9 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate var toRadio: ToRadio! toRadio = ToRadio() toRadio.packet = meshPacket - let binaryData: Data = try! toRadio.serializedData() + guard let binaryData: Data = try? toRadio.serializedData() else { + return false + } if connectedPeripheral?.peripheral.state ?? CBPeripheralState.disconnected == CBPeripheralState.connected { connectedPeripheral.peripheral.writeValue(binaryData, for: TORADIO_characteristic, type: .withResponse) let logString = String.localizedStringWithFormat("mesh.log.textmessage.sent %@ %@ %@".localized, String(newMessage.messageId), String(fromUserNum), String(toUserNum)) @@ -952,7 +955,9 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate var toRadio: ToRadio! toRadio = ToRadio() toRadio.packet = meshPacket - let binaryData: Data = try! toRadio.serializedData() + guard let binaryData: Data = try? toRadio.serializedData() else { + return false + } let logString = String.localizedStringWithFormat("mesh.log.waypoint.sent %@".localized, String(fromNodeNum)) MeshLogger.log("📍 \(logString)") if connectedPeripheral?.peripheral.state ?? CBPeripheralState.disconnected == CBPeripheralState.connected { @@ -1051,9 +1056,14 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate meshPacket.wantAck = true meshPacket.channel = UInt32(channel) var dataMessage = DataMessage() - dataMessage.payload = try! adminPacket.serializedData() - dataMessage.portnum = PortNum.adminApp meshPacket.decoded = dataMessage + if let serializedData: Data = try? adminPacket.serializedData() { + dataMessage.payload = serializedData + dataMessage.portnum = PortNum.adminApp + meshPacket.decoded = dataMessage + } else { + return false + } let messageDescription = "🚀 Sent Set Fixed Postion Admin Message to: \(fromUser.longName ?? "unknown".localized) from: \(fromUser.longName ?? "unknown".localized)" if sendAdminMessageToRadio(meshPacket: meshPacket, adminDescription: messageDescription, fromUser: fromUser, toUser: fromUser) { return true @@ -1072,9 +1082,13 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate meshPacket.wantAck = true meshPacket.channel = UInt32(channel) var dataMessage = DataMessage() - dataMessage.payload = try! adminPacket.serializedData() - dataMessage.portnum = PortNum.adminApp - meshPacket.decoded = dataMessage + if let serializedData: Data = try? adminPacket.serializedData() { + dataMessage.payload = serializedData + dataMessage.portnum = PortNum.adminApp + meshPacket.decoded = dataMessage + } else { + return false + } let messageDescription = "🚀 Sent Remove Fixed Position Admin Message to: \(fromUser.longName ?? "unknown".localized) from: \(fromUser.longName ?? "unknown".localized)" if sendAdminMessageToRadio(meshPacket: meshPacket, adminDescription: messageDescription, fromUser: fromUser, toUser: fromUser) { return true @@ -1094,15 +1108,21 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate meshPacket.channel = UInt32(channel) meshPacket.from = UInt32(fromNodeNum) var dataMessage = DataMessage() - dataMessage.payload = try! positionPacket.serializedData() - dataMessage.portnum = PortNum.positionApp - dataMessage.wantResponse = wantResponse - meshPacket.decoded = dataMessage + if let serializedData: Data = try? positionPacket.serializedData() { + dataMessage.payload = serializedData + dataMessage.portnum = PortNum.positionApp + dataMessage.wantResponse = wantResponse + meshPacket.decoded = dataMessage + } else { + return false + } var toRadio: ToRadio! toRadio = ToRadio() toRadio.packet = meshPacket - let binaryData: Data = try! toRadio.serializedData() + guard let binaryData: Data = try? toRadio.serializedData() else { + return false + } if connectedPeripheral?.peripheral.state ?? CBPeripheralState.disconnected == CBPeripheralState.connected { connectedPeripheral.peripheral.writeValue(binaryData, for: TORADIO_characteristic, type: .withResponse) success = true @@ -1132,9 +1152,13 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate meshPacket.wantAck = true meshPacket.channel = UInt32(adminIndex) var dataMessage = DataMessage() - dataMessage.payload = try! adminPacket.serializedData() - dataMessage.portnum = PortNum.adminApp - meshPacket.decoded = dataMessage + if let serializedData: Data = try? adminPacket.serializedData() { + dataMessage.payload = serializedData + dataMessage.portnum = PortNum.adminApp + meshPacket.decoded = dataMessage + } else { + return false + } let messageDescription = "🚀 Sent Shutdown Admin Message to: \(toUser.longName ?? "unknown".localized) from: \(fromUser.longName ?? "unknown".localized)" if sendAdminMessageToRadio(meshPacket: meshPacket, adminDescription: messageDescription, fromUser: fromUser, toUser: toUser) { return true @@ -1153,9 +1177,13 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate meshPacket.wantAck = true meshPacket.channel = UInt32(adminIndex) var dataMessage = DataMessage() - dataMessage.payload = try! adminPacket.serializedData() - dataMessage.portnum = PortNum.adminApp - meshPacket.decoded = dataMessage + if let serializedData: Data = try? adminPacket.serializedData() { + dataMessage.payload = serializedData + dataMessage.portnum = PortNum.adminApp + meshPacket.decoded = dataMessage + } else { + return false + } let messageDescription = "🚀 Sent Reboot Admin Message to: \(toUser.longName ?? "unknown".localized) from: \(fromUser.longName ?? "unknown".localized)" if sendAdminMessageToRadio(meshPacket: meshPacket, adminDescription: messageDescription, fromUser: fromUser, toUser: toUser) { return true @@ -1174,9 +1202,13 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate meshPacket.wantAck = true meshPacket.channel = UInt32(adminIndex) var dataMessage = DataMessage() - dataMessage.payload = try! adminPacket.serializedData() - dataMessage.portnum = PortNum.adminApp - meshPacket.decoded = dataMessage + if let serializedData: Data = try? adminPacket.serializedData() { + dataMessage.payload = serializedData + dataMessage.portnum = PortNum.adminApp + meshPacket.decoded = dataMessage + } else { + return false + } let messageDescription = "🚀 Sent Reboot OTA Admin Message to: \(toUser.longName ?? "unknown".localized) from: \(fromUser.longName ?? "unknown".localized)" if sendAdminMessageToRadio(meshPacket: meshPacket, adminDescription: messageDescription, fromUser: fromUser, toUser: toUser) { return true @@ -1195,9 +1227,13 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate meshPacket.wantAck = true meshPacket.channel = UInt32(0) var dataMessage = DataMessage() - dataMessage.payload = try! adminPacket.serializedData() - dataMessage.portnum = PortNum.adminApp - meshPacket.decoded = dataMessage + if let serializedData: Data = try? adminPacket.serializedData() { + dataMessage.payload = serializedData + dataMessage.portnum = PortNum.adminApp + meshPacket.decoded = dataMessage + } else { + return false + } automaticallyReconnect = false let messageDescription = "🚀 Sent enter DFU mode Admin Message to: \(toUser.longName ?? "unknown".localized) from: \(fromUser.longName ?? "unknown".localized)" if sendAdminMessageToRadio(meshPacket: meshPacket, adminDescription: messageDescription, fromUser: fromUser, toUser: toUser) { @@ -1216,9 +1252,13 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate meshPacket.priority = MeshPacket.Priority.reliable meshPacket.wantAck = true var dataMessage = DataMessage() - dataMessage.payload = try! adminPacket.serializedData() - dataMessage.portnum = PortNum.adminApp - meshPacket.decoded = dataMessage + if let serializedData: Data = try? adminPacket.serializedData() { + dataMessage.payload = serializedData + dataMessage.portnum = PortNum.adminApp + meshPacket.decoded = dataMessage + } else { + return false + } let messageDescription = "🚀 Sent Factory Reset Admin Message to: \(toUser.longName ?? "unknown".localized) from: \(fromUser.longName ?? "unknown".localized)" if sendAdminMessageToRadio(meshPacket: meshPacket, adminDescription: messageDescription, fromUser: fromUser, toUser: toUser) { @@ -1237,7 +1277,10 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate meshPacket.priority = MeshPacket.Priority.reliable meshPacket.wantAck = true var dataMessage = DataMessage() - dataMessage.payload = try! adminPacket.serializedData() + guard let adminData: Data = try? adminPacket.serializedData() else { + return false + } + dataMessage.payload = adminData dataMessage.portnum = PortNum.adminApp meshPacket.decoded = dataMessage @@ -1276,7 +1319,10 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate meshPacket.id = UInt32.random(in: UInt32(UInt8.max).. String { if !message.isEmoji() { let types: NSTextCheckingResult.CheckingType = [.address, .link, .phoneNumber] - let detector = try! NSDataDetector(types: types.rawValue) + guard let detector = try? NSDataDetector(types: types.rawValue) else { + return message + } let matches = detector.matches(in: message, options: [], range: NSRange(location: 0, length: message.utf16.count)) var messageWithMarkdown = message if matches.count > 0 { @@ -629,16 +631,11 @@ func routingPacket (packet: MeshPacket, connectedNodeNum: Int64, context: NSMana let fetchedMyInfo = try context.fetch(fetchMyInfoRequest) as? [MyInfoEntity] if fetchedMyInfo?.count ?? 0 > 0 { - for ch in fetchedMyInfo![0].channels!.array as? [ChannelEntity] ?? [] { - - if ch.index == packet.channel { - ch.objectWillChange.send() - } + for ch in fetchedMyInfo![0].channels!.array as? [ChannelEntity] ?? [] where ch.index == packet.channel { + ch.objectWillChange.send() } } - } catch { - - } + } catch { } } } else { diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index e7b0abe2..90bb164b 100644 --- a/Meshtastic/Views/Bluetooth/Connect.swift +++ b/Meshtastic/Views/Bluetooth/Connect.swift @@ -355,9 +355,8 @@ struct Connect: View { func endActivity() { liveActivityStarted = false Task { - for activity in Activity.activities { - // Check if this is the activity associated with this order. - if activity.attributes.nodeNum == node?.num ?? 0 { await activity.end(nil, dismissalPolicy: .immediate) } + for activity in Activity.activities where activity.attributes.nodeNum == node?.num ?? 0 { + await activity.end(nil, dismissalPolicy: .immediate) } } } diff --git a/Meshtastic/Views/MapKitMap/Custom/MapViewSwiftUI.swift b/Meshtastic/Views/MapKitMap/Custom/MapViewSwiftUI.swift index 4cc8b941..90ae646e 100644 --- a/Meshtastic/Views/MapKitMap/Custom/MapViewSwiftUI.swift +++ b/Meshtastic/Views/MapKitMap/Custom/MapViewSwiftUI.swift @@ -98,10 +98,8 @@ struct MapViewSwiftUI: UIViewRepresentable { // Avoid refreshing UI if selectedLayer has not changed guard currentMapLayer != selectedMapLayer else { return } currentMapLayer = selectedMapLayer - for overlay in mapView.overlays { - if overlay is MKTileOverlay { - mapView.removeOverlay(overlay) - } + for overlay in mapView.overlays where overlay is MKTileOverlay { + mapView.removeOverlay(overlay) } switch selectedMapLayer { case .offline: @@ -179,10 +177,8 @@ struct MapViewSwiftUI: UIViewRepresentable { // Node Route Lines if showRouteLines { // Remove all existing PolyLine Overlays - for overlay in mapView.overlays { - if overlay is MKPolyline { - mapView.removeOverlay(overlay) - } + for overlay in mapView.overlays where overlay is MKPolyline { + mapView.removeOverlay(overlay) } var lineIndex = 0 for position in latest { @@ -201,10 +197,8 @@ struct MapViewSwiftUI: UIViewRepresentable { } } else { // Remove all existing PolyLine Overlays - for overlay in mapView.overlays { - if overlay is MKPolyline { - mapView.removeOverlay(overlay) - } + for overlay in mapView.overlays where overlay is MKPolyline { + mapView.removeOverlay(overlay) } } let annotationCount = waypoints.count + (showNodeHistory ? positions.count : latest.count) diff --git a/Meshtastic/Views/MapKitMap/NodeMapMapkit.swift b/Meshtastic/Views/MapKitMap/NodeMapMapkit.swift index 59176569..1f310851 100644 --- a/Meshtastic/Views/MapKitMap/NodeMapMapkit.swift +++ b/Meshtastic/Views/MapKitMap/NodeMapMapkit.swift @@ -43,7 +43,6 @@ struct NodeMapMapkit: View { var body: some View { - let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral?.num ?? -1, context: context) NavigationStack { GeometryReader { bounds in VStack { diff --git a/Meshtastic/Views/Messages/ChannelList.swift b/Meshtastic/Views/Messages/ChannelList.swift index 9cd2ed5d..c1c47a89 100644 --- a/Meshtastic/Views/Messages/ChannelList.swift +++ b/Meshtastic/Views/Messages/ChannelList.swift @@ -97,7 +97,6 @@ struct ChannelList: View { } } } - var body: some View { VStack { // Display Contacts for the rest of the non admin channels diff --git a/Meshtastic/Views/Nodes/Helpers/Map/PositionPopover.swift b/Meshtastic/Views/Nodes/Helpers/Map/PositionPopover.swift index 37e913bf..0c03e8f4 100644 --- a/Meshtastic/Views/Nodes/Helpers/Map/PositionPopover.swift +++ b/Meshtastic/Views/Nodes/Helpers/Map/PositionPopover.swift @@ -133,7 +133,6 @@ struct PositionPopover: View { if position.nodePosition?.viaMqtt ?? false { Label { - let heading = Measurement(value: degrees.degrees, unit: UnitAngle.degrees) Text("MQTT") } icon: { Image(systemName: "network") diff --git a/Meshtastic/Views/Nodes/Helpers/NodeInfoItem.swift b/Meshtastic/Views/Nodes/Helpers/NodeInfoItem.swift index ea24ed4f..df40aaa5 100644 --- a/Meshtastic/Views/Nodes/Helpers/NodeInfoItem.swift +++ b/Meshtastic/Views/Nodes/Helpers/NodeInfoItem.swift @@ -25,7 +25,7 @@ struct NodeInfoItem: View { } if node.user != nil { Divider() - VStack (alignment: .center) { + VStack(alignment: .center) { if node.user?.hwModel != "UNSET" { Image(node.user!.hwModel ?? "unset".localized) .resizable() diff --git a/Meshtastic/Views/Nodes/MeshMap.swift b/Meshtastic/Views/Nodes/MeshMap.swift index 4e4ec412..18a61228 100644 --- a/Meshtastic/Views/Nodes/MeshMap.swift +++ b/Meshtastic/Views/Nodes/MeshMap.swift @@ -65,27 +65,27 @@ struct MeshMap: View { .sequenced(before: SpatialTapGesture(coordinateSpace: .local)) .onEnded { value in switch value { - case let .second(_, tapValue): - guard let point = tapValue?.location else { - logger.error("Unable to retreive tap location from gesture data.") - return - } + case let .second(_, tapValue): + guard let point = tapValue?.location else { + logger.error("Unable to retreive tap location from gesture data.") + return + } - guard let coordinate = reader.convert(point, from: .local) else { - logger.error("Unable to convert local point to coordinate on map.") - return - } + guard let coordinate = reader.convert(point, from: .local) else { + logger.error("Unable to convert local point to coordinate on map.") + return + } - newWaypointCoord = coordinate - editingWaypoint = WaypointEntity(context: context) - editingWaypoint!.name = "Waypoint Pin" - editingWaypoint!.expire = Date.now.addingTimeInterval(60 * 480) - editingWaypoint!.latitudeI = Int32((newWaypointCoord?.latitude ?? 0) * 1e7) - editingWaypoint!.longitudeI = Int32((newWaypointCoord?.longitude ?? 0) * 1e7) - editingWaypoint!.expire = Date.now.addingTimeInterval(60 * 480) - editingWaypoint!.id = 0 - logger.debug("Long press occured at Lat: \(coordinate.latitude) Long: \(coordinate.longitude)") - default: return + newWaypointCoord = coordinate + editingWaypoint = WaypointEntity(context: context) + editingWaypoint!.name = "Waypoint Pin" + editingWaypoint!.expire = Date.now.addingTimeInterval(60 * 480) + editingWaypoint!.latitudeI = Int32((newWaypointCoord?.latitude ?? 0) * 1e7) + editingWaypoint!.longitudeI = Int32((newWaypointCoord?.longitude ?? 0) * 1e7) + editingWaypoint!.expire = Date.now.addingTimeInterval(60 * 480) + editingWaypoint!.id = 0 + logger.debug("Long press occured at Lat: \(coordinate.latitude) Long: \(coordinate.longitude)") + default: return } }) } @@ -170,9 +170,6 @@ struct MeshMap: View { }) .onAppear { UIApplication.shared.isIdleTimerDisabled = true - if self.bleManager.context == nil { - self.bleManager.context = context - } // let wayPointEntity = getWaypoint(id: Int64(deepLinkManager.waypointId) ?? -1, context: context) // if wayPointEntity.id > 0 { diff --git a/Meshtastic/Views/Settings/Channels.swift b/Meshtastic/Views/Settings/Channels.swift index 567aff6f..d91779e5 100644 --- a/Meshtastic/Views/Settings/Channels.swift +++ b/Meshtastic/Views/Settings/Channels.swift @@ -196,10 +196,8 @@ struct Channels: View { for object in objects { context.delete(object) } - for node in nodes { - if node.channel == channelEntity.index { - context.delete(node) - } + for node in nodes where node.channel == channelEntity.index { + context.delete(node) } context.delete(channelEntity) do { @@ -295,7 +293,7 @@ struct Channels: View { } func firstMissingChannelIndex(_ indexes: [Int]) -> Int { - var smallestIndex = 1 + let smallestIndex = 1 if indexes.isEmpty { return smallestIndex } if smallestIndex <= indexes.count { for element in smallestIndex...indexes.count where !indexes.contains(element) { diff --git a/Meshtastic/Views/Settings/ShareChannels.swift b/Meshtastic/Views/Settings/ShareChannels.swift index 6246d7fe..627bc5e5 100644 --- a/Meshtastic/Views/Settings/ShareChannels.swift +++ b/Meshtastic/Views/Settings/ShareChannels.swift @@ -269,20 +269,18 @@ struct ShareChannels: View { channelSet.loraConfig = loRaConfig if node?.myInfo?.channels != nil && node?.myInfo?.channels?.count ?? 0 > 0 { for ch in node?.myInfo?.channels?.array as? [ChannelEntity] ?? [] { - if ch.role > 0 { - - if ch.index == 0 && includeChannel0 || ch.index == 1 && includeChannel1 || ch.index == 2 && includeChannel2 || ch.index == 3 && includeChannel3 || - ch.index == 4 && includeChannel4 || ch.index == 5 && includeChannel5 || ch.index == 6 && includeChannel6 || ch.index == 7 && includeChannel7 { - - var channelSettings = ChannelSettings() - channelSettings.name = ch.name! - channelSettings.psk = ch.psk! - channelSettings.id = UInt32(ch.id) - channelSet.settings.append(channelSettings) - } + if ch.role > 0, ch.index == 0 && includeChannel0 || ch.index == 1 && includeChannel1 || ch.index == 2 && includeChannel2 || ch.index == 3 && includeChannel3 || + ch.index == 4 && includeChannel4 || ch.index == 5 && includeChannel5 || ch.index == 6 && includeChannel6 || ch.index == 7 && includeChannel7 { + var channelSettings = ChannelSettings() + channelSettings.name = ch.name! + channelSettings.psk = ch.psk! + channelSettings.id = UInt32(ch.id) + channelSet.settings.append(channelSettings) } } - let settingsString = try! channelSet.serializedData().base64EncodedString() + guard let settingsString = try? channelSet.serializedData().base64EncodedString() else { + return + } channelsUrl = ("https://meshtastic.org/e/#" + settingsString.base64ToBase64url() + (replaceChannels ? "" : "?add=true")) } }