Repository Public License
1// ORIX Scan2// File: App/Sources/Settings/SettingsView.swift3// Description: Settings: recognition mode and languages, capture and export defaults, App Lock, storage, privacy statement, about.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import ORIXDesign8import ORIXKit9import SwiftData10import SwiftUI1112struct SettingsView: View {13 @Environment(AppModel.self) private var model14 @Environment(\.orixAccent) private var accent15 @Query private var records: [DocumentRecord]16 @State private var cacheCleared = false1718 private var version: String {19 let info = Bundle.main.infoDictionary20 return "\(info?["CFBundleShortVersionString"] as? String ?? "") (\(info?["CFBundleVersion"] as? String ?? ""))"21 }2223 var body: some View {24 @Bindable var settings = model.settings25 Form {26 Section {27 Picker("Mode", selection: $settings.recognitionMode) {28 ForEach(RecognitionMode.allCases) { Text($0.title).tag($0) }29 }30 .accessibilityIdentifier("settings.mode")31 NavigationLink {32 LanguagePicker()33 } label: {34 LabeledContent("Languages") {35 Text(settings.languages.isEmpty ? String(localized: "Automatic") : settings.languages.map(AppSettings.languageName).joined(separator: ", "))36 .lineLimit(1)37 }38 }39 .accessibilityIdentifier("settings.languages")40 Toggle("Language Correction", isOn: $settings.languageCorrection)41 Toggle("Recognize After Capture", isOn: $settings.recognizeAfterCapture)42 } header: { Text("Text Recognition") } footer: {43 Text(settings.recognitionMode.detail)44 }4546 Section("Capture") {47 Picker("Default Filter", selection: $settings.defaultFilter) { ForEach(FilterMode.allCases) { Text($0.title).tag($0) } }48 Toggle("Detect Edges in Imported Photos", isOn: $settings.autoCropImports)49 Toggle("Page Quality Warnings", isOn: Binding(get: { !settings.dismissedQualityWarnings }, set: { settings.dismissedQualityWarnings = !$0 }))50 }5152 Section("Export Defaults") {53 Picker("Quality", selection: $settings.exportPreset) { ForEach(ExportPreset.allCases) { Text($0.title).tag($0) } }54 Picker("Page Size", selection: $settings.pageSize) { ForEach(PageSizeMode.allCases) { Text($0.title).tag($0) } }55 }5657 Section {58 Toggle("App Lock with \(AppLock.biometryName)", isOn: Binding(get: { settings.appLock }, set: { wanted in59 if wanted {60 Task { if await AppLock.confirm() { settings.appLock = true } }61 } else {62 settings.appLock = false63 }64 }))65 .disabled(!AppLock.isAvailable)66 .accessibilityIdentifier("settings.appLock")67 } header: { Text("Security") } footer: {68 Text(AppLock.isAvailable69 ? "Optional. When on, ORIX Scan asks for the device's own authentication each time it opens. Files are also encrypted at rest by iOS."70 : "Set a device passcode to use App Lock.")71 }7273 Section {74 LabeledContent("Documents", value: records.filter { $0.deletedAt == nil }.count.formatted())75 LabeledContent("Storage Used", value: records.reduce(0) { $0 + $1.byteSize }.byteCountString)76 Button(cacheCleared ? "Previews Cleared" : "Clear Preview Cache") {77 Task { await model.clearCaches(); cacheCleared = true }78 }79 .disabled(cacheCleared)80 } header: { Text("Storage") } footer: {81 Text("Previews are rebuilt when needed. Clearing them never touches your documents.")82 }8384 Section("Privacy") {85 privacyRow("iphone", "Everything stays on this device", "Scans, recognized text and PDFs are processed and stored locally.")86 privacyRow("person.crop.circle.badge.xmark", "No account", "Nothing to sign up for, nothing to sign in to.")87 privacyRow("wifi.slash", "Works offline", "Text recognition uses Apple's on-device Vision framework. ORIX Scan makes no network requests.")88 privacyRow("chart.bar.xaxis", "No analytics or ads", "No tracking, no advertising SDK, no telemetry.")89 }9091 Section("About") {92 LabeledContent("Version", value: version)93 LabeledContent("Made by", value: "Simon-Pierre Boucher")94 HStack(spacing: ORIX.Space.sm) {95 ORIXMark().frame(width: 36)96 VStack(alignment: .leading) {97 Text("ORIX Scan").font(.orixHeadline)98 Text("Part of ORIX — premium Apple utilities.").font(.orixCaption).foregroundStyle(ORIX.Palette.textSecondary)99 }100 }101 .accessibilityElement(children: .combine)102 }103 }104 .navigationTitle("Settings")105 }106107 private func privacyRow(_ symbol: String, _ title: LocalizedStringKey, _ detail: LocalizedStringKey) -> some View {108 HStack(alignment: .top, spacing: ORIX.Space.sm) {109 ORIXGlyph(symbol, tint: ORIX.Palette.success, size: 32)110 VStack(alignment: .leading, spacing: 2) {111 Text(title).font(.orixHeadline)112 Text(detail).font(.orixCaption).foregroundStyle(ORIX.Palette.textSecondary)113 }114 }115 .accessibilityElement(children: .combine)116 }117}118119/// Recognition languages, listed from what Vision reports on this device. Order is priority.120struct LanguagePicker: View {121 @Environment(AppModel.self) private var model122 @Environment(\.orixAccent) private var accent123124 var body: some View {125 let settings = model.settings126 let available = settings.availableLanguages127 List {128 Section {129 Button {130 settings.languages = []131 } label: {132 row(String(localized: "Automatic"), detail: String(localized: "Let recognition detect the language"), selected: settings.languages.isEmpty)133 }134 }135 if !settings.languages.isEmpty {136 Section {137 ForEach(settings.languages, id: \.self) { id in138 Button { settings.languages.removeAll { $0 == id } } label: { row(AppSettings.languageName(id), detail: id, selected: true) }139 }140 .onMove { settings.languages.move(fromOffsets: $0, toOffset: $1) }141 } header: { Text("Selected, by Priority") }142 }143 Section {144 ForEach(available.filter { !settings.languages.contains($0) }, id: \.self) { id in145 Button { settings.languages.append(id) } label: { row(AppSettings.languageName(id), detail: id, selected: false) }146 }147 } header: { Text("Available on This Device") } footer: {148 Text("\(available.count) languages are supported by this version of iOS in \(String(localized: settings.recognitionMode.title)) mode. The list comes from the system; it can differ between modes.")149 }150 }151 .navigationTitle("Languages")152 .navigationBarTitleDisplayMode(.inline)153 .toolbar { if !settings.languages.isEmpty { EditButton() } }154 }155156 private func row(_ title: String, detail: String, selected: Bool) -> some View {157 HStack {158 VStack(alignment: .leading, spacing: 1) {159 Text(title).foregroundStyle(ORIX.Palette.textPrimary)160 Text(detail).font(.orixCaption).foregroundStyle(ORIX.Palette.textSecondary)161 }162 Spacer()163 if selected { Image(systemName: "checkmark").foregroundStyle(accent.primary).fontWeight(.semibold) }164 }165 .contentShape(Rectangle())166 .accessibilityElement(children: .combine)167 .accessibilityAddTraits(selected ? .isSelected : [])168 }169}170