Repository Public License
1// ORIX Secure2// File: App/Sources/Features/Settings/SettingsView.swift3// Description: Settings: appearance, optional App Lock, history and export privacy, data management, and what the app is.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import ORIXDesign8import ORIXSecureEngines9import ORIXSecureModel10import SwiftUI1112struct SettingsView: View {13 @Environment(AppModel.self) private var model14 @Environment(AppSettings.self) private var settings15 @State private var confirmErase = false16 @State private var lockError: String?17 @State private var cleared: String?1819 var body: some View {20 @Bindable var settings = settings21 Form {22 Section("Appearance") {23 Picker("Appearance", selection: $settings.appearance) {24 ForEach(AppearancePreference.allCases) { Text($0.title).tag($0) }25 }26 .pickerStyle(.segmented)27 .accessibilityIdentifier("settings.appearance")28 }29 Section {30 Toggle("App Lock", isOn: Binding(get: { settings.appLockEnabled }, set: { enable in31 if enable {32 Task { if await !model.lock.enable() { lockError = String(localized: "Authentication did not succeed, so App Lock stays off.") } }33 } else {34 Task { if await !model.lock.disable() { lockError = String(localized: "Authentication did not succeed, so App Lock stays on.") } }35 }36 }))37 .disabled(!AppLock.isAvailable && !settings.appLockEnabled)38 .accessibilityIdentifier("settings.appLock")39 } header: { Text("Protection") } footer: {40 Text(AppLock.isAvailable ? "Asks for \(model.signals.biometryKind == .none ? String(localized: "your passcode") : model.signals.biometryKind.title) or your passcode when ORIX Secure opens. Optional."41 : "Set a device passcode to use App Lock.")42 }43 Section {44 Toggle("Keep analysed links in history", isOn: $settings.keepLinkHistory).accessibilityIdentifier("settings.linkHistory")45 Toggle("Mask identifiers in exports", isOn: $settings.redactExports).accessibilityIdentifier("settings.redact")46 } header: { Text("Privacy") } footer: {47 Text("Links can be private, so they are not saved unless you turn this on. Masking replaces addresses, network names and personal paths in exported reports.")48 }49 Section {50 LabeledContent("Reports", value: "\(model.store.reports().count)")51 LabeledContent("Checklist answers", value: "\(model.store.responses().count)")52 LabeledContent("App files", value: ORIXFormat.bytes(model.storage.ownedTotal))53 Button("Clear Caches and Temporary Files") {54 let result = model.storageEngine.clear([.caches, .temporary, .exports])55 model.refresh()56 cleared = String(localized: "\(ORIXFormat.bytes(result.freedBytes)) freed, \(result.filesRemoved) file(s) removed.")57 }58 .accessibilityIdentifier("settings.clearCaches")59 if let cleared { Text(verbatim: cleared).font(.orixCaption).foregroundStyle(ORIX.Palette.textSecondary) }60 Button("Erase All App Data", role: .destructive) { confirmErase = true }.accessibilityIdentifier("settings.erase")61 } header: { Text("Data on this device") }62 Section {63 Button { openSettings() } label: { Label("ORIX Secure in Settings", systemImage: "gear") }64 } header: { Text("Permissions") } footer: { Text("Photos, Camera, Location and Local Network are requested only when you use the feature that needs them.") }65 Section("About") {66 LabeledContent("Version", value: ReportBuilder.generator.replacingOccurrences(of: "ORIX Secure ", with: ""))67 NavigationLink("What ORIX Secure can and cannot do") { CapabilitiesView() }.accessibilityIdentifier("settings.capabilities")68 LabeledContent("Account", value: String(localized: "None"))69 LabeledContent("Analytics and advertising", value: String(localized: "None"))70 }71 }72 .navigationTitle("Settings")73 .alert("App Lock", isPresented: Binding(get: { lockError != nil }, set: { if !$0 { lockError = nil } })) {74 Button("OK", role: .cancel) {}75 } message: { Text(verbatim: lockError ?? "") }76 .confirmationDialog("Erase all app data?", isPresented: $confirmErase, titleVisibility: .visible) {77 Button("Erase Reports, Answers, Workflows and Preferences", role: .destructive) {78 model.store.deleteEverything()79 _ = model.storageEngine.clear([.caches, .temporary, .exports])80 let lockWasOn = settings.appLockEnabled81 settings.reset()82 settings.hasSeenWelcome = true83 // Erasing data must not be a way around App Lock: the lock setting is kept.84 settings.appLockEnabled = lockWasOn85 model.refresh()86 }87 } message: { Text("Reports, checklist answers, saved workflows and preferences are deleted from this device. App Lock stays as it is. This cannot be undone.") }88 .accessibilityIdentifier("settings")89 }90}9192/// The capability statement, inside the app.93struct CapabilitiesView: View {94 var body: some View {95 ScreenScroll {96 ORIXBanner(.info, title: Text("ORIX Secure is not an antivirus"),97 message: Text("iOS isolates every app. No App Store app can scan the system, other apps or their data, so none can tell you an iPhone is free of malware."))98 ORIXSectionHeader("What it does")99 list([100 String(localized: "Reads the security facts iOS exposes: passcode, biometrics, Secure Enclave, signs of system modification, data protection."),101 String(localized: "Guides you through the settings apps cannot read, and records your answers as yours."),102 String(localized: "Analyses links, QR codes and files you choose, from their structure, without opening or running them."),103 String(localized: "Tests the connections you choose: DNS, latency, certificates, Wi-Fi security type."),104 String(localized: "Finds duplicate and similar photos, screenshots and large videos, and deletes only what you confirm."),105 String(localized: "Measures storage, thermal state, battery level and its own resource use."),106 ], symbol: "checkmark.circle", tint: ORIX.Palette.success)107 ORIXSectionHeader("What no app can do")108 list((PlatformLimits.securityAssessments + PlatformLimits.deviceMeasurements).map { "\($0.title) — \($0.reason)" }, symbol: "minus.circle", tint: ORIX.Palette.textTertiary)109 }110 .navigationTitle("Capabilities")111 .navigationBarTitleDisplayMode(.inline)112 .accessibilityIdentifier("capabilities")113 }114115 private func list(_ items: [String], symbol: String, tint: Color) -> some View {116 VStack(alignment: .leading, spacing: ORIX.Space.sm) {117 ForEach(items, id: \.self) { item in118 Label { Text(verbatim: item).foregroundStyle(ORIX.Palette.textPrimary) } icon: { Image(systemName: symbol).foregroundStyle(tint) }.font(.orixCallout)119 }120 }121 .frame(maxWidth: .infinity, alignment: .leading)122 .orixCard()123 }124}125