Repository Public
1// SP Notes iOS2// File: App/SPNotesApp.swift3// Description: Application entry point: builds the application model once, shows the root view and routes what comes from4// outside (links, Handoff, Spotlight) to it. Background work is scheduled when the app leaves the foreground.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import SwiftUI910@main11struct SPNotesApp: App {12 @UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate13 @State private var boot = Boot()14 @Environment(\.scenePhase) private var scenePhase1516 var body: some Scene {17 // The main window (several on iPad). Links and activities are received by `RootView`, which names its window.18 WindowGroup {19 root(.shell)20 }21 .commands { ShellCommands() }22 .onChange(of: scenePhase) { _, phase in23 if phase == .background { BackgroundSync.scheduleAll() }24 }2526 // One note in a window of its own (« Ouvrir dans une nouvelle fenêtre », ⌃⌘N): restored with its note after a relaunch.27 WindowGroup("Note", for: NoteWindowTarget.self) { $target in28 root(.noteWindow($target))29 }30 .commands { ShellCommands() }31 }3233 @ViewBuilder private func root(_ mode: SceneMode) -> some View {34 Group {35 switch boot.result {36 case .success(let model):37 RootView(mode: mode)38 .pencilDebugRoute() // DEBUG: SPNOTES_OPEN=pencil-… | pdf-… (Features/Drawing/PencilDebugRoutes.swift)39 .captureDebugRoute() // DEBUG: SPNOTES_OPEN=capture[:mode] | voice (Features/Capture/CaptureDebugRoutes.swift)40 .liveSeedMarker() // DEBUG: SPNOTES_LIVE_SEED=1 (App/LiveSeed.swift)41 .askRequestHost() // 2.0: « Demander à mes notes » (Siri, Shortcuts) — App/Intents/AskRequests.swift42 .environment(model)43 case .failure(let error): StoreFailureScreen(failure: StoreFailure(error)) { boot.retry() }44 }45 }46 .tint(Color.accentColor)47 }48}4950/// The model is created once per process; a failure to open the database is shown instead of crashing.51@MainActor52@Observable53final class Boot {54 private(set) var result: Result<AppModel, Error>55 /// `AppRuntime` owns the single model so intents and background tasks reach the same one.56 init() { result = AppRuntime.result }57 func retry() { result = AppRuntime.retry() }58}59