Merge pull request #4 from garthvh/coredata-refactor

Small fixes before working on CoreData refactor
This commit is contained in:
Garth Vander Houwen 2021-11-04 10:02:35 -07:00 committed by GitHub
commit 667ee47c60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 109 additions and 39 deletions

View file

@ -42,6 +42,8 @@
DDAF8C6B26ED0DD80058C060 /* environmental_measurement.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAF8C6A26ED0DD80058C060 /* environmental_measurement.pb.swift */; };
DDAF8C6E26ED19040058C060 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAF8C6D26ED19040058C060 /* Extensions.swift */; };
DDB020A0272B0C6B00F8DBAE /* PersistanceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB0209F272B0C6B00F8DBAE /* PersistanceController.swift */; };
DDB020A42733A6F400F8DBAE /* MeshtasticClient.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = DDB020A22733A6F400F8DBAE /* MeshtasticClient.xcdatamodeld */; };
DDB020A92733AECE00F8DBAE /* NodeInfoEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB020A82733AECE00F8DBAE /* NodeInfoEntity.swift */; };
DDC2E15826CE248E0042C5E4 /* MeshtasticClientApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC2E15726CE248E0042C5E4 /* MeshtasticClientApp.swift */; };
DDC2E15C26CE248F0042C5E4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DDC2E15B26CE248F0042C5E4 /* Assets.xcassets */; };
DDC2E15F26CE248F0042C5E4 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DDC2E15E26CE248F0042C5E4 /* Preview Assets.xcassets */; };
@ -106,6 +108,9 @@
DDAF8C6A26ED0DD80058C060 /* environmental_measurement.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = environmental_measurement.pb.swift; sourceTree = "<group>"; };
DDAF8C6D26ED19040058C060 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
DDB0209F272B0C6B00F8DBAE /* PersistanceController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistanceController.swift; sourceTree = "<group>"; };
DDB020A1273396D800F8DBAE /* RELEASENOTES.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = RELEASENOTES.md; sourceTree = "<group>"; };
DDB020A32733A6F400F8DBAE /* MeshtasticClient.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MeshtasticClient.xcdatamodel; sourceTree = "<group>"; };
DDB020A82733AECE00F8DBAE /* NodeInfoEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeInfoEntity.swift; sourceTree = "<group>"; };
DDC2E15426CE248E0042C5E4 /* MeshtasticClient.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MeshtasticClient.app; sourceTree = BUILT_PRODUCTS_DIR; };
DDC2E15726CE248E0042C5E4 /* MeshtasticClientApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeshtasticClientApp.swift; sourceTree = "<group>"; };
DDC2E15B26CE248F0042C5E4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@ -206,6 +211,7 @@
isa = PBXGroup;
children = (
DDB0209F272B0C6B00F8DBAE /* PersistanceController.swift */,
DDB020A82733AECE00F8DBAE /* NodeInfoEntity.swift */,
);
path = Data;
sourceTree = "<group>";
@ -245,6 +251,8 @@
DDC2E15B26CE248F0042C5E4 /* Assets.xcassets */,
DDC2E16526CE248F0042C5E4 /* Info.plist */,
DDC2E15D26CE248F0042C5E4 /* Preview Content */,
DDB020A1273396D800F8DBAE /* RELEASENOTES.md */,
DDB020A22733A6F400F8DBAE /* MeshtasticClient.xcdatamodeld */,
);
path = MeshtasticClient;
sourceTree = "<group>";
@ -494,6 +502,7 @@
DD23A51326FEF5D500D9B90C /* MessageData.swift in Sources */,
DD836AED26F858F900ABCC23 /* MeshData.swift in Sources */,
DDAF8C6B26ED0DD80058C060 /* environmental_measurement.pb.swift in Sources */,
DDB020A42733A6F400F8DBAE /* MeshtasticClient.xcdatamodeld in Sources */,
DD90860C26F684AF00DC5189 /* BatteryIcon.swift in Sources */,
DD4A91202708C66600501B7E /* Configuration.swift in Sources */,
DD4A911E2708C65400501B7E /* AppSettings.swift in Sources */,
@ -501,6 +510,7 @@
DDF924CA26FBB953009FE055 /* ConnectedDevice.swift in Sources */,
DDAF8C5D26ED09490058C060 /* portnums.pb.swift in Sources */,
DD47E3DF26F39D9F00029299 /* MyInfoModel.swift in Sources */,
DDB020A92733AECE00F8DBAE /* NodeInfoEntity.swift in Sources */,
DD23A50F26FD1B4400D9B90C /* PeripheralModel.swift in Sources */,
DD47E3CE26F103C600029299 /* NodeList.swift in Sources */,
DD47E3D026F1073F00029299 /* NodeRow.swift in Sources */,
@ -609,6 +619,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = "1,2,6";
};
name = Debug;
};
@ -660,9 +671,11 @@
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
TARGETED_DEVICE_FAMILY = "1,2,6";
VALIDATE_PRODUCT = YES;
};
name = Release;
@ -684,11 +697,11 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.27.6;
MARKETING_VERSION = 1.27.8;
PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,6";
};
@ -711,11 +724,11 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.27.6;
MARKETING_VERSION = 1.27.8;
PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,6";
};
@ -864,6 +877,19 @@
productName = SwiftProtobuf;
};
/* End XCSwiftPackageProductDependency section */
/* Begin XCVersionGroup section */
DDB020A22733A6F400F8DBAE /* MeshtasticClient.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
DDB020A32733A6F400F8DBAE /* MeshtasticClient.xcdatamodel */,
);
currentVersion = DDB020A32733A6F400F8DBAE /* MeshtasticClient.xcdatamodel */;
path = MeshtasticClient.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
};
/* End XCVersionGroup section */
};
rootObject = DDC2E14C26CE248E0042C5E4 /* Project object */;
}

View file

@ -20,8 +20,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
}
}
@ObservedObject var meshData : MeshData
@ObservedObject var messageData : MessageData
@Published var meshData : MeshData
@Published var messageData : MessageData
private var centralManager: CBCentralManager!
@ -114,22 +114,22 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
self.timeoutTimerCount += 1
if timeoutTimerCount == 6 {
if timeoutTimerCount == 10 {
if connectedPeripheral != nil && connectedPeripheral.peripheral.state != CBPeripheralState.connected {
if connectedPeripheral != nil {
self.centralManager?.cancelPeripheralConnection(connectedPeripheral.peripheral)
connectedNode = nil
connectedPeripheral = nil
if meshLoggingEnabled { Logger.log("BLE Connecting Timeout Timer disconnected orphaned radio: \(name) in state: \(connectedPeripheral.peripheral.state.rawValue)") }
}
self.lastConnectionError = "Timeout while connecting to \(name)."
print("BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Times and failed: \(name)")
if meshLoggingEnabled { Logger.log("BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Times and failed: \(name)") }
connectedNode = nil
connectedPeripheral = nil
self.lastConnectionError = "BLE Connecting Timeout after making \(timeoutTimerCount) attempts to connect to \(name)."
print("BLE Connecting Timeout after making \(timeoutTimerCount) attempts to connect to \(name).")
if meshLoggingEnabled { Logger.log("BLE Connecting Timeout after making \(timeoutTimerCount) attempts to connect to \(String(name)).") }
self.timeoutTimer?.invalidate()
self.timeoutTimerCount = 0
self.timeoutTimer?.invalidate()
}
else {
print("BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Time(s): \(name)")

View file

@ -6,6 +6,8 @@
<true/>
<key>com.apple.security.device.bluetooth</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.personal-information.location</key>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="19461" systemVersion="21A559" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="NodeInfoEntity" representedClassName="NodeInfoEntity" syncable="YES">
<fetchedProperty name="fetchedProperty" optional="YES">
<fetchRequest name="fetchedPropertyFetchRequest" entity="NodeInfoEntity"/>
</fetchedProperty>
</entity>
<elements>
<element name="NodeInfoEntity" positionX="-45" positionY="0" width="128" height="50"/>
</elements>
</model>

View file

@ -6,7 +6,7 @@ struct MeshtasticClientApp: App {
@ObservedObject private var bleManager: BLEManager = BLEManager()
@ObservedObject private var userSettings: UserSettings = UserSettings()
//let persistenceController = PersistenceController.shared
//@Environment(\.scenePhase) var scenePhase
@Environment(\.scenePhase) var scenePhase
var body: some Scene {
WindowGroup {
@ -15,18 +15,18 @@ struct MeshtasticClientApp: App {
.environmentObject(userSettings)
//.environment(\.managedObjectContext, persistenceController.container.viewContext)
}
//.onChange(of: scenePhase) { (newScenePhase) in
// switch newScenePhase {
// case .background:
// print("Scene is in the background")
// persistenceController.save()
// case .inactive:
// print("Scene is inactive")
// case .active:
// print("Scene is active")
// @unknown default:
// print("Apple must have changed something")
// }
//}
.onChange(of: scenePhase) { (newScenePhase) in
switch newScenePhase {
case .background:
print("Scene is in the background")
//persistenceController.save()
case .inactive:
print("Scene is inactive")
case .active:
print("Scene is active")
@unknown default:
print("Apple must have changed something")
}
}
}
}

View file

@ -0,0 +1,16 @@
import Foundation
import CoreData
//extension NodeInfoEntity {
// @nonobjc public class func createFetchRequest() -> NSFetchRequest<NodeInfoEntity> {
// return NSFetchRequest<Commit>(entityName: "NodeInfoEntity")
// }
// @NSManaged public var id: UInt32
// @NSManaged public var num: UInt32
// @NSManaged public var sha: String
// @NSManaged public var url: String
//}

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="19461" systemVersion="21A559" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="NodeInfoEntity" representedClassName="NodeInfoEntity" syncable="YES"/>
<elements>
<element name="NodeInfoEntity" positionX="-27" positionY="18" width="128" height="29"/>
</elements>
</model>

View file

@ -0,0 +1,8 @@
# 1.27.8
* Update NodeList SwipeAction Button to be role: Destructive
* Added com.apple.security.files.user-selected.read-write entitlement to AppSandbox for MacOS for Mesh log download
* Cleaned up bluetooth connecting timeout errors and logic, run 10 2 second timers now

View file

@ -103,7 +103,6 @@ struct Connect: View {
Button(role: .destructive) {
if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.state == CBPeripheralState.connected
{
bleManager.disconnectDevice()
isPreferredRadio = false
}

View file

@ -14,8 +14,10 @@ struct Messages: View {
@State private var totalBytes = 0
@State private var lastTypingMessage = ""
@FocusState private var focusedField: Field?
@Namespace var topId
@Namespace var bottomId
@State var showDeleteMessageAlert = false
@State private var deleteMessageId : UInt32 = 0

View file

@ -65,17 +65,15 @@ struct NodeList: View {
}
}
.swipeActions {
Button {
let nodeIndex = bleManager.meshData.nodes.firstIndex(where: { $0.id == node.id })
bleManager.meshData.nodes.remove(at: nodeIndex!)
bleManager.meshData.save()
.swipeActions (edge: .trailing) {
Button (role: .destructive) {
let nodeIndex = bleManager.meshData.nodes.firstIndex(where: { $0.num == node.num })
bleManager.meshData.nodes.remove(at: nodeIndex!)
bleManager.meshData.save()
} label: {
Label("Delete from app", systemImage: "trash")
}
.tint(.red)
}
}
}
}
@ -83,6 +81,7 @@ struct NodeList: View {
.navigationTitle("All Nodes")
.onAppear(
perform: {
bleManager.meshData.load()
if UIDevice.current.userInterfaceIdiom == .pad {
if bleManager.meshData.nodes.count > 0 {
selection = "0"