mirror of
https://github.com/VernissageApp/Vernissage.git
synced 2024-12-28 18:00:53 +01:00
68 lines
2.5 KiB
Swift
68 lines
2.5 KiB
Swift
//
|
|
// https://mczachurski.dev
|
|
// Copyright © 2022 Marcin Czachurski and the repository contributors.
|
|
// Licensed under the MIT License.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
@main
|
|
struct VernissageApp: App {
|
|
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
|
|
|
let coreDataHandler = CoreDataHandler.shared
|
|
let applicationState = ApplicationState.shared
|
|
|
|
@State var applicationViewMode: ApplicationViewMode = .loading
|
|
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
NavigationStack {
|
|
switch applicationViewMode {
|
|
case .loading:
|
|
LoadingView()
|
|
case .signIn:
|
|
SignInView { viewMode in
|
|
applicationViewMode = viewMode
|
|
}
|
|
.environment(\.managedObjectContext, coreDataHandler.container.viewContext)
|
|
.environmentObject(applicationState)
|
|
case .mainView:
|
|
MainView()
|
|
.environment(\.managedObjectContext, coreDataHandler.container.viewContext)
|
|
.environmentObject(applicationState)
|
|
}
|
|
}
|
|
.task {
|
|
await AuthorizationService.shared.verifyAccount({ accountData in
|
|
guard let accountData = accountData else {
|
|
self.applicationViewMode = .signIn
|
|
return
|
|
}
|
|
|
|
self.applicationState.accountData = accountData
|
|
self.applicationViewMode = .mainView
|
|
})
|
|
}
|
|
.navigationViewStyle(.stack)
|
|
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in
|
|
try? HapticService.shared.start()
|
|
}
|
|
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in
|
|
HapticService.shared.stop()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class AppDelegate: NSObject, UIApplicationDelegate {
|
|
func application(_ application: UIApplication,
|
|
configurationForConnecting connectingSceneSession: UISceneSession,
|
|
options: UIScene.ConnectionOptions
|
|
) -> UISceneConfiguration {
|
|
let sceneConfig: UISceneConfiguration = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role)
|
|
sceneConfig.delegateClass = SceneDelegate.self
|
|
return sceneConfig
|
|
}
|
|
}
|