Sesame-iOS/Sesame-Watch Watch App/Sesame_WatchApp.swift

53 lines
1.4 KiB
Swift
Raw Normal View History

2023-08-07 15:57:09 +02:00
import SwiftUI
2023-12-12 17:33:42 +01:00
import SwiftData
2023-08-07 15:57:09 +02:00
2023-12-27 21:57:17 +01:00
private enum MainScreenSelection: Int {
case unlock = 0
case settings = 1
case history = 2
}
2023-08-07 15:57:09 +02:00
@main
2023-12-27 21:57:17 +01:00
struct SesameWatchApp: App {
2023-08-07 15:57:09 +02:00
2023-12-12 17:33:42 +01:00
@State
var modelContainer: ModelContainer
@ObservedObject
var coordinator: RequestCoordinator
2023-08-07 15:57:09 +02:00
let keyManagement = KeyManagement()
@State
2023-12-27 21:57:17 +01:00
private var selectedScreen: MainScreenSelection = .unlock
@State
var didLaunchFromComplication = false
2023-08-07 15:57:09 +02:00
2023-12-12 17:33:42 +01:00
init() {
2023-12-27 21:57:17 +01:00
let modelContainer = SesameWatchApp.loadModelContainer()
self.modelContainer = modelContainer
self.coordinator = .init(modelContext: modelContainer.mainContext)
2023-12-12 17:33:42 +01:00
}
2023-08-07 15:57:09 +02:00
var body: some Scene {
WindowGroup {
2023-12-27 21:57:17 +01:00
TabView(selection: $selectedScreen) {
2023-12-12 17:33:42 +01:00
ContentView(coordinator: coordinator, didLaunchFromComplication: $didLaunchFromComplication)
2023-12-27 21:57:17 +01:00
.tag(MainScreenSelection.unlock)
2023-08-07 15:57:09 +02:00
SettingsView()
2023-08-09 16:29:18 +02:00
.environmentObject(keyManagement)
2023-12-27 21:57:17 +01:00
.tag(MainScreenSelection.settings)
2023-12-12 17:33:42 +01:00
HistoryView()
2023-12-27 21:57:17 +01:00
.tag(MainScreenSelection.history)
2023-08-07 15:57:09 +02:00
}
.tabViewStyle(PageTabViewStyle())
.onOpenURL { url in
didLaunchFromComplication = true
2023-12-27 21:57:17 +01:00
selectedScreen = .unlock
}
2023-08-07 15:57:09 +02:00
}
2023-12-12 17:33:42 +01:00
.modelContainer(modelContainer)
2023-08-07 15:57:09 +02:00
}
}