From 261af7de4b2830f12b29e58d0a4b2bfe2069dfd3 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Wed, 27 Oct 2021 21:15:36 -0700 Subject: [PATCH] V 1.27.3 Data cleanup so everything uses BLEManager, will implement core data soon --- Meshtastic Client.xcodeproj/project.pbxproj | 4 ++-- MeshtasticClient/Helpers/BLEManager.swift | 5 +++-- MeshtasticClient/MeshtasticClientApp.swift | 2 -- .../Views/Bluetooth/Connect.swift | 1 - MeshtasticClient/Views/Nodes/NodeDetail.swift | 6 +++--- MeshtasticClient/Views/Nodes/NodeList.swift | 19 +++++++++---------- MeshtasticClient/Views/Nodes/NodeMap.swift | 15 ++++----------- .../Views/Settings/AppSettings.swift | 2 +- 8 files changed, 22 insertions(+), 32 deletions(-) diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index 259d3e23..c7beaeec 100644 --- a/Meshtastic Client.xcodeproj/project.pbxproj +++ b/Meshtastic Client.xcodeproj/project.pbxproj @@ -672,7 +672,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.27.1; + MARKETING_VERSION = 1.27.3; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = YES; @@ -699,7 +699,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.27.1; + MARKETING_VERSION = 1.27.3; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = YES; diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift index a4b146e5..f0952681 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -170,10 +170,11 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph peripheralName = name } - let newPeripheral = Peripheral(id: peripheral.identifier.uuidString, name: peripheralName, rssi: RSSI.intValue, peripheral: peripheral, myInfo: nil) + var newPeripheral = Peripheral(id: peripheral.identifier.uuidString, name: peripheralName, rssi: RSSI.intValue, peripheral: peripheral, myInfo: nil) let peripheralIndex = peripherals.firstIndex(where: { $0.id == newPeripheral.id }) - + if peripheralIndex != nil { + newPeripheral.myInfo = self.meshData.nodes[peripheralIndex!].myInfo peripherals.remove(at: peripheralIndex!) peripherals.append(newPeripheral) print("Updating peripheral: \(peripheralName)"); diff --git a/MeshtasticClient/MeshtasticClientApp.swift b/MeshtasticClient/MeshtasticClientApp.swift index dff2d0bd..571ab864 100644 --- a/MeshtasticClient/MeshtasticClientApp.swift +++ b/MeshtasticClient/MeshtasticClientApp.swift @@ -10,14 +10,12 @@ import SwiftUI @main struct MeshtasticClientApp: App { - @ObservedObject private var meshData: MeshData = MeshData() @ObservedObject private var bleManager: BLEManager = BLEManager() @ObservedObject private var userSettings: UserSettings = UserSettings() var body: some Scene { WindowGroup { ContentView() - .environmentObject(meshData) .environmentObject(bleManager) .environmentObject(userSettings) } diff --git a/MeshtasticClient/Views/Bluetooth/Connect.swift b/MeshtasticClient/Views/Bluetooth/Connect.swift index 9fd1e718..8cc8040d 100644 --- a/MeshtasticClient/Views/Bluetooth/Connect.swift +++ b/MeshtasticClient/Views/Bluetooth/Connect.swift @@ -15,7 +15,6 @@ import CoreBluetooth struct Connect: View { - @EnvironmentObject var meshData: MeshData @EnvironmentObject var bleManager: BLEManager @EnvironmentObject var userSettings: UserSettings diff --git a/MeshtasticClient/Views/Nodes/NodeDetail.swift b/MeshtasticClient/Views/Nodes/NodeDetail.swift index 55742b09..b7a2b659 100644 --- a/MeshtasticClient/Views/Nodes/NodeDetail.swift +++ b/MeshtasticClient/Views/Nodes/NodeDetail.swift @@ -162,12 +162,12 @@ struct NodeDetail: View { struct NodeDetail_Previews: PreviewProvider { - static let meshData = MeshData() + static let bleManager = BLEManager() static var previews: some View { Group { - NodeDetail(node: meshData.nodes[0]).environmentObject(meshData) - NodeDetail(node: meshData.nodes[1]).environmentObject(meshData) + NodeDetail(node: bleManager.meshData.nodes[0]) + NodeDetail(node: bleManager.meshData.nodes[1]) } } } diff --git a/MeshtasticClient/Views/Nodes/NodeList.swift b/MeshtasticClient/Views/Nodes/NodeList.swift index d63defa8..64ef1a21 100644 --- a/MeshtasticClient/Views/Nodes/NodeList.swift +++ b/MeshtasticClient/Views/Nodes/NodeList.swift @@ -11,15 +11,15 @@ import SwiftUI struct NodeList: View { + @EnvironmentObject var bleManager: BLEManager - @EnvironmentObject var meshData: MeshData @State private var selection: String? = nil @State private var showLocationOnly = false var filteredDevices: [NodeInfoModel] { - meshData.nodes.filter { node in + bleManager.meshData.nodes.filter { node in (!showLocationOnly || node.position.coordinate != nil) } } @@ -29,7 +29,7 @@ struct NodeList: View { List { - if meshData.nodes.count == 0 { + if bleManager.meshData.nodes.count == 0 { Text("Scan for Radios").font(.largeTitle) //.listRowSeparator(.hidden) Text("No LoRa Mesh Nodes Found").font(.title2) @@ -68,9 +68,9 @@ struct NodeList: View { .swipeActions { Button { - let nodeIndex = meshData.nodes.firstIndex(where: { $0.id == node.id }) - meshData.nodes.remove(at: nodeIndex!) - meshData.save() + let nodeIndex = bleManager.meshData.nodes.firstIndex(where: { $0.id == node.id }) + bleManager.meshData.nodes.remove(at: nodeIndex!) + bleManager.meshData.save() } label: { Label("Delete from app", systemImage: "trash") @@ -83,11 +83,11 @@ struct NodeList: View { .navigationTitle("All Nodes") .onAppear( perform: { - if meshData.nodes.count == 0 { - meshData.load() + if bleManager.meshData.nodes.count == 0 { + bleManager.meshData.load() } if UIDevice.current.userInterfaceIdiom == .pad { - if meshData.nodes.count > 0 { + if bleManager.meshData.nodes.count > 0 { selection = "0" } } @@ -102,6 +102,5 @@ struct NodeList: View { struct NodeList_Previews: PreviewProvider { static var previews: some View { NodeList() - .environmentObject(MeshData()) } } diff --git a/MeshtasticClient/Views/Nodes/NodeMap.swift b/MeshtasticClient/Views/Nodes/NodeMap.swift index 32f49982..5820fd4f 100644 --- a/MeshtasticClient/Views/Nodes/NodeMap.swift +++ b/MeshtasticClient/Views/Nodes/NodeMap.swift @@ -12,13 +12,10 @@ import CoreLocation struct NodeMap: View { - - - @ObservedObject var bleManager = BLEManager() - @EnvironmentObject var meshData: MeshData + @EnvironmentObject var bleManager :BLEManager var locationNodes: [NodeInfoModel] { - meshData.nodes.filter { node in + bleManager.meshData.nodes.filter { node in (node.position.coordinate != nil) } } @@ -27,8 +24,6 @@ struct NodeMap: View { let name: String let coordinate: CLLocationCoordinate2D } - - var body: some View { let location = LocationHelper.currentLocation @@ -64,17 +59,15 @@ struct NodeMap: View { } .navigationViewStyle(StackNavigationViewStyle()) .onAppear{ - meshData.load() + bleManager.meshData.load() } } } struct NodeMap_Previews: PreviewProvider { - static let meshData = MeshData() static let bleManager = BLEManager() static var previews: some View { - NodeMap(bleManager: bleManager) - .environmentObject(MeshData()) + NodeMap() } } diff --git a/MeshtasticClient/Views/Settings/AppSettings.swift b/MeshtasticClient/Views/Settings/AppSettings.swift index c33f35a2..8ea6cfd7 100644 --- a/MeshtasticClient/Views/Settings/AppSettings.swift +++ b/MeshtasticClient/Views/Settings/AppSettings.swift @@ -75,7 +75,7 @@ class UserSettings: ObservableObject { struct AppSettings: View { @EnvironmentObject var bleManager: BLEManager - @ObservedObject var userSettings: UserSettings = UserSettings() + @EnvironmentObject var userSettings: UserSettings @State private var preferredDeviceConnected = false