SPB Git

Repository Public License

ORIXScanApp.swift 8.4 KB 219 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Scan9// File             : App/Sources/Core/ORIXScanApp.swift10// Description      : App entry point: builds the app model, shows the root11//                    interface, applies App Lock and the privacy cover.12// Module           : Core13// Repository       : https://git.spboucher.ai/orix-scan14// Created          : 2026-11-2015// Last Modified    : 2026-11-2016//17// =============================================================================18// AUTHOR & PROFESSIONAL AFFILIATION19// =============================================================================20//21// Author           : Simon-Pierre Boucher22// Position         : Professor of Finance23// Institution      : Université du Québec en Outaouais (UQO)24// Department       : Département des sciences administratives25// Organization     : SP Boucher26//27// Website          : https://spboucher.ai28// Git              : https://git.spboucher.ai29//30// =============================================================================31// OFFICIAL CONTACT DIRECTORY32// =============================================================================33//34// General          : info@spboucher.ai35// Professional     : contact@spboucher.ai36// Direct           : simon@spboucher.ai37// Research         : research@spboucher.ai38// Development      : dev@spboucher.ai39// Support          : support@spboucher.ai40// Security/Admin   : admin@spboucher.ai41// Notifications    : notifications@spboucher.ai42//43// Preferred Contact: support@spboucher.ai44//45// =============================================================================46// COPYRIGHT & INTELLECTUAL PROPERTY47// =============================================================================48//49// Copyright (c) 202650// Simon-Pierre Boucher51//52// All rights reserved where applicable.53//54// This file is governed by the applicable project license,55// copyright notices, institutional agreements and relevant law.56//57// Unless expressly authorized by the applicable license or58// rights holder, copying, redistribution, sublicensing,59// publication and commercial exploitation are not permitted.60//61// Existing third-party rights and notices remain unaffected.62//63// =============================================================================64// CONFIDENTIALITY & SECURITY65// =============================================================================66//67// Classification   : Public68// Distribution     : Public repository; use is governed by the project license69// Security Contact : admin@spboucher.ai70//71// Access to this source does not independently grant permission72// to redistribute or disclose confidential materials.73//74// Do not embed credentials, private keys, access tokens,75// certificates or confidential personal information.76//77// =============================================================================78// LICENSE & MAINTENANCE79// =============================================================================80//81// License          : Proprietary, all rights reserved (see license file)82// License File     : LICENSE83// Maintainer       : Simon-Pierre Boucher84// Technical Contact: dev@spboucher.ai85//86// =============================================================================87// END OF SP BOUCHER SOURCE HEADER88// =============================================================================8990import ORIXDesign91import ORIXKit92import SwiftData93import SwiftUI9495@main96struct ORIXScanApp: App {97    @State private var boot = Boot()98    @State private var lock = AppLock()99    @Environment(\.scenePhase) private var scenePhase100101    var body: some Scene {102        WindowGroup {103            Group {104                if let model = boot.model {105                    RootView()106                        .environment(model)107                        .modelContainer(model.container)108                        .overlay { if lock.isLocked { LockScreen(lock: lock) } }109                        .overlay { if scenePhase != .active && model.settings.appLock { PrivacyCover() } }110                        .task {111                            lock.lockIfEnabled(model.settings.appLock)112                            await lock.unlock()113                        }114                        .onChange(of: scenePhase) { old, new in115                            if new == .background { lock.lockIfEnabled(model.settings.appLock) }116                            if new == .active && old != .active { Task { await lock.unlock() } }117                        }118                        .onReceive(NotificationCenter.default.publisher(for: AppRequests.scan)) { _ in model.request(.scan) }119                } else if let failure = boot.failure {120                    ORIXEmptyState(systemName: "externaldrive.badge.exclamationmark", title: "Storage Unavailable",121                                   message: "ORIX Scan could not open its document storage. Your files were not changed. Restart the app, and free up space if the device is full.") {122                        Text(failure).font(.orixMono).foregroundStyle(ORIX.Palette.textTertiary)123                    }124                } else {125                    LaunchView()126                }127            }128            .environment(\.orixAccent, .scan)129            .tint(ORIXAccent.scan.primary)130            .task { await boot.start() }131        }132        .commands {133            CommandGroup(replacing: .newItem) {134                Button("Scan Document") { boot.model?.request(.scan) }.keyboardShortcut("n", modifiers: .command)135                Button("Import Photos…") { boot.model?.request(.photos) }.keyboardShortcut("p", modifiers: [.command, .shift])136                Button("Import Files…") { boot.model?.request(.files) }.keyboardShortcut("i", modifiers: [.command, .shift])137            }138            CommandGroup(after: .sidebar) {139                Button("Library") { boot.model?.router.showLibrary() }.keyboardShortcut("1", modifiers: .command)140                Button("ORIX Actions") { boot.model?.router.showActions() }.keyboardShortcut("2", modifiers: .command)141            }142        }143    }144}145146/// Requests coming from outside the interface (App Intents).147enum AppRequests {148    static let scan = Notification.Name("ai.spboucher.orix.scan.request-scan")149}150151@Observable152final class Boot {153    var model: AppModel?154    var failure: String?155    private var started = false156157    func start() async {158        guard !started else { return }159        started = true160        do {161            #if DEBUG162            let model = try DemoContent.makeModel()163            #else164            let model = try AppModel()165            #endif166            await model.start()167            #if DEBUG168            await DemoContent.seedIfRequested(model)169            #endif170            self.model = model171        } catch {172            failure = String(describing: type(of: error))173        }174    }175}176177private struct LaunchView: View {178    var body: some View {179        ZStack {180            ORIX.Palette.canvas.ignoresSafeArea()181            ORIXMark().frame(width: 120)182        }183    }184}185186/// Hides document content in the app switcher when App Lock is on.187private struct PrivacyCover: View {188    var body: some View {189        ZStack {190            ORIX.Palette.canvas.ignoresSafeArea()191            ORIXMark().frame(width: 96)192        }193        .accessibilityHidden(true)194    }195}196197private struct LockScreen: View {198    let lock: AppLock199200    var body: some View {201        ZStack {202            ORIX.Palette.canvas.ignoresSafeArea()203            VStack(spacing: ORIX.Space.lg) {204                ORIXMark().frame(width: 96)205                VStack(spacing: ORIX.Space.xs) {206                    Text("ORIX Scan Is Locked").font(.orixTitle)207                    Text("Unlock to see your documents.").font(.orixCallout).foregroundStyle(ORIX.Palette.textSecondary)208                }209                Button { Task { await lock.unlock() } } label: { Label("Unlock", systemImage: "lock.open") }210                    .buttonStyle(.orixPrimary)211                    .frame(maxWidth: 260)212                    .disabled(lock.isAuthenticating)213                    .accessibilityIdentifier("lock.unlock")214            }215            .padding(ORIX.Space.xl)216        }217    }218}219
Files main
Menu

Theme