Cotton code
64 lines · 2.2 KB · SwiftRaw
// The splash's one way down, and the ceiling the fan's launch rule borrows.//// The boot gate itself is the core's (`shell.home`, boundary review move 5):// it decides the stage, the waits and where a refusal stands, and the app// draws what it answers (`CottonUI/Boot/BootModel.swift`).import Foundation/// The boot's ceiling, as the fan's launch rule waits it out/// (`FanLaunchRule`): the core's own is `shell_home::CEILING_MS`.public let AUTH_INIT_FALLBACK_MS = 5_000/// Take the splash down, ONCE, from whichever screen paints first.////// Three screens paint OUTSIDE any route — `ErrorFallback`,/// `ServerRefusalScreen` and `GateScreen` — and each hides the splash/// itself. Before this seam existed on the phone, neither of the first two did,/// so a boot-time error looked exactly like a hang: issue #15 was eleven/// launches across two TestFlight builds, each one an error screen nobody could/// see behind the constellation.////// It is a global rather than a member of the overlay because the caller is/// whichever screen wins the race, and "once" has to survive all of them/// asking. `@MainActor` so the flag needs no lock and the overlay's `withAnimation`/// runs where SwiftUI wants it.@MainActorpublic final class SplashState {    public static let shared = SplashState()    /// Observed by the overlay. False until somebody takes the splash down.    public private(set) var hidden = false    private var listeners: [@MainActor () -> Void] = []    private init() {}    public func onHidden(_ listener: @escaping @MainActor () -> Void) {        if hidden {            listener()            return        }        listeners.append(listener)    }    /// Fires exactly once and survives re-entry.    public func hideOnce() {        guard !hidden else { return }        hidden = true        let waiting = listeners        listeners = []        for listener in waiting { listener() }    }    /// Test seam only: the guard is process state.    public func resetForTests() {        hidden = false        listeners = []    }}/// Take the native splash down, once. The one call site rule of design P16.@MainActorpublic func hideSplashOnce() {    SplashState.shared.hideOnce()}