Repository Public License
1// ORIX Secure2// File: App/Sources/Features/SecurityAudit/ChecklistView.swift3// Description: The user-assisted checklist: for each setting an app cannot read, where it is, why it matters, and the user's4// answer. Answers are recorded as reported by the user and expire.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import ORIXDesign9import ORIXSecureEngines10import ORIXSecureModel11import SwiftUI1213struct ChecklistView: View {14 let domain: ChecklistDomain15 @Environment(AppModel.self) private var model16 @State private var selected: ChecklistItem?1718 private var items: [ChecklistItem] { domain == .security ? ChecklistCatalog.security : ChecklistCatalog.privacyItems }19 private var findings: [String: Finding] {20 let list = domain == .security ? model.assessment.checklist : model.privacy.checklist21 return Dictionary(list.map { ($0.id, $0) }, uniquingKeysWith: { a, _ in a })22 }2324 var body: some View {25 let findings = findings26 let required = items.filter { !$0.isOptional }27 let done = required.filter { [.userConfirmed, .attention, .notAvailable].contains(findings[$0.id]?.state ?? .notAssessed) }.count28 ScreenScroll {29 VStack(alignment: .leading, spacing: ORIX.Space.sm) {30 Text("\(done) of \(required.count) checked").font(.orixHeadline).foregroundStyle(ORIX.Palette.textPrimary)31 ORIXProgressBar(value: required.isEmpty ? 0 : Double(done) / Double(required.count))32 Text("An app cannot read these settings. Open each one in Settings, look, and record what you see. Your answers stay on this device.")33 .font(.orixCaption).foregroundStyle(ORIX.Palette.textSecondary)34 Button { openSettings() } label: { Label("Open Settings", systemImage: "gear") }.buttonStyle(.orixSecondary)35 .accessibilityIdentifier("checklist.openSettings")36 Text("This opens ORIX Secure's page in Settings — the only page iOS lets an app open. Go back once to reach the other sections.")37 .font(.caption2).foregroundStyle(ORIX.Palette.textTertiary)38 }39 .orixCard()40 ForEach(ChecklistGroup.allCases, id: \.self) { group in41 let inGroup = items.filter { $0.group == group }42 if !inGroup.isEmpty {43 Text(verbatim: group.title).font(.orixTitle).foregroundStyle(ORIX.Palette.textPrimary).accessibilityAddTraits(.isHeader)44 VStack(spacing: 0) {45 ForEach(Array(inGroup.enumerated()), id: \.element.id) { index, item in46 Button { selected = item } label: { row(item, finding: findings[item.id]) }47 .buttonStyle(.plain)48 .accessibilityIdentifier("checklist." + item.id)49 if index < inGroup.count - 1 { Divider().padding(.leading, 40) }50 }51 }52 .orixCard(padding: ORIX.Space.sm)53 }54 }55 Text("Menu names can differ slightly between iOS versions.").font(.orixCaption).foregroundStyle(ORIX.Palette.textTertiary)56 }57 .navigationTitle(domain == .security ? "Security Checklist" : "Privacy Checklist")58 .sheet(item: $selected) { ChecklistItemView(item: $0) }59 .accessibilityIdentifier("checklist")60 }6162 private func row(_ item: ChecklistItem, finding: Finding?) -> some View {63 let state = finding?.state ?? .userConfirmationRequired64 return HStack(alignment: .top, spacing: ORIX.Space.sm) {65 Image(systemName: finding?.symbol ?? state.symbol).font(.title3).foregroundStyle(finding?.tint ?? state.tint).frame(width: 28).accessibilityHidden(true)66 VStack(alignment: .leading, spacing: 3) {67 HStack(spacing: 6) {68 Text(verbatim: item.title).font(.orixHeadline).foregroundStyle(ORIX.Palette.textPrimary).multilineTextAlignment(.leading)69 if item.isOptional { ORIXChip(Text("Optional")) }70 }71 Text(verbatim: state.title).font(.orixCaption).foregroundStyle(ORIX.Palette.textSecondary)72 Text(verbatim: item.pathText).font(.orixCaption).foregroundStyle(ORIX.Palette.textTertiary).multilineTextAlignment(.leading)73 }74 Spacer(minLength: 0)75 Image(systemName: "chevron.right").font(.footnote.weight(.semibold)).foregroundStyle(ORIX.Palette.textTertiary).accessibilityHidden(true)76 }77 .padding(.vertical, 6)78 .contentShape(Rectangle())79 .accessibilityElement(children: .combine)80 .accessibilityAddTraits(.isButton)81 }82}8384@MainActor func openSettings() {85 if let url = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(url) }86}8788struct ChecklistItemView: View {89 let item: ChecklistItem90 @Environment(AppModel.self) private var model91 @Environment(\.dismiss) private var dismiss9293 var body: some View {94 let response = model.response(for: item.id)95 NavigationStack {96 ScrollView {97 VStack(alignment: .leading, spacing: ORIX.Space.lg) {98 VStack(alignment: .leading, spacing: ORIX.Space.xs) {99 Text(verbatim: item.title).font(.orixTitle).foregroundStyle(ORIX.Palette.textPrimary)100 if item.isOptional {101 ORIXChip(Text("Optional — for people who may be personally targeted"), systemName: "person.badge.shield.checkmark")102 }103 Text(verbatim: item.why).font(.orixBody).foregroundStyle(ORIX.Palette.textSecondary)104 }105 VStack(alignment: .leading, spacing: ORIX.Space.sm) {106 Text("Where to look").font(.orixOverline).textCase(.uppercase).foregroundStyle(ORIX.Palette.textSecondary)107 ForEach(Array(item.path.enumerated()), id: \.offset) { index, step in108 HStack(spacing: ORIX.Space.sm) {109 Text(verbatim: "\(index + 1)").font(.orixCaption).foregroundStyle(ORIX.Palette.onAccent)110 .frame(width: 22, height: 22).background(ORIXAccent.secure.primary, in: Circle())111 Text(verbatim: step).font(.orixHeadline).foregroundStyle(ORIX.Palette.textPrimary)112 }113 }114 Button { openSettings() } label: { Label("Open Settings", systemImage: "gear") }.buttonStyle(.orixSecondary)115 }116 .frame(maxWidth: .infinity, alignment: .leading)117 .orixCard()118 .accessibilityElement(children: .contain)119 VStack(alignment: .leading, spacing: ORIX.Space.sm) {120 Text(verbatim: item.question).font(.orixHeadline).foregroundStyle(ORIX.Palette.textPrimary)121 ForEach(ChecklistAnswer.allCases, id: \.self) { answer in122 Button { model.answer(answer, for: item.id); ORIXHaptics.tick() } label: {123 HStack {124 Image(systemName: response?.answer == answer ? "largecircle.fill.circle" : "circle")125 .foregroundStyle(response?.answer == answer ? ORIXAccent.secure.primary : ORIX.Palette.textTertiary)126 Text(verbatim: answer.title).foregroundStyle(ORIX.Palette.textPrimary)127 Spacer()128 }129 .frame(minHeight: ORIX.minimumTarget)130 .contentShape(Rectangle())131 }132 .buttonStyle(.plain)133 .accessibilityAddTraits(response?.answer == answer ? .isSelected : [])134 .accessibilityIdentifier("answer." + answer.rawValue)135 }136 if let response {137 Text("Answered \(response.answeredAt.formatted(date: .abbreviated, time: .shortened)). Valid for \(item.validityDays) days.")138 .font(.orixCaption).foregroundStyle(ORIX.Palette.textTertiary)139 Button("Clear Answer", role: .destructive) { model.answer(nil, for: item.id) }.font(.orixCallout)140 .accessibilityIdentifier("answer.clear")141 }142 }143 .frame(maxWidth: .infinity, alignment: .leading)144 .orixCard()145 if let response, response.answer != item.expected, response.answer == .yes || response.answer == .no {146 ORIXBanner(item.isOptional ? .info : .warning, title: Text(item.isOptional ? "Optional" : "Recommended action"), message: Text(verbatim: item.action))147 }148 Label("Recorded as reported by you. ORIX Secure cannot read this setting and never presents it as verified.", systemImage: "person.crop.circle.badge.checkmark")149 .font(.orixCaption).foregroundStyle(ORIX.Palette.textTertiary)150 }151 .padding(ORIX.Space.lg)152 .frame(maxWidth: 720, alignment: .leading)153 .frame(maxWidth: .infinity)154 }155 .background(ORIX.Palette.canvas)156 .navigationTitle("Check")157 .navigationBarTitleDisplayMode(.inline)158 .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() }.accessibilityIdentifier("check.done") } }159 }160 .accessibilityIdentifier("checklist.item")161 }162}163