| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- //
- // LoadingViewController.swift
- // App for Indeed
- //
- import Cocoa
- final class LoadingViewController: NSViewController {
- private let loadingView = LoadingView(frame: .zero)
- private var didStartLaunch = false
- private var didTransitionToDashboard = false
- override func loadView() {
- view = loadingView
- }
- override func viewDidAppear() {
- super.viewDidAppear()
- guard !didStartLaunch else { return }
- didStartLaunch = true
- if let window = view.window {
- AppWindowConfiguration.apply(to: window)
- }
- Task { @MainActor in
- await runLaunchSequence()
- transitionToDashboard()
- }
- }
- @MainActor
- private func runLaunchSequence() async {
- loadingView.setStatus("Starting up…", progress: 0.05)
- async let startup: Void = AppLaunchCoordinator.performStartup { [weak self] message, progress in
- self?.loadingView.setStatus(message, progress: progress)
- }
- async let minimumDisplay: Void = {
- try? await Task.sleep(nanoseconds: AppLaunchCoordinator.minimumDisplayNanoseconds)
- }()
- _ = await (startup, minimumDisplay)
- }
- @MainActor
- private func transitionToDashboard() {
- guard !didTransitionToDashboard, let window = view.window else { return }
- didTransitionToDashboard = true
- loadingView.stopAnimating()
- let dashboard = ViewController()
- NSAnimationContext.runAnimationGroup { context in
- context.duration = 0.32
- context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
- window.animator().contentViewController = dashboard
- } completionHandler: { [weak window] in
- guard let window else { return }
- AppWindowConfiguration.apply(to: window)
- window.center()
- }
- }
- }
|