Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP ID & Card Vault7// File : SPVault/Features/Settings/SettingsView.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/// Settings tab. Interface preferences only; nothing here weakens the vault,44/// and the lock-on-background rule has no switch.45struct SettingsView: View {46 @Environment(Vault.self) private var vault47 @Environment(AppEnvironment.self) private var environment48 @Environment(AppSettings.self) private var settings49 @Environment(AppRouter.self) private var router5051 @State private var showsErase = false52 @State private var notice: String?5354 var body: some View {55 @Bindable var settings = settings56 @Bindable var router = router57 NavigationStack(path: $router.settingsPath) {58 ScreenScaffold(eyebrow: "SP Vault", title: "Settings") {59 PanelSection("Appearance") {60 labelled("Theme") {61 ChoiceChips(options: AppearanceChoice.allCases.map { ($0, $0.title, nil) }, selection: $settings.appearance, identifierPrefix: "settings.appearance")62 }63 Hairline().padding(.leading, SP.Space.m)64 labelled("Wallet layout") {65 ChoiceChips(options: WalletLayout.allCases.map { ($0, $0.title, nil) }, selection: $settings.walletLayout, identifierPrefix: "settings.layout")66 }67 Hairline().padding(.leading, SP.Space.m)68 labelled("Card rendering", caption: settings.renderMode == .premium69 ? "Premium adds light, depth and perspective on top of the photograph."70 : "Original shows the corrected photograph with nothing added.") {71 ChoiceChips(options: CardRenderMode.allCases.map { ($0, $0.title, nil) }, selection: $settings.renderMode, identifierPrefix: "settings.render")72 }73 }7475 PanelSection("Privacy & feel") {76 ToggleRow(symbol: "eye.slash.fill", title: "Privacy Mode", caption: "Veil card faces in lists until a card is opened.",77 identifier: "settings.privacyMode", isOn: $settings.privacyMode)78 ToggleRow(symbol: "camera.viewfinder", title: "Screenshot alerts", caption: "Tell me when a screenshot is taken while the vault is open.",79 identifier: "settings.screenshotAlerts", isOn: $settings.screenshotAlerts)80 ToggleRow(symbol: "iphone.radiowaves.left.and.right", title: "Haptics", caption: "Tactile feedback for unlocking, flipping and capturing.",81 identifier: "settings.haptics", isOn: $settings.hapticsEnabled)82 ToggleRow(symbol: "gyroscope", title: "Motion effects", caption: "Reflections that follow the tilt of the iPhone. Always off with Reduce Motion.",83 showsDivider: false, identifier: "settings.motion", isOn: $settings.motionEffects)84 }8586 PanelSection("Expiry reminders") {87 ToggleRow(symbol: "bell.fill", title: "Reminders", caption: "Local notifications with generic text.",88 identifier: "settings.reminders", isOn: $settings.remindersEnabled)89 labelled("Default reminders for new cards", caption: "Days before expiry.") {90 ReminderOffsetChips(offsets: $settings.defaultReminderOffsets, identifierPrefix: "settings.offset")91 }92 Hairline().padding(.leading, SP.Space.m)93 labelled("“Expiring soon” window") {94 ChoiceChips(options: [30, 60, 90, 180].map { ($0, "\($0) d", nil) }, selection: $settings.expiringSoonDays, identifierPrefix: "settings.soon")95 }96 }9798 PanelSection("Vault") {99 ActionRow(symbol: "lock.doc.fill", tint: SP.Palette.electric, title: "Backup & Restore",100 caption: vault.lastBackupAt.map { "Last backup \($0.spShort)" } ?? "No backup yet", identifier: "settings.backup") { router.settingsPath = [.backup] }101 ActionRow(symbol: "folder.fill", title: "Categories",102 value: "\(vault.categories.count)", identifier: "settings.categories") { router.settingsPath = [.categories] }103 ActionRow(symbol: "checkmark.shield.fill", title: "Security Center", identifier: "settings.security") { router.tab = .security }104 ActionRow(symbol: "info.circle.fill", title: "About SP Vault", showsDivider: false, identifier: "settings.about") { router.settingsPath = [.about] }105 }106107 VStack(alignment: .leading, spacing: SP.Space.s) {108 SectionHeader("Danger zone")109 VStack(alignment: .leading, spacing: SP.Space.s) {110 Text("Erase this vault").font(.spHeadline).foregroundStyle(SP.Palette.textPrimary)111 Text("Deletes every card, photograph and key from this iPhone. Asks for Face ID, then a typed confirmation.")112 .font(.spCaption).foregroundStyle(SP.Palette.textSecondary).fixedSize(horizontal: false, vertical: true)113 if let notice { NoticeView(tone: .warning, symbol: "faceid", title: nil, message: notice) }114 Button("Erase vault…") {115 Task {116 if await vault.reauthenticate(reason: "Confirm it is you before erasing the vault") { notice = nil; showsErase = true }117 else { notice = "Face ID did not confirm. Nothing was erased." }118 }119 }120 .buttonStyle(.spDestructive)121 .accessibilityIdentifier("settings.erase")122 }123 .spPanel()124 }125 }126 .navigationDestination(for: SettingsRoute.self) { route in127 switch route {128 case .backup: BackupRestoreView()129 case .categories: CategoriesView()130 case .about: AboutView()131 }132 }133 }134 .onChange(of: settings.remindersEnabled) { environment.reminders.reschedule(for: vault.cards) }135 .sheet(isPresented: $showsErase) {136 TypedConfirmationSheet(title: "Erase this vault",137 message: "Every card, photograph and key is deleted from this iPhone. This cannot be undone. Export a backup first if you want to keep anything.",138 word: "ERASE", actionTitle: "Erase everything") {139 Haptics.shared.play(.warning)140 vault.eraseEverything()141 }142 }143 }144145 private func labelled<Control: View>(_ title: String, caption: String? = nil, @ViewBuilder control: () -> Control) -> some View {146 VStack(alignment: .leading, spacing: SP.Space.xs) {147 Text(title).font(.spBody.weight(.medium)).foregroundStyle(SP.Palette.textPrimary)148 control()149 if let caption {150 Text(caption).font(.spCaption).foregroundStyle(SP.Palette.textSecondary).fixedSize(horizontal: false, vertical: true)151 }152 }153 .padding(SP.Space.m)154 }155}156