Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Apps/Shared/AppBootstrap.swift3// Description: Creates the shared AppModel for both apps and shows a clear failure screen when storage cannot be opened.4import SwiftUI5import LocalChatUI67struct AppBootstrap {8 let model: AppModel?9 let failure: String?1011 @MainActor static func make() -> AppBootstrap {12 let arguments = ProcessInfo.processInfo.arguments13 do {14 // UI tests and screenshots run on a throw-away store (never the user's data)15 if arguments.contains("-LCEphemeral") { return AppBootstrap(model: try AppModel(ephemeral: true), failure: nil) }16 if let index = arguments.firstIndex(of: "-LCRoot"), arguments.indices.contains(index + 1) {17 return AppBootstrap(model: try AppModel(root: URL(fileURLWithPath: arguments[index + 1])), failure: nil)18 }19 return AppBootstrap(model: try AppModel(), failure: nil)20 } catch {21 return AppBootstrap(model: nil, failure: error.localizedDescription)22 }23 }2425 @MainActor @ViewBuilder static func root(_ bootstrap: AppBootstrap) -> some View {26 if let model = bootstrap.model {27 RootView().environment(model)28 } else {29 VStack(spacing: 12) {30 Image(systemName: "externaldrive.badge.xmark").font(.system(size: 40)).foregroundStyle(.red)31 Text("Local Chat could not open its storage").font(.title2.bold())32 Text(bootstrap.failure ?? "Unknown error").font(.callout).foregroundStyle(.secondary).multilineTextAlignment(.center)33 }34 .padding(40).frame(maxWidth: .infinity, maxHeight: .infinity)35 }36 }37}38