2022-12-28 09:37:16 +01:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2022 Marcin Czachurski and the repository contributors.
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
@main
|
2023-01-03 14:09:22 +01:00
|
|
|
struct VernissageApp: App {
|
2022-12-31 16:31:05 +01:00
|
|
|
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
|
|
|
|
|
|
|
let coreDataHandler = CoreDataHandler.shared
|
|
|
|
let applicationState = ApplicationState.shared
|
|
|
|
|
|
|
|
@State var applicationViewMode: ApplicationViewMode = .loading
|
2022-12-30 18:20:54 +01:00
|
|
|
|
2022-12-28 09:37:16 +01:00
|
|
|
var body: some Scene {
|
|
|
|
WindowGroup {
|
2022-12-29 17:27:15 +01:00
|
|
|
NavigationStack {
|
2022-12-31 16:31:05 +01:00
|
|
|
switch applicationViewMode {
|
|
|
|
case .loading:
|
2023-01-05 11:55:20 +01:00
|
|
|
// TODO: Loading splashscreen.
|
2022-12-31 16:31:05 +01:00
|
|
|
Text("Loading")
|
|
|
|
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 {
|
2023-01-03 14:09:22 +01:00
|
|
|
await AuthorizationService.shared.verifyAccount({ accountData in
|
|
|
|
guard let accountData = accountData else {
|
|
|
|
self.applicationViewMode = .signIn
|
|
|
|
return
|
|
|
|
}
|
2022-12-31 16:31:05 +01:00
|
|
|
|
|
|
|
self.applicationState.accountData = accountData
|
2023-01-03 14:09:22 +01:00
|
|
|
self.applicationViewMode = .mainView
|
|
|
|
})
|
2023-01-05 11:55:20 +01:00
|
|
|
|
|
|
|
URLCache.shared.memoryCapacity = 10_000_000 // ~10 MB memory space
|
|
|
|
URLCache.shared.diskCapacity = 1_000_000_000 // ~1GB disk cache space
|
2022-12-29 17:27:15 +01:00
|
|
|
}
|
|
|
|
.navigationViewStyle(.stack)
|
2022-12-28 09:37:16 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-31 16:31:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2022-12-28 09:37:16 +01:00
|
|
|
}
|