mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Clean up object graph updates
This commit is contained in:
parent
0d5f36d9cb
commit
1c19ae11e6
10 changed files with 43 additions and 39 deletions
|
|
@ -15,6 +15,10 @@ extension Date {
|
|||
func formattedDate(format: String) -> String {
|
||||
let dateformat = DateFormatter()
|
||||
dateformat.dateFormat = format
|
||||
return dateformat.string(from: self)
|
||||
if self > Calendar.current.date(byAdding: .year, value: -5, to: Date())! {
|
||||
return dateformat.string(from: self)
|
||||
} else {
|
||||
return "unknown.age".localized
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
@Published var isSwitchedOn: Bool = false
|
||||
@Published var automaticallyReconnect: Bool = true
|
||||
@Published var mqttProxyConnected: Bool = false
|
||||
|
||||
@StateObject var appState = AppState.shared
|
||||
public var minimumVersion = "2.0.0"
|
||||
public var connectedVersion: String
|
||||
public var isConnecting: Bool = false
|
||||
|
|
@ -516,6 +518,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
let version = decodedInfo.metadata.firmwareVersion[...(lastDotIndex ?? String.Index(utf16Offset: 6, in: decodedInfo.metadata.firmwareVersion))]
|
||||
nowKnown = true
|
||||
connectedVersion = String(version.dropLast())
|
||||
appState.firmwareVersion = connectedVersion
|
||||
}
|
||||
|
||||
let supportedVersion = connectedVersion == "0.0.0" || self.minimumVersion.compare(connectedVersion, options: .numeric) == .orderedAscending || minimumVersion.compare(connectedVersion, options: .numeric) == .orderedSame
|
||||
|
|
@ -718,7 +721,6 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
if toUserNum > 0 {
|
||||
newMessage.toUser = fetchedUsers.first(where: { $0.num == toUserNum })
|
||||
newMessage.toUser?.lastMessage = Date()
|
||||
newMessage.toUser?.objectWillChange.send()
|
||||
}
|
||||
newMessage.fromUser = fetchedUsers.first(where: { $0.num == fromUserNum })
|
||||
newMessage.isEmoji = isEmoji
|
||||
|
|
|
|||
|
|
@ -535,26 +535,26 @@ func routingPacket (packet: MeshPacket, connectedNodeNum: Int64, context: NSMana
|
|||
fetchedMessage![0].ackSNR = packet.rxSnr
|
||||
fetchedMessage![0].ackTimestamp = Int32(packet.rxTime)
|
||||
|
||||
if fetchedMessage![0].toUser != nil {
|
||||
fetchedMessage![0].toUser?.objectWillChange.send()
|
||||
} else {
|
||||
let fetchMyInfoRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: "MyInfoEntity")
|
||||
fetchMyInfoRequest.predicate = NSPredicate(format: "myNodeNum == %lld", connectedNodeNum)
|
||||
do {
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
|
||||
}
|
||||
}
|
||||
// if fetchedMessage![0].toUser != nil {
|
||||
// //fetchedMessage![0].toUser?.objectWillChange.send()
|
||||
// } else {
|
||||
// let fetchMyInfoRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: "MyInfoEntity")
|
||||
// fetchMyInfoRequest.predicate = NSPredicate(format: "myNodeNum == %lld", connectedNodeNum)
|
||||
// do {
|
||||
// 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()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
} else {
|
||||
return
|
||||
|
|
@ -765,7 +765,7 @@ func textMessageAppPacket(packet: MeshPacket, blockRangeTest: Bool, connectedNod
|
|||
messageSaved = true
|
||||
|
||||
if messageSaved {
|
||||
var appState = AppState.shared
|
||||
let appState = AppState.shared
|
||||
if newMessage.fromUser != nil && newMessage.toUser != nil && !(newMessage.fromUser?.mute ?? false) {
|
||||
// Set Unread Message Indicators
|
||||
if packet.to == connectedNode {
|
||||
|
|
|
|||
|
|
@ -124,5 +124,6 @@ class AppState: ObservableObject {
|
|||
@Published var tabSelection: Tab = .ble
|
||||
@Published var unreadDirectMessages: Int = 0
|
||||
@Published var unreadChannelMessages: Int = 0
|
||||
@Published var firmwareVersion: String = "0.0.0"
|
||||
@Published var connectedNode: NodeInfoEntity?
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ func upsertNodeInfoPacket (packet: MeshPacket, context: NSManagedObjectContext)
|
|||
print("💥 Error Inserting New Core Data MyInfoEntity: \(nsError)")
|
||||
}
|
||||
newNode.myInfo = myInfoEntity
|
||||
newNode.objectWillChange.send()
|
||||
//newNode.objectWillChange.send()
|
||||
|
||||
} else {
|
||||
// Update an existing node
|
||||
|
|
|
|||
|
|
@ -409,9 +409,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
}
|
||||
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
|
||||
switch view.annotation {
|
||||
case let positionAnnotation as PositionEntity:
|
||||
print(positionAnnotation)
|
||||
case let waypointAnnotation as WaypointEntity:
|
||||
case _ as WaypointEntity:
|
||||
// Only Allow Edit for waypoint annotations with a id
|
||||
if view.tag > 0 {
|
||||
parent.onWaypointEdit(view.tag)
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ struct ChannelMessageList: View {
|
|||
var maxbytes = 228
|
||||
@FocusState var focusedField: Field?
|
||||
|
||||
@StateObject var myInfo: MyInfoEntity
|
||||
@StateObject var channel: ChannelEntity
|
||||
@ObservedObject var myInfo: MyInfoEntity
|
||||
@ObservedObject var channel: ChannelEntity
|
||||
@State var showDeleteMessageAlert = false
|
||||
@State private var deleteMessageId: Int64 = 0
|
||||
@State private var replyMessageId: Int64 = 0
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ struct DeviceMetricsLog: View {
|
|||
.font(.caption)
|
||||
Text("\(String(format: "%.2f", dm.airUtilTx))%")
|
||||
.font(.caption)
|
||||
Text(dm.time?.formattedDate(format: dateFormatString) ?? "Unknown time")
|
||||
Text(dm.time?.formattedDate(format: dateFormatString) ?? "unknown.age".localized)
|
||||
.font(.caption)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,11 +64,9 @@ struct NodeDetail: View {
|
|||
waypointCoordinate = WaypointCoordinate(id: .init(), coordinate: nil, waypointId: Int64(wpId))
|
||||
}
|
||||
},
|
||||
// visibleMapRect: $mapRect,
|
||||
selectedMapLayer: selectedMapLayer,
|
||||
positions: lastTenThousand,
|
||||
waypoints: Array(waypoints),
|
||||
// mapViewType: mapType,
|
||||
userTrackingMode: MKUserTrackingMode.none,
|
||||
showNodeHistory: meshMapShowNodeHistory,
|
||||
showRouteLines: meshMapShowRouteLines,
|
||||
|
|
@ -221,10 +219,6 @@ struct NodeDetail: View {
|
|||
deviceConnected: bleManager.connectedPeripheral != nil,
|
||||
name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName : "?")
|
||||
})
|
||||
.onAppear {
|
||||
self.bleManager.context = context
|
||||
// mapType = .standard// MeshMapTypes(rawValue: meshMapType)?.MKMapTypeValue() ?? .standard
|
||||
}
|
||||
.task(id: node.num) {
|
||||
if !loadedWeather {
|
||||
do {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,11 @@ struct PositionLog: View {
|
|||
@State var exportString = ""
|
||||
var node: NodeInfoEntity
|
||||
@State private var isPresentingClearLogConfirm = false
|
||||
@State private var sortOrder = [KeyPathComparator(\PositionEntity.latitude)]
|
||||
//@State private var sortOrder = [KeyPathComparator(\PositionEntity.latitude)]
|
||||
|
||||
@State var sortOrder: [KeyPathComparator<PositionEntity>] = [
|
||||
.init(\.latitude, order: SortOrder.forward)
|
||||
]
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
let localeDateFormat = DateFormatter.dateFormat(fromTemplate: "yyMMddjmma", options: 0, locale: Locale.current)
|
||||
|
|
@ -27,7 +31,7 @@ struct PositionLog: View {
|
|||
if UIDevice.current.userInterfaceIdiom == .pad && !useGrid || UIDevice.current.userInterfaceIdiom == .mac {
|
||||
// Add a table for mac and ipad
|
||||
let positions = node.positions?.reversed() as? [PositionEntity] ?? []
|
||||
Table(positions) {
|
||||
Table(positions, sortOrder: $sortOrder) {
|
||||
TableColumn("Latitude") { position in
|
||||
Text(String(format: "%.5f", position.latitude ?? 0))
|
||||
}
|
||||
|
|
@ -58,6 +62,7 @@ struct PositionLog: View {
|
|||
}
|
||||
.width(min: 180)
|
||||
}
|
||||
|
||||
} else {
|
||||
ScrollView {
|
||||
// Use a grid on iOS as a table only shows a single column
|
||||
|
|
@ -97,7 +102,7 @@ struct PositionLog: View {
|
|||
.font(.caption2)
|
||||
Text(altitude.formatted())
|
||||
.font(.caption2)
|
||||
Text(mappin.time?.formattedDate(format: dateFormatString) ?? "Unknown time")
|
||||
Text(mappin.time?.formattedDate(format: dateFormatString) ?? "unknown.age".localized)
|
||||
.font(.caption2)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue