forked from fritob/Camper-Monitor
32 lines
927 B
Swift
32 lines
927 B
Swift
import SwiftUI
|
|
|
|
@main
|
|
struct CamperMonitorApp: App {
|
|
@State private var store: DeviceStore
|
|
@State private var bluetooth: BluetoothManager
|
|
@Environment(\.scenePhase) private var scenePhase
|
|
|
|
init() {
|
|
let store = DeviceStore()
|
|
_store = State(initialValue: store)
|
|
_bluetooth = State(initialValue: BluetoothManager(store: store))
|
|
}
|
|
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
DashboardView()
|
|
.environment(store)
|
|
.environment(bluetooth)
|
|
}
|
|
.onChange(of: scenePhase) { _, phase in
|
|
// Im Hintergrund darf ohne Service-Filter ohnehin nicht gescannt
|
|
// werden, also Funk sparen und beim Zurückkommen neu starten.
|
|
switch phase {
|
|
case .active: bluetooth.start()
|
|
case .background: bluetooth.stop()
|
|
default: break
|
|
}
|
|
}
|
|
}
|
|
}
|