mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Merge pull request #1297 from meshtastic/minor-fixes
Reduce Dependency on BLEManager by moving context to @Environment in WaypointForm
This commit is contained in:
commit
3c996e2abc
2 changed files with 15 additions and 14 deletions
|
|
@ -15,7 +15,7 @@ import OSLog
|
|||
import ActivityKit
|
||||
#endif
|
||||
|
||||
// Simple extension to consicely pass values through a has_XXX boolean check
|
||||
// Simple extension to concisely pass values through a has_XXX boolean check
|
||||
fileprivate extension Bool {
|
||||
func then<T>(_ value: T) -> T? {
|
||||
self ? value : nil
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import SwiftUI
|
|||
struct WaypointForm: View {
|
||||
|
||||
@EnvironmentObject var bleManager: BLEManager
|
||||
@Environment(\.managedObjectContext) var context
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@State var waypoint: WaypointEntity
|
||||
let distanceFormatter = MKDistanceFormatter()
|
||||
|
|
@ -210,11 +211,11 @@ struct WaypointForm: View {
|
|||
|
||||
Menu {
|
||||
Button("For me", action: {
|
||||
bleManager.context.delete(waypoint)
|
||||
context.delete(waypoint)
|
||||
do {
|
||||
try bleManager.context.save()
|
||||
try context.save()
|
||||
} catch {
|
||||
bleManager.context.rollback()
|
||||
context.rollback()
|
||||
}
|
||||
dismiss() })
|
||||
Button("For everyone", action: {
|
||||
|
|
@ -239,11 +240,11 @@ struct WaypointForm: View {
|
|||
newWaypoint.expire = UInt32(1)
|
||||
if bleManager.sendWaypoint(waypoint: newWaypoint) {
|
||||
|
||||
bleManager.context.delete(waypoint)
|
||||
context.delete(waypoint)
|
||||
do {
|
||||
try bleManager.context.save()
|
||||
try context.save()
|
||||
} catch {
|
||||
bleManager.context.rollback()
|
||||
context.rollback()
|
||||
}
|
||||
dismiss()
|
||||
} else {
|
||||
|
|
@ -384,11 +385,11 @@ struct WaypointForm: View {
|
|||
}
|
||||
.alert("Waypoint Failed to Send", isPresented: $waypointFailedAlert) {
|
||||
Button("OK", role: .cancel) {
|
||||
bleManager.context.delete(waypoint)
|
||||
context.delete(waypoint)
|
||||
do {
|
||||
try bleManager.context.save()
|
||||
try context.save()
|
||||
} catch {
|
||||
bleManager.context.rollback()
|
||||
context.rollback()
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
|
|
@ -396,18 +397,18 @@ struct WaypointForm: View {
|
|||
.onDisappear {
|
||||
if waypoint.id == 0 {
|
||||
// New, unsent waypoint created by the user: delete it
|
||||
bleManager.context.delete(waypoint)
|
||||
context.delete(waypoint)
|
||||
do {
|
||||
try bleManager.context.save()
|
||||
try context.save()
|
||||
} catch {
|
||||
bleManager.context.rollback()
|
||||
context.rollback()
|
||||
Logger.mesh.error("Failed to save context on waypoint deletion: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
if waypoint.id > 0 {
|
||||
let waypoint = getWaypoint(id: Int64(waypoint.id), context: bleManager.context)
|
||||
let waypoint = getWaypoint(id: Int64(waypoint.id), context: context)
|
||||
name = waypoint.name ?? "Dropped Pin"
|
||||
description = waypoint.longDescription ?? ""
|
||||
icon = String(UnicodeScalar(Int(waypoint.icon)) ?? "📍")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue