Açıklama Yok

LoadingViewController.swift 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // LoadingViewController.swift
  3. // App for Indeed
  4. //
  5. import Cocoa
  6. final class LoadingViewController: NSViewController {
  7. private let loadingView = LoadingView(frame: .zero)
  8. private var didStartLaunch = false
  9. private var didTransitionToDashboard = false
  10. override func loadView() {
  11. view = loadingView
  12. }
  13. override func viewDidAppear() {
  14. super.viewDidAppear()
  15. guard !didStartLaunch else { return }
  16. didStartLaunch = true
  17. if let window = view.window {
  18. AppWindowConfiguration.apply(to: window)
  19. }
  20. Task { @MainActor in
  21. await runLaunchSequence()
  22. transitionToDashboard()
  23. }
  24. }
  25. @MainActor
  26. private func runLaunchSequence() async {
  27. loadingView.setStatus("Starting up…", progress: 0.05)
  28. async let startup: Void = AppLaunchCoordinator.performStartup { [weak self] message, progress in
  29. self?.loadingView.setStatus(message, progress: progress)
  30. }
  31. async let minimumDisplay: Void = {
  32. try? await Task.sleep(nanoseconds: AppLaunchCoordinator.minimumDisplayNanoseconds)
  33. }()
  34. _ = await (startup, minimumDisplay)
  35. }
  36. @MainActor
  37. private func transitionToDashboard() {
  38. guard !didTransitionToDashboard, let window = view.window else { return }
  39. didTransitionToDashboard = true
  40. loadingView.stopAnimating()
  41. let dashboard = ViewController()
  42. NSAnimationContext.runAnimationGroup { context in
  43. context.duration = 0.32
  44. context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
  45. window.animator().contentViewController = dashboard
  46. } completionHandler: { [weak window] in
  47. guard let window else { return }
  48. AppWindowConfiguration.apply(to: window)
  49. window.center()
  50. }
  51. }
  52. }