Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP ID & Card Vault7// File : SPVault/App/RootView.swift8// Module : SPVault9// Repository : https://git.spboucher.ai/sp-id-card-vault10// Project Website : Not specified11// Created : 2026-12-0212// Last Modified : 2026-12-0213//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI4243/// Top of the view tree. What is shown depends only on the vault state, so no44/// navigation path can reach card content while the vault is locked: the45/// unlocked shell is removed from the hierarchy (with every sheet it presented)46/// the moment the key is dropped.47struct RootView: View {48 @Environment(AppEnvironment.self) private var environment49 @Environment(Vault.self) private var vault50 @Environment(AppSettings.self) private var settings51 @Environment(\.scenePhase) private var scenePhase52 @Environment(\.isSceneCaptured) private var isSceneCaptured53 @Environment(\.accessibilityReduceMotion) private var reduceMotion54 @State private var splashFinished = false5556 var body: some View {57 ZStack {58 VaultBackground()59 content60 }61 .animation(reduceMotion ? SP.Motion.reduced : SP.Motion.card, value: vault.state)62 .animation(SP.Motion.gentle, value: splashFinished)63 .tint(SP.Palette.electric)64 .preferredColorScheme(settings.appearance.colorScheme)65 .onChange(of: scenePhase) { _, phase in66 // Immediate lock: the key and every decrypted byte are dropped as soon67 // as the app is in the background.68 if phase == .background {69 if vault.isUnlocked { Haptics.shared.play(.lock) }70 vault.lock()71 }72 }73 .onChange(of: isSceneCaptured, initial: true) { _, captured in environment.privacy.setCaptured(captured) }74 .task {75 environment.privacy.start()76 vault.bootstrap()77 #if DEBUG78 await environment.seedDemoVault()79 #endif80 try? await Task.sleep(for: .milliseconds(environment.launch.isUITesting ? 50 : 900))81 splashFinished = true82 }83 }8485 @ViewBuilder86 private var content: some View {87 if !splashFinished || vault.state == .loading {88 SplashView().transition(.opacity)89 } else {90 switch vault.state {91 case .loading: EmptyView()92 case .noVault: OnboardingView().transition(.opacity)93 case .locked, .keyInvalidated: LockScreenView().transition(.opacity)94 case .unlocked:95 MainShellView()96 .transition(reduceMotion ? .opacity : .asymmetric(insertion: .scale(scale: 1.04).combined(with: .opacity), removal: .opacity))97 }98 }99 }100}101102struct SplashView: View {103 @State private var appeared = false104 @Environment(\.accessibilityReduceMotion) private var reduceMotion105106 var body: some View {107 VStack(spacing: SP.Space.xl) {108 VaultMark(size: 132, openness: appeared ? 0 : 1)109 .scaleEffect(appeared || reduceMotion ? 1 : 0.9)110 .opacity(appeared ? 1 : 0)111 VStack(spacing: SP.Space.xs) {112 Text("SP Vault").font(.spDisplay).foregroundStyle(SP.Palette.textPrimary)113 Text("ID & Card Vault").spEyebrow()114 }115 .opacity(appeared ? 1 : 0)116 }117 .frame(maxWidth: .infinity, maxHeight: .infinity)118 .onAppear { withAnimation(reduceMotion ? SP.Motion.reduced : .spring(response: 0.8, dampingFraction: 0.8)) { appeared = true } }119 .accessibilityElement(children: .ignore)120 .accessibilityLabel("SP Vault")121 }122}123