| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- //
- // 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(L("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()
- }
- }
- }
|