SPB Git

Repository Public License

NightstandLaunch.swift 2.0 KB 44 lines swift

1// ORIX Alarm2// File: App/Features/Nightstand/NightstandLaunch.swift3// Description: Launch argument `-ORIXNightstandDemo YES`: opens Nightstand for the first enabled alarm and runs the compressed demo.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import Foundation89/// Screenshot and manual-test entry point.10///11/// `xcrun simctl launch <sim> ai.spboucher.orix.alarm -ORIXUITest YES -ORIXReset YES -ORIXDemo YES -ORIXNightstandDemo YES`12///13/// The app entry point belongs to another module owner, so this is armed from `Haptics.isEnabled` (which the app14/// model sets while it is created) and does nothing at all unless the launch argument is present. The clean15/// replacement is one explicit call to `NightstandLaunch.openIfRequested(model:)` after the demo data is loaded.16enum NightstandLaunch {17    static var isRequested: Bool { UserDefaults.standard.bool(forKey: "ORIXNightstandDemo") }18    /// Set when Nightstand was opened by the launch argument; the view consumes it and starts the demo.19    static var pendingDemo = false20    private static var isArmed = false2122    static func armIfRequested() {23        guard !isArmed, isRequested else { return }24        isArmed = true25        Task {26            // Wait for the model to exist, onboarding to be out of the way and the alarms to be loaded (demo data arrives asynchronously).27            for _ in 0..<100 {28                if let model = AppDependencies.model, openIfRequested(model: model) { return }29                try? await Task.sleep(for: .milliseconds(100))30            }31        }32    }3334    /// Opens Nightstand in demo mode when the launch argument is present. Returns false while there is no enabled alarm yet.35    @discardableResult36    static func openIfRequested(model: AppModel) -> Bool {37        guard isRequested, model.settings.hasCompletedOnboarding, let alarm = model.alarms.first(where: \.isEnabled) else { return false }38        isArmed = true39        pendingDemo = true40        model.nightstandAlarmID = alarm.id41        return true42    }43}44
Files main
Menu

Theme