Commit 26151dbdf5
Verified · cmc
Layout: unified · split
DomainDataPortabilityService.swift +2 −18
| @@ -19,7 +19,6 @@ struct DomainDigBackup: Codable { | |||
| 19 | 19 | ||
| 20 | struct AppSettingsSnapshot: Codable { | 20 | struct AppSettingsSnapshot: Codable { |
| 21 | let recentSearches: [String] | 21 | let recentSearches: [String] |
| 22 | let savedDomains: [String] | ||
| 23 | let resolverURLString: String | 22 | let resolverURLString: String |
| 24 | let appDensityRawValue: String | 23 | let appDensityRawValue: String |
| 25 | } | 24 | } |
| @@ -549,7 +548,6 @@ enum DomainDataPortabilityService { | |||
| 549 | 548 | ||
| 550 | private enum StorageKey { | 549 | private enum StorageKey { |
| 551 | static let recentSearches = "recentSearches" | 550 | static let recentSearches = "recentSearches" |
| 552 | static let savedDomains = "savedDomains" | ||
| 553 | static let trackedDomains = "trackedDomains" | 551 | static let trackedDomains = "trackedDomains" |
| 554 | static let legacyWatchedDomains = "watchedDomains" | 552 | static let legacyWatchedDomains = "watchedDomains" |
| 555 | static let history = "lookupHistory" | 553 | static let history = "lookupHistory" |
| @@ -570,14 +568,6 @@ enum DomainDataPortabilityService { | |||
| 570 | defaults.set(Array(values.prefix(20)), forKey: StorageKey.recentSearches) | 568 | defaults.set(Array(values.prefix(20)), forKey: StorageKey.recentSearches) |
| 571 | } | 569 | } |
| 572 | 570 | ||
| 573 | static func loadSavedDomains(defaults: UserDefaults = .standard) -> [String] { | ||
| 574 | defaults.stringArray(forKey: StorageKey.savedDomains) ?? [] | ||
| 575 | } | ||
| 576 | |||
| 577 | static func saveSavedDomains(_ values: [String], defaults: UserDefaults = .standard) { | ||
| 578 | defaults.set(values, forKey: StorageKey.savedDomains) | ||
| 579 | } | ||
| 580 | |||
| 581 | static func loadTrackedDomains(defaults: UserDefaults = .standard) -> [TrackedDomain] { | 571 | static func loadTrackedDomains(defaults: UserDefaults = .standard) -> [TrackedDomain] { |
| 582 | let decoder = JSONDecoder() | 572 | let decoder = JSONDecoder() |
| 583 | 573 | ||
| @@ -700,7 +690,6 @@ enum DomainDataPortabilityService { | |||
| 700 | static func loadAppSettings(defaults: UserDefaults = .standard) -> AppSettingsSnapshot { | 690 | static func loadAppSettings(defaults: UserDefaults = .standard) -> AppSettingsSnapshot { |
| 701 | AppSettingsSnapshot( | 691 | AppSettingsSnapshot( |
| 702 | recentSearches: loadRecentSearches(defaults: defaults), | 692 | recentSearches: loadRecentSearches(defaults: defaults), |
| 703 | savedDomains: loadSavedDomains(defaults: defaults), | ||
| 704 | resolverURLString: defaults.string(forKey: StorageKey.resolverURL) ?? DNSResolverOption.defaultURLString, | 693 | resolverURLString: defaults.string(forKey: StorageKey.resolverURL) ?? DNSResolverOption.defaultURLString, |
| 705 | appDensityRawValue: defaults.string(forKey: StorageKey.appDensity) ?? AppDensity.compact.rawValue | 694 | appDensityRawValue: defaults.string(forKey: StorageKey.appDensity) ?? AppDensity.compact.rawValue |
| 706 | ) | 695 | ) |
| @@ -708,7 +697,6 @@ enum DomainDataPortabilityService { | |||
| 708 | 697 | ||
| 709 | static func saveAppSettings(_ settings: AppSettingsSnapshot, defaults: UserDefaults = .standard) { | 698 | static func saveAppSettings(_ settings: AppSettingsSnapshot, defaults: UserDefaults = .standard) { |
| 710 | saveRecentSearches(settings.recentSearches, defaults: defaults) | 699 | saveRecentSearches(settings.recentSearches, defaults: defaults) |
| 711 | saveSavedDomains(settings.savedDomains, defaults: defaults) | ||
| 712 | defaults.set(settings.resolverURLString, forKey: StorageKey.resolverURL) | 700 | defaults.set(settings.resolverURLString, forKey: StorageKey.resolverURL) |
| 713 | defaults.set(settings.appDensityRawValue, forKey: StorageKey.appDensity) | 701 | defaults.set(settings.appDensityRawValue, forKey: StorageKey.appDensity) |
| 714 | } | 702 | } |
| @@ -865,7 +853,6 @@ enum DomainDataPortabilityService { | |||
| 865 | let appSettings = loadAppSettings(defaults: defaults) | 853 | let appSettings = loadAppSettings(defaults: defaults) |
| 866 | let featureMetadata = loadFeatureMetadata(defaults: defaults) | 854 | let featureMetadata = loadFeatureMetadata(defaults: defaults) |
| 867 | let cachedItems = appSettings.recentSearches.count | 855 | let cachedItems = appSettings.recentSearches.count |
| 868 | + appSettings.savedDomains.count | ||
| 869 | + (featureMetadata.cachedEntitlement == nil ? 0 : 1) | 856 | + (featureMetadata.cachedEntitlement == nil ? 0 : 1) |
| 870 | 857 | ||
| 871 | return DataLifecycleSummary( | 858 | return DataLifecycleSummary( |
| @@ -943,7 +930,6 @@ enum DomainDataPortabilityService { | |||
| 943 | let monitoringSettings: MonitoringSettings? | 930 | let monitoringSettings: MonitoringSettings? |
| 944 | let monitoringLogs: [MonitoringLog]? | 931 | let monitoringLogs: [MonitoringLog]? |
| 945 | let recentSearches: [String]? | 932 | let recentSearches: [String]? |
| 946 | let savedDomains: [String]? | ||
| 947 | } | 933 | } |
| 948 | 934 | ||
| 949 | let legacy = try JSONDecoder().decode(LegacyBackup.self, from: data) | 935 | let legacy = try JSONDecoder().decode(LegacyBackup.self, from: data) |
| @@ -959,7 +945,6 @@ enum DomainDataPortabilityService { | |||
| 959 | monitoringLogs: legacy.monitoringLogs ?? [], | 945 | monitoringLogs: legacy.monitoringLogs ?? [], |
| 960 | appSettings: AppSettingsSnapshot( | 946 | appSettings: AppSettingsSnapshot( |
| 961 | recentSearches: legacy.recentSearches ?? [], | 947 | recentSearches: legacy.recentSearches ?? [], |
| 962 | savedDomains: legacy.savedDomains ?? [], | ||
| 963 | resolverURLString: DNSResolverOption.defaultURLString, | 948 | resolverURLString: DNSResolverOption.defaultURLString, |
| 964 | appDensityRawValue: AppDensity.compact.rawValue | 949 | appDensityRawValue: AppDensity.compact.rawValue |
| 965 | ), | 950 | ), |
| @@ -1076,7 +1061,7 @@ enum DomainDataPortabilityService { | |||
| 1076 | historySnapshots: backup.historyEntries.count, | 1061 | historySnapshots: backup.historyEntries.count, |
| 1077 | auditSessions: backup.auditSessions?.count ?? 0, | 1062 | auditSessions: backup.auditSessions?.count ?? 0, |
| 1078 | workflows: backup.workflows.count, | 1063 | workflows: backup.workflows.count, |
| 1079 | cachedItems: backup.appSettings.recentSearches.count + backup.appSettings.savedDomains.count + (backup.featureMetadata?.cachedEntitlement == nil ? 0 : 1), | 1064 | cachedItems: backup.appSettings.recentSearches.count + (backup.featureMetadata?.cachedEntitlement == nil ? 0 : 1), |
| 1080 | monitoringLogs: backup.monitoringLogs.count | 1065 | monitoringLogs: backup.monitoringLogs.count |
| 1081 | ) | 1066 | ) |
| 1082 | } | 1067 | } |
| @@ -1086,7 +1071,7 @@ enum DomainDataPortabilityService { | |||
| 1086 | historySnapshots: mergeHistoryEntries(existing: loadHistoryEntries(defaults: defaults), incoming: backup.historyEntries).count, | 1071 | historySnapshots: mergeHistoryEntries(existing: loadHistoryEntries(defaults: defaults), incoming: backup.historyEntries).count, |
| 1087 | auditSessions: mergeAuditSessions(existing: loadAuditSessions(defaults: defaults), incoming: backup.auditSessions ?? []).count, | 1072 | auditSessions: mergeAuditSessions(existing: loadAuditSessions(defaults: defaults), incoming: backup.auditSessions ?? []).count, |
| 1088 | workflows: mergeWorkflows(existing: loadWorkflows(defaults: defaults), incoming: backup.workflows).count, | 1073 | workflows: mergeWorkflows(existing: loadWorkflows(defaults: defaults), incoming: backup.workflows).count, |
| 1089 | cachedItems: max(current.cachedItems, backup.appSettings.recentSearches.count + backup.appSettings.savedDomains.count), | 1074 | cachedItems: max(current.cachedItems, backup.appSettings.recentSearches.count), |
| 1090 | monitoringLogs: mergeMonitoringLogs(existing: loadMonitoringLogs(defaults: defaults), incoming: backup.monitoringLogs).count | 1075 | monitoringLogs: mergeMonitoringLogs(existing: loadMonitoringLogs(defaults: defaults), incoming: backup.monitoringLogs).count |
| 1091 | ) | 1076 | ) |
| 1092 | case .trackedDomains(let trackedDomains, _): | 1077 | case .trackedDomains(let trackedDomains, _): |
| @@ -1269,7 +1254,6 @@ enum DomainDataPortabilityService { | |||
| 1269 | private static func mergeAppSettings(existing: AppSettingsSnapshot, incoming: AppSettingsSnapshot) -> AppSettingsSnapshot { | 1254 | private static func mergeAppSettings(existing: AppSettingsSnapshot, incoming: AppSettingsSnapshot) -> AppSettingsSnapshot { |
| 1270 | AppSettingsSnapshot( | 1255 | AppSettingsSnapshot( |
| 1271 | recentSearches: deduplicated(incoming.recentSearches + existing.recentSearches).prefix(20).map { $0 }, | 1256 | recentSearches: deduplicated(incoming.recentSearches + existing.recentSearches).prefix(20).map { $0 }, |
| 1272 | savedDomains: deduplicated(incoming.savedDomains + existing.savedDomains), | ||
| 1273 | resolverURLString: incoming.resolverURLString.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? existing.resolverURLString : incoming.resolverURLString, | 1257 | resolverURLString: incoming.resolverURLString.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? existing.resolverURLString : incoming.resolverURLString, |
| 1274 | appDensityRawValue: incoming.appDensityRawValue.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? existing.appDensityRawValue : incoming.appDensityRawValue | 1258 | appDensityRawValue: incoming.appDensityRawValue.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? existing.appDensityRawValue : incoming.appDensityRawValue |
| 1275 | ) | 1259 | ) |
DomainDig.xcodeproj/project.pbxproj −2
| @@ -118,8 +118,6 @@ | |||
| 118 | 8B1B506D2F666F64005C246F /* Exceptions for "DomainDig" folder in "DomainDig" target */ = { | 118 | 8B1B506D2F666F64005C246F /* Exceptions for "DomainDig" folder in "DomainDig" target */ = { |
| 119 | isa = PBXFileSystemSynchronizedBuildFileExceptionSet; | 119 | isa = PBXFileSystemSynchronizedBuildFileExceptionSet; |
| 120 | membershipExceptions = ( | 120 | membershipExceptions = ( |
| 121 | AuditMode.swift, | ||
| 122 | AuditModeView.swift, | ||
| 123 | Info.plist, | 121 | Info.plist, |
| 124 | ); | 122 | ); |
| 125 | target = 8B7800682F6090E300933221 /* DomainDig */; | 123 | target = 8B7800682F6090E300933221 /* DomainDig */; |
DomainDig/AuditMode.swift deleted −212
| @@ -1,212 +0,0 @@ | |||
| 1 | import Foundation | ||
| 2 | import SwiftUI | ||
| 3 | |||
| 4 | enum AuditStatus: String, Codable, Sendable, CaseIterable { | ||
| 5 | case draft | ||
| 6 | case inReview | ||
| 7 | case complete | ||
| 8 | |||
| 9 | var title: String { | ||
| 10 | switch self { | ||
| 11 | case .draft: return "Draft" | ||
| 12 | case .inReview: return "In Review" | ||
| 13 | case .complete: return "Complete" | ||
| 14 | } | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | enum AuditFindingSeverity: String, Codable, Sendable, CaseIterable { | ||
| 19 | case informational | ||
| 20 | case low | ||
| 21 | case medium | ||
| 22 | case high | ||
| 23 | } | ||
| 24 | |||
| 25 | struct AuditEvidenceSnapshot: Codable, Sendable { | ||
| 26 | var capturedAt: Date | ||
| 27 | var dnsSections: [DNSSection] | ||
| 28 | var headers: [HTTPHeader] | ||
| 29 | var tls: SSLCertificateInfo? | ||
| 30 | var redirects: [RedirectHop] | ||
| 31 | var reachability: [PortReachability] | ||
| 32 | var ownership: DomainOwnership? | ||
| 33 | var ownershipHistory: [DomainOwnershipHistoryEvent] | ||
| 34 | var dnsHistory: [DNSHistoryEvent] | ||
| 35 | var screenshotPath: String? | ||
| 36 | } | ||
| 37 | |||
| 38 | struct AuditFinding: Codable, Sendable, Identifiable { | ||
| 39 | var id: UUID | ||
| 40 | var title: String | ||
| 41 | var severity: AuditFindingSeverity | ||
| 42 | var summary: String | ||
| 43 | var evidenceReferences: [String] | ||
| 44 | var notes: String | ||
| 45 | var status: AuditStatus | ||
| 46 | |||
| 47 | init( | ||
| 48 | id: UUID = UUID(), | ||
| 49 | title: String, | ||
| 50 | severity: AuditFindingSeverity, | ||
| 51 | summary: String, | ||
| 52 | evidenceReferences: [String] = [], | ||
| 53 | notes: String = "", | ||
| 54 | status: AuditStatus = .draft | ||
| 55 | ) { | ||
| 56 | self.id = id | ||
| 57 | self.title = title | ||
| 58 | self.severity = severity | ||
| 59 | self.summary = summary | ||
| 60 | self.evidenceReferences = evidenceReferences | ||
| 61 | self.notes = notes | ||
| 62 | self.status = status | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | struct AuditChecklistItem: Codable, Sendable, Identifiable { | ||
| 67 | var id: String | ||
| 68 | var title: String | ||
| 69 | var isComplete: Bool | ||
| 70 | |||
| 71 | static let defaults: [AuditChecklistItem] = [ | ||
| 72 | .init(id: "dns_review", title: "DNS review", isComplete: false), | ||
| 73 | .init(id: "certificate_review", title: "Certificate review", isComplete: false), | ||
| 74 | .init(id: "redirect_review", title: "Redirect review", isComplete: false), | ||
| 75 | .init(id: "header_review", title: "Header review", isComplete: false), | ||
| 76 | .init(id: "ownership_review", title: "Ownership review", isComplete: false), | ||
| 77 | .init(id: "infrastructure_review", title: "Infrastructure review", isComplete: false), | ||
| 78 | .init(id: "monitoring_history_review", title: "Monitoring history review", isComplete: false) | ||
| 79 | ] | ||
| 80 | } | ||
| 81 | |||
| 82 | struct AuditSession: Codable, Sendable, Identifiable { | ||
| 83 | var id: UUID | ||
| 84 | var domain: String | ||
| 85 | var createdAt: Date | ||
| 86 | var reviewer: String | ||
| 87 | var status: AuditStatus | ||
| 88 | var evidence: AuditEvidenceSnapshot | ||
| 89 | var findings: [AuditFinding] | ||
| 90 | var notes: String | ||
| 91 | var checklist: [AuditChecklistItem] | ||
| 92 | } | ||
| 93 | |||
| 94 | enum AuditExportFormat: String, CaseIterable, Identifiable { | ||
| 95 | case json | ||
| 96 | case markdown | ||
| 97 | case pdf | ||
| 98 | |||
| 99 | var id: String { rawValue } | ||
| 100 | } | ||
| 101 | |||
| 102 | @MainActor | ||
| 103 | @Observable | ||
| 104 | final class AuditStore { | ||
| 105 | private(set) var sessions: [AuditSession] = [] | ||
| 106 | private let encoder = JSONEncoder() | ||
| 107 | private let decoder = JSONDecoder() | ||
| 108 | private let fileURL: URL | ||
| 109 | |||
| 110 | init() { | ||
| 111 | encoder.outputFormatting = [.prettyPrinted, .sortedKeys] | ||
| 112 | encoder.dateEncodingStrategy = .iso8601 | ||
| 113 | decoder.dateDecodingStrategy = .iso8601 | ||
| 114 | |||
| 115 | let base = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first | ||
| 116 | ?? FileManager.default.temporaryDirectory | ||
| 117 | let directory = base.appendingPathComponent("DomainDig", isDirectory: true) | ||
| 118 | try? FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true) | ||
| 119 | self.fileURL = directory.appendingPathComponent("audits.json") | ||
| 120 | load() | ||
| 121 | } | ||
| 122 | |||
| 123 | func startAudit(domain: String, reviewer: String, source: DomainViewModel) { | ||
| 124 | let snapshot = AuditEvidenceSnapshot( | ||
| 125 | capturedAt: Date(), | ||
| 126 | dnsSections: source.dnsSections, | ||
| 127 | headers: source.httpHeaders, | ||
| 128 | tls: source.sslInfo, | ||
| 129 | redirects: source.redirectChain, | ||
| 130 | reachability: source.reachabilityResults, | ||
| 131 | ownership: source.ownershipResult, | ||
| 132 | ownershipHistory: source.ownershipHistory, | ||
| 133 | dnsHistory: source.dnsHistory, | ||
| 134 | screenshotPath: nil | ||
| 135 | ) | ||
| 136 | let session = AuditSession( | ||
| 137 | id: UUID(), | ||
| 138 | domain: domain, | ||
| 139 | createdAt: Date(), | ||
| 140 | reviewer: reviewer, | ||
| 141 | status: .draft, | ||
| 142 | evidence: snapshot, | ||
| 143 | findings: [], | ||
| 144 | notes: "", | ||
| 145 | checklist: AuditChecklistItem.defaults | ||
| 146 | ) | ||
| 147 | sessions.insert(session, at: 0) | ||
| 148 | persist() | ||
| 149 | } | ||
| 150 | |||
| 151 | func update(session: AuditSession) { | ||
| 152 | guard let index = sessions.firstIndex(where: { $0.id == session.id }) else { return } | ||
| 153 | sessions[index] = session | ||
| 154 | persist() | ||
| 155 | } | ||
| 156 | |||
| 157 | func sessions(for domain: String) -> [AuditSession] { | ||
| 158 | sessions.filter { $0.domain.caseInsensitiveCompare(domain) == .orderedSame } | ||
| 159 | .sorted { $0.createdAt > $1.createdAt } | ||
| 160 | } | ||
| 161 | |||
| 162 | func export(session: AuditSession, format: AuditExportFormat) async throws -> URL { | ||
| 163 | let exportDir = fileURL.deletingLastPathComponent().appendingPathComponent("exports", isDirectory: true) | ||
| 164 | try FileManager.default.createDirectory(at: exportDir, withIntermediateDirectories: true) | ||
| 165 | let stamp = ISO8601DateFormatter().string(from: session.createdAt).replacingOccurrences(of: ":", with: "-") | ||
| 166 | let base = "audit-\(session.domain)-\(stamp)" | ||
| 167 | switch format { | ||
| 168 | case .json: | ||
| 169 | let url = exportDir.appendingPathComponent("\(base).json") | ||
| 170 | try encoder.encode(session).write(to: url) | ||
| 171 | return url | ||
| 172 | case .markdown: | ||
| 173 | let url = exportDir.appendingPathComponent("\(base).md") | ||
| 174 | try markdown(for: session).write(to: url, atomically: true, encoding: .utf8) | ||
| 175 | return url | ||
| 176 | case .pdf: | ||
| 177 | let url = exportDir.appendingPathComponent("\(base).pdf") | ||
| 178 | try markdown(for: session).write(to: url, atomically: true, encoding: .utf8) | ||
| 179 | return url | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | private func markdown(for session: AuditSession) -> String { | ||
| 184 | var lines: [String] = [] | ||
| 185 | lines.append("# Audit Summary") | ||
| 186 | lines.append("- Domain: \(session.domain)") | ||
| 187 | lines.append("- Review date: \(session.createdAt.formatted(date: .abbreviated, time: .shortened))") | ||
| 188 | lines.append("- Reviewer: \(session.reviewer)") | ||
| 189 | lines.append("- Status: \(session.status.title)") | ||
| 190 | lines.append("\n## Findings") | ||
| 191 | for finding in session.findings { | ||
| 192 | lines.append("### \(finding.title) [\(finding.severity.rawValue)]") | ||
| 193 | lines.append(finding.summary) | ||
| 194 | if !finding.evidenceReferences.isEmpty { | ||
| 195 | lines.append("Evidence: \(finding.evidenceReferences.joined(separator: ", "))") | ||
| 196 | } | ||
| 197 | } | ||
| 198 | lines.append("\n## Notes") | ||
| 199 | lines.append(session.notes) | ||
| 200 | return lines.joined(separator: "\n") | ||
| 201 | } | ||
| 202 | |||
| 203 | private func load() { | ||
| 204 | guard let data = try? Data(contentsOf: fileURL), let decoded = try? decoder.decode([AuditSession].self, from: data) else { return } | ||
| 205 | sessions = decoded.sorted { $0.createdAt > $1.createdAt } | ||
| 206 | } | ||
| 207 | |||
| 208 | private func persist() { | ||
| 209 | guard let data = try? encoder.encode(sessions) else { return } | ||
| 210 | try? data.write(to: fileURL, options: .atomic) | ||
| 211 | } | ||
| 212 | } | ||
DomainDig/AuditModeView.swift deleted −124
| @@ -1,124 +0,0 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | struct AuditModeView: View { | ||
| 4 | @Bindable var viewModel: DomainViewModel | ||
| 5 | @State private var auditStore = AuditStore() | ||
| 6 | @State private var reviewer = "Local Reviewer" | ||
| 7 | @State private var selectedSession: AuditSession? | ||
| 8 | @State private var exportMessage: String? | ||
| 9 | |||
| 10 | var body: some View { | ||
| 11 | List { | ||
| 12 | Section("Start Audit") { | ||
| 13 | TextField("Domain", text: $viewModel.domain) | ||
| 14 | .textInputAutocapitalization(.never) | ||
| 15 | .autocorrectionDisabled(true) | ||
| 16 | TextField("Reviewer", text: $reviewer) | ||
| 17 | Button("Start Audit") { | ||
| 18 | let domain = viewModel.domain.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| 19 | guard !domain.isEmpty else { return } | ||
| 20 | auditStore.startAudit(domain: domain, reviewer: reviewer, source: viewModel) | ||
| 21 | } | ||
| 22 | .disabled(viewModel.domain.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) | ||
| 23 | } | ||
| 24 | |||
| 25 | Section("Audit Timeline") { | ||
| 26 | if auditStore.sessions.isEmpty { | ||
| 27 | Text("No audits yet.") | ||
| 28 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 29 | } else { | ||
| 30 | ForEach(auditStore.sessions) { session in | ||
| 31 | Button { | ||
| 32 | selectedSession = session | ||
| 33 | } label: { | ||
| 34 | VStack(alignment: .leading) { | ||
| 35 | Text(session.domain).font(.headline) | ||
| 36 | Text("\(session.createdAt.formatted(date: .abbreviated, time: .shortened)) • \(session.status.title)") | ||
| 37 | .font(.caption) | ||
| 38 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } | ||
| 45 | .navigationTitle("Audit Mode") | ||
| 46 | .sheet(item: $selectedSession) { session in | ||
| 47 | AuditSessionDetailView(session: session) { updated in | ||
| 48 | auditStore.update(session: updated) | ||
| 49 | selectedSession = updated | ||
| 50 | } onExport: { updated, format in | ||
| 51 | do { | ||
| 52 | let url = try await auditStore.export(session: updated, format: format) | ||
| 53 | exportMessage = "Exported to \(url.lastPathComponent)" | ||
| 54 | } catch { | ||
| 55 | exportMessage = "Export failed: \(error.localizedDescription)" | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
| 59 | .alert("Audit Export", isPresented: Binding(get: { exportMessage != nil }, set: { if !$0 { exportMessage = nil } })) { | ||
| 60 | Button("OK", role: .cancel) { /* Dismiss only; SwiftUI closes the alert. */ } | ||
| 61 | } message: { | ||
| 62 | Text(exportMessage ?? "") | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | private struct AuditSessionDetailView: View { | ||
| 68 | @Environment(\.dismiss) private var dismiss | ||
| 69 | @State var session: AuditSession | ||
| 70 | let onSave: (AuditSession) -> Void | ||
| 71 | let onExport: (AuditSession, AuditExportFormat) async -> Void | ||
| 72 | |||
| 73 | var body: some View { | ||
| 74 | NavigationStack { | ||
| 75 | List { | ||
| 76 | Section("Session") { | ||
| 77 | Text(session.domain) | ||
| 78 | Picker("Status", selection: $session.status) { | ||
| 79 | ForEach(AuditStatus.allCases, id: \.self) { Text($0.title).tag($0) } | ||
| 80 | } | ||
| 81 | TextField("Notes", text: $session.notes, axis: .vertical) | ||
| 82 | } | ||
| 83 | Section("Checklist") { | ||
| 84 | ForEach($session.checklist) { $item in | ||
| 85 | Toggle(item.title, isOn: $item.isComplete) | ||
| 86 | } | ||
| 87 | } | ||
| 88 | Section("Findings") { | ||
| 89 | ForEach($session.findings) { $finding in | ||
| 90 | VStack(alignment: .leading) { | ||
| 91 | TextField("Title", text: $finding.title) | ||
| 92 | Picker("Severity", selection: $finding.severity) { | ||
| 93 | ForEach(AuditFindingSeverity.allCases, id: \.self) { Text($0.rawValue.capitalized).tag($0) } | ||
| 94 | } | ||
| 95 | TextField("Summary", text: $finding.summary, axis: .vertical) | ||
| 96 | } | ||
| 97 | } | ||
| 98 | Button("Add Finding") { | ||
| 99 | session.findings.append(.init(title: "New finding", severity: .informational, summary: "")) | ||
| 100 | } | ||
| 101 | } | ||
| 102 | Section("Export") { | ||
| 103 | ForEach(AuditExportFormat.allCases) { format in | ||
| 104 | Button("Export \(format.rawValue.uppercased())") { | ||
| 105 | Task { await onExport(session, format) } | ||
| 106 | } | ||
| 107 | } | ||
| 108 | } | ||
| 109 | } | ||
| 110 | .navigationTitle("Audit Session") | ||
| 111 | .toolbar { | ||
| 112 | ToolbarItem(placement: .topBarLeading) { | ||
| 113 | Button("Close") { dismiss() } | ||
| 114 | } | ||
| 115 | ToolbarItem(placement: .topBarTrailing) { | ||
| 116 | Button("Save") { | ||
| 117 | onSave(session) | ||
| 118 | dismiss() | ||
| 119 | } | ||
| 120 | } | ||
| 121 | } | ||
| 122 | } | ||
| 123 | } | ||
| 124 | } | ||
DomainDig/CloudSyncMerge.swift −2
| @@ -240,7 +240,6 @@ enum CloudSyncMerge { | |||
| 240 | let merged = SyncedAppSettings( | 240 | let merged = SyncedAppSettings( |
| 241 | snapshot: AppSettingsSnapshot( | 241 | snapshot: AppSettingsSnapshot( |
| 242 | recentSearches: deduplicated(winner.snapshot.recentSearches + loser.snapshot.recentSearches).prefix(20).map { $0 }, | 242 | recentSearches: deduplicated(winner.snapshot.recentSearches + loser.snapshot.recentSearches).prefix(20).map { $0 }, |
| 243 | savedDomains: deduplicated(winner.snapshot.savedDomains + loser.snapshot.savedDomains), | ||
| 244 | resolverURLString: winner.snapshot.resolverURLString, | 243 | resolverURLString: winner.snapshot.resolverURLString, |
| 245 | appDensityRawValue: winner.snapshot.appDensityRawValue | 244 | appDensityRawValue: winner.snapshot.appDensityRawValue |
| 246 | ), | 245 | ), |
| @@ -436,7 +435,6 @@ enum CloudSyncMerge { | |||
| 436 | 435 | ||
| 437 | static func sameAppSettings(_ lhs: AppSettingsSnapshot, _ rhs: AppSettingsSnapshot) -> Bool { | 436 | static func sameAppSettings(_ lhs: AppSettingsSnapshot, _ rhs: AppSettingsSnapshot) -> Bool { |
| 438 | lhs.recentSearches == rhs.recentSearches | 437 | lhs.recentSearches == rhs.recentSearches |
| 439 | && lhs.savedDomains == rhs.savedDomains | ||
| 440 | && lhs.resolverURLString == rhs.resolverURLString | 438 | && lhs.resolverURLString == rhs.resolverURLString |
| 441 | && lhs.appDensityRawValue == rhs.appDensityRawValue | 439 | && lhs.appDensityRawValue == rhs.appDensityRawValue |
| 442 | } | 440 | } |
DomainDig/ContentView.swift −10
| @@ -555,16 +555,6 @@ struct ContentView: View { | |||
| 555 | .foregroundStyle(Color(.appTextSecondary)) | 555 | .foregroundStyle(Color(.appTextSecondary)) |
| 556 | } | 556 | } |
| 557 | .accessibilityLabel("Actions") | 557 | .accessibilityLabel("Actions") |
| 558 | Button { | ||
| 559 | viewModel.toggleSavedDomain() | ||
| 560 | } label: { | ||
| 561 | Image(systemName: viewModel.isCurrentDomainSaved ? "bookmark.fill" : "bookmark") | ||
| 562 | .font(appDensity.font(.body, design: .default)) | ||
| 563 | .foregroundStyle(viewModel.isCurrentDomainSaved ? Color(.statusWarning) : .secondary) | ||
| 564 | } | ||
| 565 | .accessibilityLabel("Save domain") | ||
| 566 | .accessibilityValue(viewModel.isCurrentDomainSaved ? "Saved" : "Not saved") | ||
| 567 | .accessibilityAddTraits(viewModel.isCurrentDomainSaved ? .isSelected : []) | ||
| 568 | Menu { | 558 | Menu { |
| 569 | ExportFormatButtons(share: shareSingleResults) | 559 | ExportFormatButtons(share: shareSingleResults) |
| 570 | } label: { | 560 | } label: { |
DomainDig/DomainViewModel+Export.swift −1
| @@ -104,7 +104,6 @@ extension DomainViewModel { | |||
| 104 | DomainDataPortabilityService.saveAppSettings( | 104 | DomainDataPortabilityService.saveAppSettings( |
| 105 | AppSettingsSnapshot( | 105 | AppSettingsSnapshot( |
| 106 | recentSearches: recentSearches, | 106 | recentSearches: recentSearches, |
| 107 | savedDomains: savedDomains, | ||
| 108 | resolverURLString: resolverURLString, | 107 | resolverURLString: resolverURLString, |
| 109 | appDensityRawValue: appDensityRawValue | 108 | appDensityRawValue: appDensityRawValue |
| 110 | ) | 109 | ) |
DomainDig/DomainViewModel.swift −26
| @@ -296,8 +296,6 @@ final class DomainViewModel { | |||
| 296 | private static let maxRecent = 20 | 296 | private static let maxRecent = 20 |
| 297 | var recentSearches: [String] = DomainDataPortabilityService.loadRecentSearches() | 297 | var recentSearches: [String] = DomainDataPortabilityService.loadRecentSearches() |
| 298 | 298 | ||
| 299 | private static let savedDomainsKey = "savedDomains" | ||
| 300 | var savedDomains: [String] = DomainDataPortabilityService.loadSavedDomains() | ||
| 301 | 299 | ||
| 302 | private static let trackedDomainsKey = "trackedDomains" | 300 | private static let trackedDomainsKey = "trackedDomains" |
| 303 | private static let legacyWatchedDomainsKey = "watchedDomains" | 301 | private static let legacyWatchedDomainsKey = "watchedDomains" |
| @@ -391,10 +389,6 @@ final class DomainViewModel { | |||
| 391 | httpHeaders.contains { $0.name.lowercased() == "cf-ray" } | 389 | httpHeaders.contains { $0.name.lowercased() == "cf-ray" } |
| 392 | } | 390 | } |
| 393 | 391 | ||
| 394 | var isCurrentDomainSaved: Bool { | ||
| 395 | !searchedDomain.isEmpty && savedDomains.contains(where: { $0.lowercased() == searchedDomain.lowercased() }) | ||
| 396 | } | ||
| 397 | |||
| 398 | var sortedTrackedDomains: [TrackedDomain] { | 392 | var sortedTrackedDomains: [TrackedDomain] { |
| 399 | sortedTrackedDomains(from: trackedDomains, using: .pinned) | 393 | sortedTrackedDomains(from: trackedDomains, using: .pinned) |
| 400 | } | 394 | } |
| @@ -770,24 +764,6 @@ final class DomainViewModel { | |||
| 770 | [portScanError, customPortScanError].compactMap { $0 }.joined(separator: "\n").nilIfEmpty | 764 | [portScanError, customPortScanError].compactMap { $0 }.joined(separator: "\n").nilIfEmpty |
| 771 | } | 765 | } |
| 772 | 766 | ||
| 773 | func toggleSavedDomain() { | ||
| 774 | if isCurrentDomainSaved { | ||
| 775 | savedDomains.removeAll { $0.lowercased() == searchedDomain.lowercased() } | ||
| 776 | } else { | ||
| 777 | savedDomains.append(searchedDomain) | ||
| 778 | } | ||
| 779 | DomainDataPortabilityService.saveSavedDomains(savedDomains) | ||
| 780 | CloudSyncService.shared.markAppSettingsChanged() | ||
| 781 | refreshDataLifecycleSummary() | ||
| 782 | } | ||
| 783 | |||
| 784 | func removeSavedDomains(at offsets: IndexSet) { | ||
| 785 | savedDomains.remove(atOffsets: offsets) | ||
| 786 | DomainDataPortabilityService.saveSavedDomains(savedDomains) | ||
| 787 | CloudSyncService.shared.markAppSettingsChanged() | ||
| 788 | refreshDataLifecycleSummary() | ||
| 789 | } | ||
| 790 | |||
| 791 | @discardableResult | 767 | @discardableResult |
| 792 | func trackCurrentDomain() -> Bool { | 768 | func trackCurrentDomain() -> Bool { |
| 793 | guard !searchedDomain.isEmpty else { return false } | 769 | guard !searchedDomain.isEmpty else { return false } |
| @@ -1027,7 +1003,6 @@ final class DomainViewModel { | |||
| 1027 | if auditFixturesActive { return } | 1003 | if auditFixturesActive { return } |
| 1028 | #endif | 1004 | #endif |
| 1029 | recentSearches = DomainDataPortabilityService.loadRecentSearches() | 1005 | recentSearches = DomainDataPortabilityService.loadRecentSearches() |
| 1030 | savedDomains = DomainDataPortabilityService.loadSavedDomains() | ||
| 1031 | trackedDomains = Self.loadTrackedDomains() | 1006 | trackedDomains = Self.loadTrackedDomains() |
| 1032 | history = Self.loadHistoryEntries() | 1007 | history = Self.loadHistoryEntries() |
| 1033 | auditSessions = DomainDataPortabilityService.loadAuditSessions() | 1008 | auditSessions = DomainDataPortabilityService.loadAuditSessions() |
| @@ -1046,7 +1021,6 @@ final class DomainViewModel { | |||
| 1046 | reset() | 1021 | reset() |
| 1047 | 1022 | ||
| 1048 | recentSearches = [] | 1023 | recentSearches = [] |
| 1049 | savedDomains = [] | ||
| 1050 | trackedDomains = [] | 1024 | trackedDomains = [] |
| 1051 | history = [] | 1025 | history = [] |
| 1052 | auditSessions = [] | 1026 | auditSessions = [] |
DomainDig/SavedDomainsView.swift deleted −41
| @@ -1,41 +0,0 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | struct SavedDomainsView: View { | ||
| 4 | @Bindable var viewModel: DomainViewModel | ||
| 5 | @Environment(\.dismiss) private var dismiss | ||
| 6 | |||
| 7 | var body: some View { | ||
| 8 | List { | ||
| 9 | if viewModel.savedDomains.isEmpty { | ||
| 10 | Text("No saved domains") | ||
| 11 | .font(.system(.callout, design: .monospaced)) | ||
| 12 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 13 | .listRowBackground(Color(.appSurface)) | ||
| 14 | } else { | ||
| 15 | ForEach(viewModel.savedDomains, id: \.self) { domain in | ||
| 16 | Button { | ||
| 17 | viewModel.domain = domain | ||
| 18 | dismiss() | ||
| 19 | viewModel.run() | ||
| 20 | } label: { | ||
| 21 | Text(domain) | ||
| 22 | .font(.system(.callout, design: .monospaced)) | ||
| 23 | .foregroundStyle(.primary) | ||
| 24 | } | ||
| 25 | .listRowBackground(Color(.appSurface)) | ||
| 26 | } | ||
| 27 | .onDelete { offsets in | ||
| 28 | viewModel.removeSavedDomains(at: offsets) | ||
| 29 | } | ||
| 30 | } | ||
| 31 | } | ||
| 32 | .scrollContentBackground(.hidden) | ||
| 33 | .background(Color(.appBackground)) | ||
| 34 | .navigationTitle("Saved Domains") | ||
| 35 | .toolbar { | ||
| 36 | if !viewModel.savedDomains.isEmpty { | ||
| 37 | EditButton() | ||
| 38 | } | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | ||