Repository Public
1import MCCCore2import SwiftUI34/// The main window: launch state, sign-in, invitation setup, lock, or the cockpit.5struct RootView: View {6 enum Screen: Equatable { case starting, setup, signIn, locked, main }78 @Environment(AppModel.self) private var app9 @Environment(\.mccTheme) private var theme10 @State private var shown: Screen?1112 private var target: Screen {13 if app.invitation != nil { return .setup }14 switch app.session.phase {15 case .starting: return .starting16 case .signedOut: return .signIn17 case .signedIn: return app.lock.isLocked ? .locked : .main18 }19 }2021 var body: some View {22 Group {23 switch shown ?? target {24 case .setup:25 if let invitation = app.invitation { InvitationSetupView(model: invitation) } else { ProgressView() }26 case .starting:27 ProgressView(tr("state.loading")).frame(maxWidth: .infinity, maxHeight: .infinity)28 case .signIn:29 SignInView()30 case .locked:31 LockView()32 case .main:33 MainWindowView()34 }35 }36 .frame(maxWidth: .infinity, maxHeight: .infinity)37 .background(theme.canvas)38 .errorAlert(app)39 // A whole screen is never replaced from inside the click that causes it: on macOS 27.0 that left AppKit with40 // a tracking area whose owner was gone, and the next mouse move crashed in41 // -[NSTrackingArea _dispatchMouseEntered:]. The swap happens a moment later, outside event dispatch.42 .task(id: target) {43 if shown == nil { shown = target; return }44 try? await Task.sleep(for: .milliseconds(150))45 shown = target46 }47 }48}49