Sesame-iOS/Sesame-Watch Watch App/Sesame_WatchApp.swift
2023-12-27 21:57:17 +01:00

53 lines
1.4 KiB
Swift

import SwiftUI
import SwiftData
private enum MainScreenSelection: Int {
case unlock = 0
case settings = 1
case history = 2
}
@main
struct SesameWatchApp: App {
@State
var modelContainer: ModelContainer
@ObservedObject
var coordinator: RequestCoordinator
let keyManagement = KeyManagement()
@State
private var selectedScreen: MainScreenSelection = .unlock
@State
var didLaunchFromComplication = false
init() {
let modelContainer = SesameWatchApp.loadModelContainer()
self.modelContainer = modelContainer
self.coordinator = .init(modelContext: modelContainer.mainContext)
}
var body: some Scene {
WindowGroup {
TabView(selection: $selectedScreen) {
ContentView(coordinator: coordinator, didLaunchFromComplication: $didLaunchFromComplication)
.tag(MainScreenSelection.unlock)
SettingsView()
.environmentObject(keyManagement)
.tag(MainScreenSelection.settings)
HistoryView()
.tag(MainScreenSelection.history)
}
.tabViewStyle(PageTabViewStyle())
.onOpenURL { url in
didLaunchFromComplication = true
selectedScreen = .unlock
}
}
.modelContainer(modelContainer)
}
}