2021-08-18 22:33:05 -07:00
|
|
|
|
import SwiftUI
|
2021-11-28 17:03:03 -08:00
|
|
|
|
import CoreData
|
2021-08-18 22:33:05 -07:00
|
|
|
|
|
|
|
|
|
|
@main
|
|
|
|
|
|
struct MeshtasticClientApp: App {
|
2021-12-25 23:48:12 -08:00
|
|
|
|
|
2021-12-12 17:17:46 -08:00
|
|
|
|
let persistenceController = PersistenceController.shared
|
2021-12-25 23:48:12 -08:00
|
|
|
|
|
2021-12-12 17:17:46 -08:00
|
|
|
|
@ObservedObject private var bleManager: BLEManager = BLEManager.shared
|
2021-10-22 10:03:50 -07:00
|
|
|
|
@ObservedObject private var userSettings: UserSettings = UserSettings()
|
2021-11-29 21:11:27 -08:00
|
|
|
|
|
2021-11-04 08:36:55 -07:00
|
|
|
|
@Environment(\.scenePhase) var scenePhase
|
2021-11-29 21:11:27 -08:00
|
|
|
|
|
2021-08-18 22:33:05 -07:00
|
|
|
|
var body: some Scene {
|
|
|
|
|
|
WindowGroup {
|
2021-10-24 01:26:04 -07:00
|
|
|
|
ContentView()
|
2021-12-12 17:17:46 -08:00
|
|
|
|
.environment(\.managedObjectContext, persistenceController.container.viewContext)
|
2021-11-28 17:03:03 -08:00
|
|
|
|
.environmentObject(bleManager)
|
2021-12-16 22:45:18 -08:00
|
|
|
|
.environmentObject(userSettings)
|
2021-10-24 01:26:04 -07:00
|
|
|
|
}
|
2021-11-04 08:36:55 -07:00
|
|
|
|
.onChange(of: scenePhase) { (newScenePhase) in
|
|
|
|
|
|
switch newScenePhase {
|
|
|
|
|
|
case .background:
|
2021-12-24 21:50:10 -08:00
|
|
|
|
print("ℹ️ Scene is in the background")
|
2021-12-15 23:53:45 -08:00
|
|
|
|
do {
|
2021-12-25 23:48:12 -08:00
|
|
|
|
|
2021-12-15 23:53:45 -08:00
|
|
|
|
try persistenceController.container.viewContext.save()
|
2021-12-24 21:50:10 -08:00
|
|
|
|
print("💾 Saved CoreData ViewContext when the app went to the background.")
|
2021-12-25 23:48:12 -08:00
|
|
|
|
|
2021-12-15 23:53:45 -08:00
|
|
|
|
} catch {
|
2021-12-25 23:48:12 -08:00
|
|
|
|
|
2021-12-24 21:50:10 -08:00
|
|
|
|
print("💥 Failed to save viewContext when the app goes to the background.")
|
2021-12-15 23:53:45 -08:00
|
|
|
|
}
|
2021-11-04 08:36:55 -07:00
|
|
|
|
case .inactive:
|
2021-12-24 21:50:10 -08:00
|
|
|
|
print("ℹ️ Scene is inactive")
|
2021-11-04 08:36:55 -07:00
|
|
|
|
case .active:
|
2021-12-24 21:50:10 -08:00
|
|
|
|
print("ℹ️ Scene is active")
|
2021-11-04 08:36:55 -07:00
|
|
|
|
@unknown default:
|
2021-12-24 21:50:10 -08:00
|
|
|
|
print("💥 Apple must have changed something")
|
2021-11-04 08:36:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-08-18 22:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|