first commit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct CamperMonitorApp: App {
|
||||
@State private var store: DeviceStore
|
||||
@State private var bluetooth: BluetoothManager
|
||||
@State private var watch: PhoneWatchLink
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
|
||||
init() {
|
||||
let store = DeviceStore()
|
||||
let bluetooth = BluetoothManager(store: store)
|
||||
_store = State(initialValue: store)
|
||||
_bluetooth = State(initialValue: bluetooth)
|
||||
_watch = State(initialValue: PhoneWatchLink(store: store, bluetooth: bluetooth))
|
||||
}
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
DashboardView()
|
||||
.environment(store)
|
||||
.environment(bluetooth)
|
||||
.environment(watch)
|
||||
.task { watch.activate() }
|
||||
}
|
||||
.onChange(of: scenePhase) { _, phase in
|
||||
// Im Hintergrund darf ohne Service-Filter ohnehin nicht gescannt
|
||||
// werden, also Funk sparen und beim Zurückkommen neu starten.
|
||||
//
|
||||
// Ausnahme: Solange jemand auf die Uhr schaut, läuft es weiter. Beim
|
||||
// Rangieren liegt das iPhone in der Halterung mit dunklem Bildschirm
|
||||
// – hörte das Funkgerät dann auf, wäre die Anzeige am Handgelenk
|
||||
// genau dann tot, wenn sie gebraucht wird. Die verbundenen Geräte
|
||||
// (Neigungsmesser, BMS, Kühlbox) liefern im Hintergrund weiter; die
|
||||
// Victron-Werbedaten nicht, dafür müsste ohne Filter gesucht werden.
|
||||
watch.isAppInBackground = phase != .active
|
||||
switch phase {
|
||||
case .active:
|
||||
bluetooth.start()
|
||||
case .background:
|
||||
if !watch.wantsLiveUpdates { bluetooth.stop() }
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user