SPB Git

Repository Public

AppSettings.swift 5.5 KB 126 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP ID & Card Vault7// File             : SPVault/App/AppSettings.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 Observation42import SwiftUI4344enum AppearanceChoice: String, CaseIterable, Identifiable, Sendable {45    case system, dark, light46    var id: String { rawValue }47    var title: String { rawValue.capitalized }48    var colorScheme: ColorScheme? {49        switch self {50        case .system: nil51        case .dark: .dark52        case .light: .light53        }54    }55}5657enum WalletLayout: String, CaseIterable, Identifiable, Sendable {58    case stack, carousel, grid, categories59    var id: String { rawValue }60    var title: String {61        switch self {62        case .stack: "Stack"63        case .carousel: "Carousel"64        case .grid: "Grid"65        case .categories: "Categories"66        }67    }68    var symbol: String {69        switch self {70        case .stack: "rectangle.stack.fill"71        case .carousel: "rectangle.split.3x1.fill"72        case .grid: "square.grid.2x2.fill"73        case .categories: "folder.fill"74        }75    }76}7778enum CardRenderMode: String, CaseIterable, Identifiable, Sendable {79    /// The corrected photograph, nothing added.80    case original81    /// The photograph with depth, light and perspective.82    case premium83    var id: String { rawValue }84    var title: String { rawValue.capitalized }85}8687/// Interface preferences. Nothing here is sensitive: it is stored in88/// `UserDefaults` and never describes a card.89@MainActor90@Observable91final class AppSettings {92    nonisolated static let reminderChoices = [180, 90, 60, 30, 7, 0]9394    @ObservationIgnored private let defaults: UserDefaults9596    var appearance: AppearanceChoice { didSet { defaults.set(appearance.rawValue, forKey: "appearance") } }97    var walletLayout: WalletLayout { didSet { defaults.set(walletLayout.rawValue, forKey: "walletLayout") } }98    var renderMode: CardRenderMode { didSet { defaults.set(renderMode.rawValue, forKey: "renderMode") } }99    /// Privacy Mode: card faces are veiled in the wallet until opened.100    var privacyMode: Bool { didSet { defaults.set(privacyMode, forKey: "privacyMode") } }101    var hapticsEnabled: Bool { didSet { defaults.set(hapticsEnabled, forKey: "haptics"); Haptics.shared.isEnabled = hapticsEnabled } }102    /// Tilt-driven reflections and parallax (always off under Reduce Motion).103    var motionEffects: Bool { didSet { defaults.set(motionEffects, forKey: "motionEffects") } }104    var remindersEnabled: Bool { didSet { defaults.set(remindersEnabled, forKey: "remindersEnabled") } }105    /// Default reminder offsets (days before expiry) given to new cards.106    var defaultReminderOffsets: [Int] { didSet { defaults.set(defaultReminderOffsets, forKey: "reminderOffsets") } }107    /// A card counts as "expiring soon" within this many days.108    var expiringSoonDays: Int { didSet { defaults.set(expiringSoonDays, forKey: "expiringSoonDays") } }109    var screenshotAlerts: Bool { didSet { defaults.set(screenshotAlerts, forKey: "screenshotAlerts") } }110111    init(defaults: UserDefaults = .standard) {112        self.defaults = defaults113        appearance = AppearanceChoice(rawValue: defaults.string(forKey: "appearance") ?? "") ?? .system114        walletLayout = WalletLayout(rawValue: defaults.string(forKey: "walletLayout") ?? "") ?? .stack115        renderMode = CardRenderMode(rawValue: defaults.string(forKey: "renderMode") ?? "") ?? .premium116        privacyMode = defaults.bool(forKey: "privacyMode")117        hapticsEnabled = defaults.object(forKey: "haptics") as? Bool ?? true118        motionEffects = defaults.object(forKey: "motionEffects") as? Bool ?? true119        remindersEnabled = defaults.object(forKey: "remindersEnabled") as? Bool ?? true120        defaultReminderOffsets = defaults.array(forKey: "reminderOffsets") as? [Int] ?? [30, 7, 0]121        expiringSoonDays = defaults.object(forKey: "expiringSoonDays") as? Int ?? 90122        screenshotAlerts = defaults.object(forKey: "screenshotAlerts") as? Bool ?? true123        Haptics.shared.isEnabled = hapticsEnabled124    }125}126
Files main
Menu

Theme