Commit 6f0eeeeea0
Unsigned
Layout: unified · split
.qlty/qlty.toml +14 −9
| @@ -40,14 +40,19 @@ name = "trufflehog" | |||
| 40 | [smells.return_statements] | 40 | [smells.return_statements] |
| 41 | enabled = false | 41 | enabled = false |
| 42 | 42 | ||
| 43 | # File complexity is a ratchet rather than a target. Measured 2026-10-25, the | 43 | # File complexity is a ratchet rather than a target: the threshold sits just |
| 44 | # ten worst files are ResultSectionViews 386, DomainViewModel 370, ContentView | 44 | # above today's worst file and fails anything past it. Lower it when a file is |
| 45 | # 306, CloudSyncService 198, DomainDataPortabilityService 146, WatchlistView | 45 | # genuinely split, never raise it to make a commit pass. |
| 46 | # 146, AuditViews 128, DomainReportExporter 114, SettingsViews 112 and | 46 | # |
| 47 | # WorkflowsView 107; twenty-two files exceed qlty's default. Splitting them is | 47 | # Measured after the A13 splits: DomainViewModel 370, CloudSyncService 198, |
| 48 | # not this finding's job, but letting them grow is avoidable, so the threshold | 48 | # WatchlistView 146, DomainDataPortabilityService 146, AuditViews 128, |
| 49 | # sits just above today's worst case and fails anything past it. Lower it when | 49 | # ContentView 119, DomainDiffViews 115, DomainReportExporter 114, |
| 50 | # a file is genuinely split, never raise it to make a commit pass. | 50 | # SettingsViews 112, WorkflowsView 107. |
| 51 | # | ||
| 52 | # DomainViewModel alone holds this threshold where it is — the next file is 172 | ||
| 53 | # points below it. Splitting it would let this drop to about 210, and it is the | ||
| 54 | # hard one: A2 collapsed its section state but left the four-way model | ||
| 55 | # duplication that makes it long. | ||
| 51 | [smells.file_complexity] | 56 | [smells.file_complexity] |
| 52 | enabled = true | 57 | enabled = true |
| 53 | 58 | ||
| @@ -76,4 +81,4 @@ filter_patterns = [ | |||
| 76 | ] | 81 | ] |
| 77 | 82 | ||
| 78 | [language.swift.smells.file_complexity] | 83 | [language.swift.smells.file_complexity] |
| 79 | threshold = 400 | 84 | threshold = 380 |
DomainDig/ContentView.swift −839
| @@ -689,842 +689,3 @@ struct ContentView: View { | |||
| 689 | ) | 689 | ) |
| 690 | } | 690 | } |
| 691 | } | 691 | } |
| 692 | |||
| 693 | struct SummaryView: View { | ||
| 694 | @Environment(\.appDensity) private var appDensity | ||
| 695 | let fields: [SummaryFieldViewData] | ||
| 696 | |||
| 697 | var body: some View { | ||
| 698 | VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) { | ||
| 699 | SectionTitleView(title: "Summary") | ||
| 700 | LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())], spacing: appDensity.metrics.cardSpacing) { | ||
| 701 | ForEach(fields) { field in | ||
| 702 | VStack(alignment: .leading, spacing: appDensity.metrics.rowSpacing) { | ||
| 703 | Text(field.label) | ||
| 704 | .font(appDensity.font(.caption2)) | ||
| 705 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 706 | Text(field.value) | ||
| 707 | .font(appDensity.font(.caption)) | ||
| 708 | .foregroundStyle(ResultColors.color(for: field.tone)) | ||
| 709 | .lineLimit(2) | ||
| 710 | .textSelection(.enabled) | ||
| 711 | } | ||
| 712 | .frame(minHeight: appDensity.metrics.rowMinHeight + 12, alignment: .topLeading) | ||
| 713 | .frame(maxWidth: .infinity, alignment: .leading) | ||
| 714 | .padding(appDensity.metrics.cardPadding) | ||
| 715 | .background(Color(.appSurface)) | ||
| 716 | .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius)) | ||
| 717 | } | ||
| 718 | } | ||
| 719 | } | ||
| 720 | } | ||
| 721 | } | ||
| 722 | |||
| 723 | struct RiskSummaryCardView: View { | ||
| 724 | @Environment(\.appDensity) private var appDensity | ||
| 725 | let report: DomainReport | ||
| 726 | |||
| 727 | private var topFactors: [RiskFactor] { | ||
| 728 | Array(report.riskAssessment.factors.prefix(3)) | ||
| 729 | } | ||
| 730 | |||
| 731 | var body: some View { | ||
| 732 | VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) { | ||
| 733 | SectionTitleView(title: "Risk") | ||
| 734 | CardView(allowsHorizontalScroll: false) { | ||
| 735 | HStack(alignment: .firstTextBaseline) { | ||
| 736 | VStack(alignment: .leading, spacing: 4) { | ||
| 737 | Text("\(report.riskAssessment.score)") | ||
| 738 | .font(appDensity.font(.largeTitle, weight: .bold)) | ||
| 739 | .foregroundStyle(levelColor) | ||
| 740 | Text(report.riskAssessment.level.title) | ||
| 741 | .font(appDensity.font(.caption)) | ||
| 742 | .foregroundStyle(levelColor) | ||
| 743 | } | ||
| 744 | Spacer() | ||
| 745 | Text("Deterministic") | ||
| 746 | .font(appDensity.font(.caption2)) | ||
| 747 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 748 | } | ||
| 749 | |||
| 750 | if topFactors.isEmpty { | ||
| 751 | Text("No major risk factors identified") | ||
| 752 | .font(appDensity.font(.caption)) | ||
| 753 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 754 | } else { | ||
| 755 | ForEach(Array(topFactors.enumerated()), id: \.offset) { _, factor in | ||
| 756 | HStack(alignment: .top, spacing: 8) { | ||
| 757 | Circle() | ||
| 758 | .fill(factorColor(factor.impact)) | ||
| 759 | .frame(width: 8, height: 8) | ||
| 760 | .padding(.top, 5) | ||
| 761 | Text(factor.description) | ||
| 762 | .font(appDensity.font(.caption)) | ||
| 763 | .foregroundStyle(.primary) | ||
| 764 | } | ||
| 765 | } | ||
| 766 | } | ||
| 767 | } | ||
| 768 | } | ||
| 769 | } | ||
| 770 | |||
| 771 | private var levelColor: Color { | ||
| 772 | switch report.riskAssessment.level { | ||
| 773 | case .low: | ||
| 774 | return Color(.statusPositive) | ||
| 775 | case .medium: | ||
| 776 | return Color(.statusWarning) | ||
| 777 | case .high: | ||
| 778 | return Color(.statusCritical) | ||
| 779 | } | ||
| 780 | } | ||
| 781 | |||
| 782 | private func factorColor(_ impact: RiskImpact) -> Color { | ||
| 783 | switch impact { | ||
| 784 | case .positive: | ||
| 785 | return Color(.statusPositive) | ||
| 786 | case .neutral: | ||
| 787 | return .secondary | ||
| 788 | case .negative: | ||
| 789 | return Color(.statusCritical) | ||
| 790 | } | ||
| 791 | } | ||
| 792 | } | ||
| 793 | |||
| 794 | struct InsightsSummaryCardView: View { | ||
| 795 | @Environment(\.appDensity) private var appDensity | ||
| 796 | let insights: [String] | ||
| 797 | |||
| 798 | var body: some View { | ||
| 799 | VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) { | ||
| 800 | SectionTitleView(title: "Insights") | ||
| 801 | CardView(allowsHorizontalScroll: false) { | ||
| 802 | if insights.isEmpty { | ||
| 803 | Text("No deterministic insights triggered") | ||
| 804 | .font(appDensity.font(.caption)) | ||
| 805 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 806 | } else { | ||
| 807 | ForEach(Array(insights.enumerated()), id: \.offset) { _, insight in | ||
| 808 | HStack(alignment: .top, spacing: 8) { | ||
| 809 | Image(systemName: "chart.line.uptrend.xyaxis") | ||
| 810 | .font(appDensity.font(.caption2)) | ||
| 811 | .foregroundStyle(Color(.statusInfo)) | ||
| 812 | .padding(.top, 2) | ||
| 813 | Text(insight) | ||
| 814 | .font(appDensity.font(.caption)) | ||
| 815 | .foregroundStyle(.primary) | ||
| 816 | } | ||
| 817 | } | ||
| 818 | } | ||
| 819 | } | ||
| 820 | } | ||
| 821 | } | ||
| 822 | } | ||
| 823 | |||
| 824 | struct StickyLookupSummaryView: View { | ||
| 825 | @Environment(\.appDensity) private var appDensity | ||
| 826 | |||
| 827 | let domain: String | ||
| 828 | let availability: DomainAvailabilityStatus? | ||
| 829 | let primaryIP: String? | ||
| 830 | let sslInfo: SSLCertificateInfo? | ||
| 831 | let sslError: String? | ||
| 832 | let emailSecurity: EmailSecurityResult? | ||
| 833 | let emailError: String? | ||
| 834 | let changeSummary: DomainChangeSummary? | ||
| 835 | |||
| 836 | var body: some View { | ||
| 837 | CardView(allowsHorizontalScroll: false) { | ||
| 838 | VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) { | ||
| 839 | HStack(alignment: .center, spacing: 10) { | ||
| 840 | Text(domain) | ||
| 841 | .font(appDensity.font(.headline, weight: .semibold)) | ||
| 842 | .foregroundStyle(.primary) | ||
| 843 | .lineLimit(1) | ||
| 844 | Spacer(minLength: 6) | ||
| 845 | AppCopyButton(value: domain, label: "Copy domain") | ||
| 846 | } | ||
| 847 | |||
| 848 | ScrollView(.horizontal, showsIndicators: false) { | ||
| 849 | HStack(spacing: 8) { | ||
| 850 | AppStatusBadgeView(model: AppStatusFactory.availability(availability)) | ||
| 851 | AppStatusBadgeView(model: AppStatusFactory.tls(sslInfo: sslInfo, error: sslError)) | ||
| 852 | AppStatusBadgeView(model: AppStatusFactory.email(emailSecurity, error: emailError)) | ||
| 853 | AppStatusBadgeView(model: AppStatusFactory.change(changeSummary)) | ||
| 854 | } | ||
| 855 | } | ||
| 856 | |||
| 857 | if let primaryIP { | ||
| 858 | HStack(spacing: 8) { | ||
| 859 | Label(primaryIP, systemImage: "network") | ||
| 860 | .font(appDensity.font(.caption)) | ||
| 861 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 862 | Spacer(minLength: 6) | ||
| 863 | AppCopyButton(value: primaryIP, label: "Copy IP") | ||
| 864 | } | ||
| 865 | } | ||
| 866 | } | ||
| 867 | } | ||
| 868 | .shadow(color: .black.opacity(0.12), radius: 14, y: 6) | ||
| 869 | } | ||
| 870 | } | ||
| 871 | |||
| 872 | struct LookupProgressOverviewView: View { | ||
| 873 | @Environment(\.appDensity) private var appDensity | ||
| 874 | let steps: [String] | ||
| 875 | |||
| 876 | var body: some View { | ||
| 877 | CardView(allowsHorizontalScroll: false) { | ||
| 878 | HStack(spacing: 8) { | ||
| 879 | ProgressView() | ||
| 880 | .controlSize(.small) | ||
| 881 | VStack(alignment: .leading, spacing: 4) { | ||
| 882 | Text("Running lookup…") | ||
| 883 | .font(appDensity.font(.caption)) | ||
| 884 | .foregroundStyle(.primary) | ||
| 885 | Text(steps.isEmpty ? "Preparing requests" : steps.joined(separator: " • ")) | ||
| 886 | .font(appDensity.font(.caption2)) | ||
| 887 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 888 | } | ||
| 889 | Spacer() | ||
| 890 | } | ||
| 891 | } | ||
| 892 | } | ||
| 893 | } | ||
| 894 | |||
| 895 | struct LookupStatusBannerView: View { | ||
| 896 | @Environment(\.appDensity) private var appDensity | ||
| 897 | let message: String | ||
| 898 | let resultSource: LookupResultSource | ||
| 899 | |||
| 900 | var body: some View { | ||
| 901 | HStack(spacing: 8) { | ||
| 902 | Image(systemName: iconName) | ||
| 903 | .font(.caption) | ||
| 904 | Text(message) | ||
| 905 | .font(appDensity.font(.caption)) | ||
| 906 | Spacer() | ||
| 907 | } | ||
| 908 | .foregroundStyle(color) | ||
| 909 | .padding(appDensity.metrics.cardPadding - 2) | ||
| 910 | .frame(maxWidth: .infinity, alignment: .leading) | ||
| 911 | .background(color.opacity(0.12)) | ||
| 912 | .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius)) | ||
| 913 | } | ||
| 914 | |||
| 915 | private var color: Color { | ||
| 916 | switch resultSource { | ||
| 917 | case .live: | ||
| 918 | return Color(.statusPositive) | ||
| 919 | case .cached: | ||
| 920 | return .secondary | ||
| 921 | case .mixed: | ||
| 922 | return Color(.statusWarning) | ||
| 923 | case .snapshot: | ||
| 924 | return Color(.statusWarning) | ||
| 925 | } | ||
| 926 | } | ||
| 927 | |||
| 928 | private var iconName: String { | ||
| 929 | switch resultSource { | ||
| 930 | case .live: | ||
| 931 | return "bolt.horizontal" | ||
| 932 | case .cached: | ||
| 933 | return "clock.arrow.trianglehead.counterclockwise.rotate.90" | ||
| 934 | case .mixed: | ||
| 935 | return "arrow.triangle.branch" | ||
| 936 | case .snapshot: | ||
| 937 | return "archivebox" | ||
| 938 | } | ||
| 939 | } | ||
| 940 | } | ||
| 941 | |||
| 942 | struct DomainChangeSummaryView: View { | ||
| 943 | @Environment(\.appDensity) private var appDensity | ||
| 944 | let summary: DomainChangeSummary | ||
| 945 | @State private var showsDetails = false | ||
| 946 | |||
| 947 | var body: some View { | ||
| 948 | CardView(allowsHorizontalScroll: false) { | ||
| 949 | HStack { | ||
| 950 | Label(summary.hasChanges ? "Changed" : "Stable", systemImage: summary.hasChanges ? "arrow.triangle.2.circlepath" : "checkmark.circle") | ||
| 951 | .font(appDensity.font(.caption)) | ||
| 952 | .foregroundStyle(summary.hasChanges ? severityTone(summary.severity).foreground : Color(.statusPositive)) | ||
| 953 | Spacer() | ||
| 954 | Text(summary.severity.title.uppercased()) | ||
| 955 | .font(appDensity.font(.caption2)) | ||
| 956 | .foregroundStyle(summary.hasChanges ? severityTone(summary.severity).foreground : Color(.appTextSecondary)) | ||
| 957 | .padding(.horizontal, 8) | ||
| 958 | .padding(.vertical, 4) | ||
| 959 | .background((summary.hasChanges ? severityTone(summary.severity) : AppStatusTone.neutral).surface) | ||
| 960 | .clipShape(Capsule()) | ||
| 961 | Text(summary.impactClassification.title.uppercased()) | ||
| 962 | .font(appDensity.font(.caption2)) | ||
| 963 | .foregroundStyle(summary.impactClassification.tone.foreground) | ||
| 964 | .padding(.horizontal, 8) | ||
| 965 | .padding(.vertical, 4) | ||
| 966 | .background(summary.impactClassification.tone.surface) | ||
| 967 | .clipShape(Capsule()) | ||
| 968 | Text(summary.generatedAt, style: .time) | ||
| 969 | .font(appDensity.font(.caption2)) | ||
| 970 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 971 | } | ||
| 972 | |||
| 973 | VStack(alignment: .leading, spacing: 4) { | ||
| 974 | Text("Inference") | ||
| 975 | .font(appDensity.font(.caption2)) | ||
| 976 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 977 | Text(summary.message) | ||
| 978 | .font(appDensity.font(.caption)) | ||
| 979 | .foregroundStyle(.primary) | ||
| 980 | .lineLimit(2) | ||
| 981 | } | ||
| 982 | |||
| 983 | if !summary.observedFacts.isEmpty || summary.contextNote != nil { | ||
| 984 | DisclosureGroup(showsDetails ? "Hide Details" : "Show Details", isExpanded: $showsDetails) { | ||
| 985 | VStack(alignment: .leading, spacing: 8) { | ||
| 986 | if !summary.observedFacts.isEmpty { | ||
| 987 | VStack(alignment: .leading, spacing: 4) { | ||
| 988 | Text("Observed") | ||
| 989 | .font(appDensity.font(.caption2)) | ||
| 990 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 991 | ForEach(Array(summary.observedFacts.enumerated()), id: \.offset) { _, fact in | ||
| 992 | Text(fact) | ||
| 993 | .font(appDensity.font(.caption)) | ||
| 994 | .foregroundStyle(.primary) | ||
| 995 | } | ||
| 996 | } | ||
| 997 | } | ||
| 998 | |||
| 999 | if let riskScoreDelta = summary.riskScoreDelta { | ||
| 1000 | Text("Risk delta: \(riskScoreDelta >= 0 ? "+" : "")\(riskScoreDelta)") | ||
| 1001 | .font(appDensity.font(.caption2)) | ||
| 1002 | .foregroundStyle(riskScoreDelta > 0 ? Color(.statusWarning) : .secondary) | ||
| 1003 | } | ||
| 1004 | |||
| 1005 | if let contextNote = summary.contextNote { | ||
| 1006 | Text(contextNote) | ||
| 1007 | .font(appDensity.font(.caption2)) | ||
| 1008 | .foregroundStyle(Color(.statusWarning)) | ||
| 1009 | } | ||
| 1010 | } | ||
| 1011 | .padding(.top, 4) | ||
| 1012 | } | ||
| 1013 | .font(appDensity.font(.caption)) | ||
| 1014 | .tint(.secondary) | ||
| 1015 | } | ||
| 1016 | } | ||
| 1017 | } | ||
| 1018 | |||
| 1019 | private func severityTone(_ severity: ChangeSeverity) -> AppStatusTone { | ||
| 1020 | switch severity { | ||
| 1021 | case .low: | ||
| 1022 | return .neutral | ||
| 1023 | case .medium: | ||
| 1024 | return .warning | ||
| 1025 | case .high: | ||
| 1026 | return .critical | ||
| 1027 | } | ||
| 1028 | } | ||
| 1029 | |||
| 1030 | } | ||
| 1031 | |||
| 1032 | struct DomainDiffView: View { | ||
| 1033 | let title: String | ||
| 1034 | let sections: [DomainDiffSection] | ||
| 1035 | let contextNote: String? | ||
| 1036 | let showsUnchanged: Bool | ||
| 1037 | let highlightedSectionID: String? | ||
| 1038 | |||
| 1039 | @State private var collapsedSections = Set<String>() | ||
| 1040 | @State private var showsLowSeverity = false | ||
| 1041 | |||
| 1042 | private var filteredSections: [DomainDiffSection] { | ||
| 1043 | sections | ||
| 1044 | .map { section in | ||
| 1045 | let items = section.items.filter { item in | ||
| 1046 | if !showsUnchanged, !item.hasChanges { | ||
| 1047 | return false | ||
| 1048 | } | ||
| 1049 | if showsLowSeverity { | ||
| 1050 | return true | ||
| 1051 | } | ||
| 1052 | return item.severity >= .medium || (showsUnchanged && item.changeType == .unchanged) | ||
| 1053 | } | ||
| 1054 | return DomainDiffSection(id: section.id, title: section.title, items: items) | ||
| 1055 | } | ||
| 1056 | .filter { !$0.items.isEmpty } | ||
| 1057 | } | ||
| 1058 | |||
| 1059 | private var hasLowSeverityChanges: Bool { | ||
| 1060 | sections.flatMap(\.items).contains { $0.hasChanges && $0.severity == .low } | ||
| 1061 | } | ||
| 1062 | |||
| 1063 | var body: some View { | ||
| 1064 | VStack(alignment: .leading, spacing: 12) { | ||
| 1065 | HStack { | ||
| 1066 | SectionTitleView(title: title) | ||
| 1067 | Spacer() | ||
| 1068 | if hasLowSeverityChanges { | ||
| 1069 | Button(showsLowSeverity ? "Hide Low" : "Show Low") { | ||
| 1070 | showsLowSeverity.toggle() | ||
| 1071 | } | ||
| 1072 | .buttonStyle(.bordered) | ||
| 1073 | .font(.system(.caption, design: .monospaced)) | ||
| 1074 | } | ||
| 1075 | } | ||
| 1076 | if let contextNote { | ||
| 1077 | MessageCardView(text: contextNote, isError: false) | ||
| 1078 | } | ||
| 1079 | if filteredSections.isEmpty { | ||
| 1080 | MessageCardView(text: "No comparison data available", isError: false) | ||
| 1081 | } else { | ||
| 1082 | ForEach(filteredSections) { section in | ||
| 1083 | CardView(allowsHorizontalScroll: false) { | ||
| 1084 | DisclosureGroup(isExpanded: binding(for: section)) { | ||
| 1085 | let visibleItems = showsUnchanged ? section.items : section.items.filter(\.hasChanges) | ||
| 1086 | |||
| 1087 | ForEach(visibleItems) { item in | ||
| 1088 | VStack(alignment: .leading, spacing: 6) { | ||
| 1089 | HStack { | ||
| 1090 | Text(item.label) | ||
| 1091 | .font(.system(.caption, design: .monospaced)) | ||
| 1092 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 1093 | Spacer() | ||
| 1094 | Text("\(item.changeType.marker) \(item.severity.title) • \(changeLabel(for: item.changeType))") | ||
| 1095 | .font(.system(.caption2, design: .monospaced)) | ||
| 1096 | .foregroundStyle(changeTone(for: item).foreground) | ||
| 1097 | .padding(.horizontal, 8) | ||
| 1098 | .padding(.vertical, 4) | ||
| 1099 | .background(changeTone(for: item).surface) | ||
| 1100 | .clipShape(Capsule()) | ||
| 1101 | } | ||
| 1102 | |||
| 1103 | if let oldValue = item.oldValue { | ||
| 1104 | VStack(alignment: .leading, spacing: 2) { | ||
| 1105 | Text("Old") | ||
| 1106 | .font(.system(.caption2, design: .monospaced)) | ||
| 1107 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 1108 | Text(oldValue) | ||
| 1109 | .font(.system(.caption2, design: .monospaced)) | ||
| 1110 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 1111 | .textSelection(.enabled) | ||
| 1112 | } | ||
| 1113 | } | ||
| 1114 | |||
| 1115 | if let newValue = item.newValue { | ||
| 1116 | VStack(alignment: .leading, spacing: 2) { | ||
| 1117 | Text("New") | ||
| 1118 | .font(.system(.caption2, design: .monospaced)) | ||
| 1119 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 1120 | Text(newValue) | ||
| 1121 | .font(.system(.caption, design: .monospaced)) | ||
| 1122 | .foregroundStyle(item.hasChanges ? .primary : .secondary) | ||
| 1123 | .textSelection(.enabled) | ||
| 1124 | } | ||
| 1125 | } | ||
| 1126 | } | ||
| 1127 | .padding(10) | ||
| 1128 | .background(item.hasChanges ? changeTone(for: item).surface : Color(.appSurface)) | ||
| 1129 | .cornerRadius(8) | ||
| 1130 | } | ||
| 1131 | } label: { | ||
| 1132 | HStack { | ||
| 1133 | Text(section.title) | ||
| 1134 | .font(.system(.subheadline, design: .monospaced)) | ||
| 1135 | .fontWeight(.semibold) | ||
| 1136 | .foregroundStyle(sectionColor(section)) | ||
| 1137 | Spacer() | ||
| 1138 | Text(section.severity.title) | ||
| 1139 | .font(.system(.caption2, design: .monospaced)) | ||
| 1140 | .foregroundStyle(sectionColor(section)) | ||
| 1141 | } | ||
| 1142 | } | ||
| 1143 | } | ||
| 1144 | .id(section.id) | ||
| 1145 | .overlay { | ||
| 1146 | if highlightedSectionID == section.id { | ||
| 1147 | RoundedRectangle(cornerRadius: 12) | ||
| 1148 | .stroke(Color(.statusInfo).opacity(0.55), lineWidth: 1) | ||
| 1149 | } | ||
| 1150 | } | ||
| 1151 | } | ||
| 1152 | } | ||
| 1153 | } | ||
| 1154 | .onAppear { | ||
| 1155 | collapsedSections = Set(sections.filter { !showsUnchanged && !$0.hasChanges }.map(\.id)) | ||
| 1156 | } | ||
| 1157 | } | ||
| 1158 | |||
| 1159 | private func changeLabel(for changeType: DiffChangeType) -> String { | ||
| 1160 | switch changeType { | ||
| 1161 | case .added: | ||
| 1162 | return "Added" | ||
| 1163 | case .removed: | ||
| 1164 | return "Removed" | ||
| 1165 | case .changed: | ||
| 1166 | return "Changed" | ||
| 1167 | case .unchanged: | ||
| 1168 | return "Unchanged" | ||
| 1169 | } | ||
| 1170 | } | ||
| 1171 | |||
| 1172 | private func changeTone(for item: DomainDiffItem) -> AppStatusTone { | ||
| 1173 | if item.changeType == .unchanged { | ||
| 1174 | return .neutral | ||
| 1175 | } | ||
| 1176 | |||
| 1177 | switch item.severity { | ||
| 1178 | case .low: | ||
| 1179 | return .info | ||
| 1180 | case .medium: | ||
| 1181 | return .warning | ||
| 1182 | case .high: | ||
| 1183 | return .critical | ||
| 1184 | } | ||
| 1185 | } | ||
| 1186 | |||
| 1187 | private func sectionColor(_ section: DomainDiffSection) -> Color { | ||
| 1188 | switch section.severity { | ||
| 1189 | case .low: | ||
| 1190 | return .blue | ||
| 1191 | case .medium: | ||
| 1192 | return Color(.statusWarning) | ||
| 1193 | case .high: | ||
| 1194 | return Color(.statusCritical) | ||
| 1195 | } | ||
| 1196 | } | ||
| 1197 | |||
| 1198 | private func binding(for section: DomainDiffSection) -> Binding<Bool> { | ||
| 1199 | Binding( | ||
| 1200 | get: { !collapsedSections.contains(section.id) }, | ||
| 1201 | set: { isExpanded in | ||
| 1202 | if isExpanded { | ||
| 1203 | collapsedSections.remove(section.id) | ||
| 1204 | } else { | ||
| 1205 | collapsedSections.insert(section.id) | ||
| 1206 | } | ||
| 1207 | } | ||
| 1208 | ) | ||
| 1209 | } | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | struct TrackedDomainDetailHeaderView: View { | ||
| 1213 | let trackedDomain: TrackedDomain | ||
| 1214 | |||
| 1215 | var body: some View { | ||
| 1216 | VStack(alignment: .leading, spacing: 4) { | ||
| 1217 | if let note = trackedDomain.note?.nilIfEmpty { | ||
| 1218 | LabeledValueRow(row: InfoRowViewData(label: "Tracking Note", value: note, tone: .secondary)) | ||
| 1219 | } | ||
| 1220 | HStack(spacing: 8) { | ||
| 1221 | if trackedDomain.isPinned { | ||
| 1222 | Label("Pinned", systemImage: "pin.fill") | ||
| 1223 | } | ||
| 1224 | Text("Last refresh \(trackedDomain.updatedAt.formatted(date: .abbreviated, time: .shortened))") | ||
| 1225 | } | ||
| 1226 | .font(.system(.caption2, design: .monospaced)) | ||
| 1227 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 1228 | } | ||
| 1229 | } | ||
| 1230 | } | ||
| 1231 | |||
| 1232 | struct SectionTitleView: View { | ||
| 1233 | @Environment(\.appDensity) private var appDensity | ||
| 1234 | let title: String | ||
| 1235 | |||
| 1236 | var body: some View { | ||
| 1237 | Text(title) | ||
| 1238 | .font(appDensity.font(.headline, design: .default, weight: .semibold)) | ||
| 1239 | .foregroundStyle(.primary) | ||
| 1240 | .accessibilityAddTraits(.isHeader) | ||
| 1241 | } | ||
| 1242 | } | ||
| 1243 | |||
| 1244 | /// A card that wraps its content by default. | ||
| 1245 | /// | ||
| 1246 | /// `allowsHorizontalScroll` used to default to `true`, so nine call sites put | ||
| 1247 | /// their content behind a horizontal gesture instead of letting it wrap — a | ||
| 1248 | /// WCAG 1.4.10 (Reflow) failure, and the mechanism behind clipped rows at large | ||
| 1249 | /// text sizes. It also forced VoiceOver and Switch Control users onto a nested | ||
| 1250 | /// scroll axis to reach data. | ||
| 1251 | /// | ||
| 1252 | /// The default is now `false`. Where horizontal scrolling genuinely suits wide | ||
| 1253 | /// tabular content, it is still opt-in — but it is suppressed at accessibility | ||
| 1254 | /// text sizes, where wrapping always beats a hidden axis. | ||
| 1255 | struct CardView<Content: View>: View { | ||
| 1256 | @Environment(\.appDensity) private var appDensity | ||
| 1257 | @Environment(\.dynamicTypeSize) private var dynamicTypeSize | ||
| 1258 | let allowsHorizontalScroll: Bool | ||
| 1259 | let content: Content | ||
| 1260 | |||
| 1261 | init(allowsHorizontalScroll: Bool = false, @ViewBuilder content: () -> Content) { | ||
| 1262 | self.allowsHorizontalScroll = allowsHorizontalScroll | ||
| 1263 | self.content = content() | ||
| 1264 | } | ||
| 1265 | |||
| 1266 | var body: some View { | ||
| 1267 | Group { | ||
| 1268 | if allowsHorizontalScroll, !dynamicTypeSize.isAccessibilitySize { | ||
| 1269 | ScrollView(.horizontal) { | ||
| 1270 | cardContent | ||
| 1271 | .scrollTargetLayout() | ||
| 1272 | } | ||
| 1273 | .scrollBounceBehavior(.basedOnSize, axes: .horizontal) | ||
| 1274 | } else { | ||
| 1275 | cardContent | ||
| 1276 | .frame(maxWidth: .infinity, alignment: .leading) | ||
| 1277 | } | ||
| 1278 | } | ||
| 1279 | .frame(maxWidth: .infinity, alignment: .leading) | ||
| 1280 | .padding(appDensity.metrics.cardPadding) | ||
| 1281 | .background(Color(.appSurface)) | ||
| 1282 | .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius)) | ||
| 1283 | } | ||
| 1284 | |||
| 1285 | private var cardContent: some View { | ||
| 1286 | VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) { | ||
| 1287 | content | ||
| 1288 | } | ||
| 1289 | } | ||
| 1290 | } | ||
| 1291 | |||
| 1292 | struct LoadingCardView: View { | ||
| 1293 | let text: String | ||
| 1294 | |||
| 1295 | var body: some View { | ||
| 1296 | CardView { | ||
| 1297 | ProgressView(text) | ||
| 1298 | .appLoadingStyle() | ||
| 1299 | .frame(maxWidth: .infinity, alignment: .center) | ||
| 1300 | } | ||
| 1301 | } | ||
| 1302 | } | ||
| 1303 | |||
| 1304 | struct MessageCardView: View { | ||
| 1305 | let text: String | ||
| 1306 | let isError: Bool | ||
| 1307 | |||
| 1308 | var body: some View { | ||
| 1309 | CardView { | ||
| 1310 | MessageRowView(text: text, isError: isError) | ||
| 1311 | } | ||
| 1312 | } | ||
| 1313 | } | ||
| 1314 | |||
| 1315 | struct MessageRowView: View { | ||
| 1316 | @Environment(\.appDensity) private var appDensity | ||
| 1317 | let text: String | ||
| 1318 | let isError: Bool | ||
| 1319 | |||
| 1320 | var body: some View { | ||
| 1321 | Label(text, systemImage: isError ? "exclamationmark.triangle.fill" : "info.circle") | ||
| 1322 | .font(appDensity.font(.caption)) | ||
| 1323 | .foregroundStyle(isError ? Color(.statusCritical) : .secondary) | ||
| 1324 | .lineLimit(nil) | ||
| 1325 | .fixedSize(horizontal: false, vertical: true) | ||
| 1326 | } | ||
| 1327 | } | ||
| 1328 | |||
| 1329 | struct SectionTrustMetadataView: View { | ||
| 1330 | @Environment(\.appDensity) private var appDensity | ||
| 1331 | let provenance: SectionProvenance? | ||
| 1332 | let confidence: ConfidenceLevel? | ||
| 1333 | let note: String? | ||
| 1334 | |||
| 1335 | init(provenance: SectionProvenance?, confidence: ConfidenceLevel?, note: String? = nil) { | ||
| 1336 | self.provenance = provenance | ||
| 1337 | self.confidence = confidence | ||
| 1338 | self.note = note | ||
| 1339 | } | ||
| 1340 | |||
| 1341 | var body: some View { | ||
| 1342 | if provenance != nil || confidence != nil || note != nil { | ||
| 1343 | VStack(alignment: .leading, spacing: 6) { | ||
| 1344 | HStack(spacing: 8) { | ||
| 1345 | if let confidence { | ||
| 1346 | Text("Confidence \(confidence.title)") | ||
| 1347 | .font(appDensity.font(.caption2)) | ||
| 1348 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 1349 | } | ||
| 1350 | if let provenance { | ||
| 1351 | Text(provenance.provider ?? provenance.source) | ||
| 1352 | .font(appDensity.font(.caption2)) | ||
| 1353 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 1354 | Text(provenance.resultSource.label) | ||
| 1355 | .font(appDensity.font(.caption2)) | ||
| 1356 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 1357 | } | ||
| 1358 | } | ||
| 1359 | DisclosureGroup("Details") { | ||
| 1360 | VStack(alignment: .leading, spacing: 4) { | ||
| 1361 | if let provenance { | ||
| 1362 | LabeledValueRow(row: .init(label: "Method", value: provenance.source, tone: .secondary)) | ||
| 1363 | if let provider = provenance.provider { | ||
| 1364 | LabeledValueRow(row: .init(label: "Provider", value: provider, tone: .secondary)) | ||
| 1365 | } | ||
| 1366 | if let resolver = provenance.resolver { | ||
| 1367 | LabeledValueRow(row: .init(label: "Resolver", value: resolver, tone: .secondary)) | ||
| 1368 | } | ||
| 1369 | LabeledValueRow(row: .init(label: "Collected", value: provenance.collectedAt.formatted(date: .abbreviated, time: .shortened), tone: .secondary)) | ||
| 1370 | LabeledValueRow(row: .init(label: "Mode", value: provenance.resultSource.label, tone: .secondary)) | ||
| 1371 | } | ||
| 1372 | if let note { | ||
| 1373 | LabeledValueRow(row: .init(label: "Note", value: note, tone: .secondary)) | ||
| 1374 | } | ||
| 1375 | } | ||
| 1376 | .padding(.top, 4) | ||
| 1377 | } | ||
| 1378 | .font(appDensity.font(.caption)) | ||
| 1379 | .tint(.secondary) | ||
| 1380 | } | ||
| 1381 | } | ||
| 1382 | } | ||
| 1383 | } | ||
| 1384 | |||
| 1385 | struct LabeledValueRow: View { | ||
| 1386 | @Environment(\.appDensity) private var appDensity | ||
| 1387 | @Environment(\.accessibilityDifferentiateWithoutColor) private var differentiateWithoutColor | ||
| 1388 | let row: InfoRowViewData | ||
| 1389 | |||
| 1390 | var body: some View { | ||
| 1391 | VStack(alignment: .leading, spacing: appDensity.metrics.rowSpacing - 1) { | ||
| 1392 | HStack(alignment: .top, spacing: 8) { | ||
| 1393 | VStack(alignment: .leading, spacing: appDensity.metrics.rowSpacing - 1) { | ||
| 1394 | Text(row.label) | ||
| 1395 | .font(appDensity.font(.caption2)) | ||
| 1396 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 1397 | HStack(alignment: .firstTextBaseline, spacing: 4) { | ||
| 1398 | if differentiateWithoutColor, let symbol = toneSymbol { | ||
| 1399 | Image(systemName: symbol) | ||
| 1400 | .font(appDensity.font(.caption2)) | ||
| 1401 | .foregroundStyle(ResultColors.color(for: row.tone)) | ||
| 1402 | .accessibilityHidden(true) | ||
| 1403 | } | ||
| 1404 | valueText | ||
| 1405 | } | ||
| 1406 | } | ||
| 1407 | .frame(maxWidth: .infinity, alignment: .leading) | ||
| 1408 | .layoutPriority(1) | ||
| 1409 | Spacer(minLength: 6) | ||
| 1410 | if !row.value.isEmpty, row.value != "Unavailable" { | ||
| 1411 | AppCopyButton(value: row.value, label: "Copy \(row.label)") | ||
| 1412 | } | ||
| 1413 | } | ||
| 1414 | } | ||
| 1415 | .frame(minHeight: appDensity.metrics.rowMinHeight, alignment: .topLeading) | ||
| 1416 | } | ||
| 1417 | |||
| 1418 | /// A leading symbol for warning/failure tones, shown only under Differentiate | ||
| 1419 | /// Without Color so tone is not conveyed by text colour alone. Hidden from | ||
| 1420 | /// VoiceOver — the value text already carries the meaning. | ||
| 1421 | private var toneSymbol: String? { | ||
| 1422 | switch row.tone { | ||
| 1423 | case .warning: return "exclamationmark.triangle.fill" | ||
| 1424 | case .failure: return "xmark.octagon.fill" | ||
| 1425 | default: return nil | ||
| 1426 | } | ||
| 1427 | } | ||
| 1428 | |||
| 1429 | @ViewBuilder | ||
| 1430 | private var valueText: some View { | ||
| 1431 | let base = Text(row.value) | ||
| 1432 | .font(appDensity.font(.caption)) | ||
| 1433 | .foregroundStyle(ResultColors.color(for: row.tone)) | ||
| 1434 | |||
| 1435 | switch row.speechStyle { | ||
| 1436 | case .plain: | ||
| 1437 | base | ||
| 1438 | .lineLimit(nil) | ||
| 1439 | .fixedSize(horizontal: false, vertical: true) | ||
| 1440 | .textSelection(.enabled) | ||
| 1441 | case .technical: | ||
| 1442 | // Record values and identifiers: keep punctuation audible (SPF/DMARC | ||
| 1443 | // separators are semantically load-bearing) and let VoiceOver use its | ||
| 1444 | // code-reading heuristics. | ||
| 1445 | base | ||
| 1446 | .speechAlwaysIncludesPunctuation() | ||
| 1447 | .accessibilityTextContentType(.sourceCode) | ||
| 1448 | .lineLimit(nil) | ||
| 1449 | .fixedSize(horizontal: false, vertical: true) | ||
| 1450 | .textSelection(.enabled) | ||
| 1451 | } | ||
| 1452 | } | ||
| 1453 | } | ||
| 1454 | |||
| 1455 | /// Maps a row's semantic tone onto the app palette. | ||
| 1456 | /// | ||
| 1457 | /// See `Docs/ACCESSIBILITY.md` for the measured contrast ratios behind these | ||
| 1458 | /// colours. Never reach for a literal (`Color(.statusCritical)`, `Color(.statusWarning)`, …) — the system | ||
| 1459 | /// palette fails WCAG AA badly in light mode (systemYellow is 1.28:1 on white). | ||
| 1460 | enum ResultColors { | ||
| 1461 | static func color(for tone: ResultTone) -> Color { | ||
| 1462 | switch tone { | ||
| 1463 | case .primary: | ||
| 1464 | return .primary | ||
| 1465 | case .secondary: | ||
| 1466 | return .secondary | ||
| 1467 | case .success: | ||
| 1468 | return Color(.statusPositive) | ||
| 1469 | case .warning: | ||
| 1470 | return Color(.statusWarning) | ||
| 1471 | case .failure: | ||
| 1472 | return Color(.statusCritical) | ||
| 1473 | } | ||
| 1474 | } | ||
| 1475 | } | ||
| 1476 | |||
| 1477 | extension DateFormatter { | ||
| 1478 | static let certDate: DateFormatter = { | ||
| 1479 | let formatter = DateFormatter() | ||
| 1480 | formatter.dateStyle = .medium | ||
| 1481 | formatter.timeStyle = .short | ||
| 1482 | return formatter | ||
| 1483 | }() | ||
| 1484 | } | ||
| 1485 | |||
| 1486 | extension View { | ||
| 1487 | func appLoadingStyle() -> some View { | ||
| 1488 | font(.system(.caption, design: .monospaced)) | ||
| 1489 | } | ||
| 1490 | } | ||
| 1491 | |||
| 1492 | private extension String { | ||
| 1493 | var nilIfEmpty: String? { | ||
| 1494 | isEmpty ? nil : self | ||
| 1495 | } | ||
| 1496 | } | ||
| 1497 | |||
| 1498 | extension ChangeImpactClassification { | ||
| 1499 | var tone: AppStatusTone { | ||
| 1500 | switch self { | ||
| 1501 | case .informational: return .neutral | ||
| 1502 | case .warning: return .warning | ||
| 1503 | case .critical: return .critical | ||
| 1504 | } | ||
| 1505 | } | ||
| 1506 | } | ||
| 1507 | |||
| 1508 | extension TLSGrade { | ||
| 1509 | var tone: ResultTone { | ||
| 1510 | switch self { | ||
| 1511 | case .a: return .success | ||
| 1512 | case .f: return .failure | ||
| 1513 | default: return .warning | ||
| 1514 | } | ||
| 1515 | } | ||
| 1516 | } | ||
| 1517 | |||
| 1518 | extension EmailSecurityGrade { | ||
| 1519 | var tone: ResultTone { | ||
| 1520 | switch self { | ||
| 1521 | case .a: return .success | ||
| 1522 | case .f: return .failure | ||
| 1523 | default: return .warning | ||
| 1524 | } | ||
| 1525 | } | ||
| 1526 | } | ||
| 1527 | |||
| 1528 | #Preview { | ||
| 1529 | ContentView(viewModel: DomainViewModel()) | ||
| 1530 | } | ||
DomainDig/DNSSectionView.swift added +168
| @@ -0,0 +1,168 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | // One inspection section: the DNS records card. Pure presentation over the | ||
| 4 | // view model's report data; the shared primitives it builds on (CardView, | ||
| 5 | // SectionTitleView, LabeledValueRow, ResultColors, appLoadingStyle) live in | ||
| 6 | // ResultPrimitives.swift. | ||
| 7 | |||
| 8 | struct DNSSectionView: View { | ||
| 9 | @Environment(\.appDensity) private var appDensity | ||
| 10 | @Binding var isCollapsed: Bool | ||
| 11 | let dnssecLabel: String? | ||
| 12 | let patternSummary: DNSPatternSummary? | ||
| 13 | let sections: [DNSRecordSectionViewData] | ||
| 14 | let ptrMessage: SectionMessageViewData? | ||
| 15 | let loading: Bool | ||
| 16 | let dnsProvenance: SectionProvenance? | ||
| 17 | let ptrProvenance: SectionProvenance? | ||
| 18 | let sectionError: String? | ||
| 19 | let history: [DNSHistoryEvent] | ||
| 20 | let historyLoading: Bool | ||
| 21 | let historyError: String? | ||
| 22 | let onLoadHistory: (() -> Void)? | ||
| 23 | |||
| 24 | init( | ||
| 25 | isCollapsed: Binding<Bool>, | ||
| 26 | dnssecLabel: String?, | ||
| 27 | patternSummary: DNSPatternSummary?, | ||
| 28 | sections: [DNSRecordSectionViewData], | ||
| 29 | ptrMessage: SectionMessageViewData?, | ||
| 30 | loading: Bool, | ||
| 31 | dnsProvenance: SectionProvenance?, | ||
| 32 | ptrProvenance: SectionProvenance?, | ||
| 33 | sectionError: String?, | ||
| 34 | history: [DNSHistoryEvent] = [], | ||
| 35 | historyLoading: Bool = false, | ||
| 36 | historyError: String? = nil, | ||
| 37 | onLoadHistory: (() -> Void)? = nil | ||
| 38 | ) { | ||
| 39 | _isCollapsed = isCollapsed | ||
| 40 | self.dnssecLabel = dnssecLabel | ||
| 41 | self.patternSummary = patternSummary | ||
| 42 | self.sections = sections | ||
| 43 | self.ptrMessage = ptrMessage | ||
| 44 | self.loading = loading | ||
| 45 | self.dnsProvenance = dnsProvenance | ||
| 46 | self.ptrProvenance = ptrProvenance | ||
| 47 | self.sectionError = sectionError | ||
| 48 | self.history = history | ||
| 49 | self.historyLoading = historyLoading | ||
| 50 | self.historyError = historyError | ||
| 51 | self.onLoadHistory = onLoadHistory | ||
| 52 | } | ||
| 53 | |||
| 54 | var body: some View { | ||
| 55 | CollapsibleSectionView(title: "DNS", isCollapsed: $isCollapsed, subtitle: dnssecLabel) { | ||
| 56 | if loading { | ||
| 57 | LoadingCardView(text: "Querying DNS…") | ||
| 58 | } else if let sectionError, sections.isEmpty { | ||
| 59 | MessageCardView(text: sectionError, isError: true) | ||
| 60 | } else { | ||
| 61 | provenanceCard | ||
| 62 | ForEach(sections) { section in | ||
| 63 | CardView { | ||
| 64 | Text(section.title) | ||
| 65 | .font(.system(.subheadline, design: .monospaced)) | ||
| 66 | .fontWeight(.semibold) | ||
| 67 | .foregroundStyle(Color(.statusInfo)) | ||
| 68 | |||
| 69 | if let message = section.message { | ||
| 70 | MessageRowView(text: message.text, isError: message.isError) | ||
| 71 | } | ||
| 72 | |||
| 73 | ForEach(section.rows) { row in | ||
| 74 | LabeledValueRow(row: row) | ||
| 75 | } | ||
| 76 | |||
| 77 | if let wildcardTitle = section.wildcardTitle { | ||
| 78 | Text(wildcardTitle) | ||
| 79 | .font(.system(.caption, design: .monospaced)) | ||
| 80 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 81 | .padding(.top, 4) | ||
| 82 | ForEach(section.wildcardRows) { row in | ||
| 83 | LabeledValueRow(row: row) | ||
| 84 | } | ||
| 85 | } | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | if let ptrMessage { | ||
| 90 | CardView { | ||
| 91 | Text("PTR") | ||
| 92 | .font(.system(.subheadline, design: .monospaced)) | ||
| 93 | .fontWeight(.semibold) | ||
| 94 | .foregroundStyle(Color(.statusInfo)) | ||
| 95 | SectionTrustMetadataView(provenance: ptrProvenance, confidence: nil) | ||
| 96 | MessageRowView(text: ptrMessage.text, isError: ptrMessage.isError) | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | CardView(allowsHorizontalScroll: false) { | ||
| 101 | HStack { | ||
| 102 | Text("History") | ||
| 103 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 104 | .foregroundStyle(Color(.statusInfo)) | ||
| 105 | Spacer() | ||
| 106 | if let onLoadHistory, history.isEmpty, !historyLoading { | ||
| 107 | Button("Load") { | ||
| 108 | onLoadHistory() | ||
| 109 | } | ||
| 110 | .buttonStyle(.bordered) | ||
| 111 | .font(appDensity.font(.caption2)) | ||
| 112 | } | ||
| 113 | } | ||
| 114 | historyContent | ||
| 115 | } | ||
| 116 | } | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | @ViewBuilder | ||
| 121 | private var historyContent: some View { | ||
| 122 | if historyLoading { | ||
| 123 | ProgressView("Loading DNS history…") | ||
| 124 | .appLoadingStyle() | ||
| 125 | } else if !history.isEmpty { | ||
| 126 | ForEach(history) { event in | ||
| 127 | VStack(alignment: .leading, spacing: 3) { | ||
| 128 | Text(event.date.formatted(date: .abbreviated, time: .omitted)) | ||
| 129 | .font(appDensity.font(.caption2)) | ||
| 130 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 131 | Text(event.summary) | ||
| 132 | .font(appDensity.font(.caption)) | ||
| 133 | if !event.aRecords.isEmpty { | ||
| 134 | Text("A: \(event.aRecords.joined(separator: ", "))") | ||
| 135 | .font(appDensity.font(.caption2)) | ||
| 136 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 137 | } | ||
| 138 | if !event.nameservers.isEmpty { | ||
| 139 | Text("NS: \(event.nameservers.joined(separator: ", "))") | ||
| 140 | .font(appDensity.font(.caption2)) | ||
| 141 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 142 | } | ||
| 143 | } | ||
| 144 | } | ||
| 145 | } else if let historyError { | ||
| 146 | MessageRowView(text: historyError, isError: false) | ||
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | @ViewBuilder | ||
| 151 | private var provenanceCard: some View { | ||
| 152 | if dnsProvenance != nil { | ||
| 153 | CardView(allowsHorizontalScroll: false) { | ||
| 154 | SectionTrustMetadataView(provenance: dnsProvenance, confidence: nil) | ||
| 155 | if let patternSummary { | ||
| 156 | if !patternSummary.providers.isEmpty { | ||
| 157 | MessageRowView(text: "Providers: \(patternSummary.providers.joined(separator: ", "))", isError: false) | ||
| 158 | } | ||
| 159 | if !patternSummary.patterns.isEmpty { | ||
| 160 | ForEach(Array(patternSummary.patterns.enumerated()), id: \.offset) { _, pattern in | ||
| 161 | MessageRowView(text: pattern, isError: false) | ||
| 162 | } | ||
| 163 | } | ||
| 164 | } | ||
| 165 | } | ||
| 166 | } | ||
| 167 | } | ||
| 168 | } | ||
DomainDig/DomainDiffViews.swift added +274
| @@ -0,0 +1,274 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | // Snapshot comparison: the change summary and the diff list. Split out of | ||
| 4 | // ContentView.swift (A13). | ||
| 5 | |||
| 6 | struct DomainChangeSummaryView: View { | ||
| 7 | @Environment(\.appDensity) private var appDensity | ||
| 8 | let summary: DomainChangeSummary | ||
| 9 | @State private var showsDetails = false | ||
| 10 | |||
| 11 | var body: some View { | ||
| 12 | CardView(allowsHorizontalScroll: false) { | ||
| 13 | HStack { | ||
| 14 | Label(summary.hasChanges ? "Changed" : "Stable", systemImage: summary.hasChanges ? "arrow.triangle.2.circlepath" : "checkmark.circle") | ||
| 15 | .font(appDensity.font(.caption)) | ||
| 16 | .foregroundStyle(summary.hasChanges ? severityTone(summary.severity).foreground : Color(.statusPositive)) | ||
| 17 | Spacer() | ||
| 18 | Text(summary.severity.title.uppercased()) | ||
| 19 | .font(appDensity.font(.caption2)) | ||
| 20 | .foregroundStyle(summary.hasChanges ? severityTone(summary.severity).foreground : Color(.appTextSecondary)) | ||
| 21 | .padding(.horizontal, 8) | ||
| 22 | .padding(.vertical, 4) | ||
| 23 | .background((summary.hasChanges ? severityTone(summary.severity) : AppStatusTone.neutral).surface) | ||
| 24 | .clipShape(Capsule()) | ||
| 25 | Text(summary.impactClassification.title.uppercased()) | ||
| 26 | .font(appDensity.font(.caption2)) | ||
| 27 | .foregroundStyle(summary.impactClassification.tone.foreground) | ||
| 28 | .padding(.horizontal, 8) | ||
| 29 | .padding(.vertical, 4) | ||
| 30 | .background(summary.impactClassification.tone.surface) | ||
| 31 | .clipShape(Capsule()) | ||
| 32 | Text(summary.generatedAt, style: .time) | ||
| 33 | .font(appDensity.font(.caption2)) | ||
| 34 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 35 | } | ||
| 36 | |||
| 37 | VStack(alignment: .leading, spacing: 4) { | ||
| 38 | Text("Inference") | ||
| 39 | .font(appDensity.font(.caption2)) | ||
| 40 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 41 | Text(summary.message) | ||
| 42 | .font(appDensity.font(.caption)) | ||
| 43 | .foregroundStyle(.primary) | ||
| 44 | .lineLimit(2) | ||
| 45 | } | ||
| 46 | |||
| 47 | if !summary.observedFacts.isEmpty || summary.contextNote != nil { | ||
| 48 | DisclosureGroup(showsDetails ? "Hide Details" : "Show Details", isExpanded: $showsDetails) { | ||
| 49 | VStack(alignment: .leading, spacing: 8) { | ||
| 50 | if !summary.observedFacts.isEmpty { | ||
| 51 | VStack(alignment: .leading, spacing: 4) { | ||
| 52 | Text("Observed") | ||
| 53 | .font(appDensity.font(.caption2)) | ||
| 54 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 55 | ForEach(Array(summary.observedFacts.enumerated()), id: \.offset) { _, fact in | ||
| 56 | Text(fact) | ||
| 57 | .font(appDensity.font(.caption)) | ||
| 58 | .foregroundStyle(.primary) | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | if let riskScoreDelta = summary.riskScoreDelta { | ||
| 64 | Text("Risk delta: \(riskScoreDelta >= 0 ? "+" : "")\(riskScoreDelta)") | ||
| 65 | .font(appDensity.font(.caption2)) | ||
| 66 | .foregroundStyle(riskScoreDelta > 0 ? Color(.statusWarning) : .secondary) | ||
| 67 | } | ||
| 68 | |||
| 69 | if let contextNote = summary.contextNote { | ||
| 70 | Text(contextNote) | ||
| 71 | .font(appDensity.font(.caption2)) | ||
| 72 | .foregroundStyle(Color(.statusWarning)) | ||
| 73 | } | ||
| 74 | } | ||
| 75 | .padding(.top, 4) | ||
| 76 | } | ||
| 77 | .font(appDensity.font(.caption)) | ||
| 78 | .tint(.secondary) | ||
| 79 | } | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | private func severityTone(_ severity: ChangeSeverity) -> AppStatusTone { | ||
| 84 | switch severity { | ||
| 85 | case .low: | ||
| 86 | return .neutral | ||
| 87 | case .medium: | ||
| 88 | return .warning | ||
| 89 | case .high: | ||
| 90 | return .critical | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | } | ||
| 95 | |||
| 96 | struct DomainDiffView: View { | ||
| 97 | let title: String | ||
| 98 | let sections: [DomainDiffSection] | ||
| 99 | let contextNote: String? | ||
| 100 | let showsUnchanged: Bool | ||
| 101 | let highlightedSectionID: String? | ||
| 102 | |||
| 103 | @State private var collapsedSections = Set<String>() | ||
| 104 | @State private var showsLowSeverity = false | ||
| 105 | |||
| 106 | private var filteredSections: [DomainDiffSection] { | ||
| 107 | sections | ||
| 108 | .map { section in | ||
| 109 | let items = section.items.filter { item in | ||
| 110 | if !showsUnchanged, !item.hasChanges { | ||
| 111 | return false | ||
| 112 | } | ||
| 113 | if showsLowSeverity { | ||
| 114 | return true | ||
| 115 | } | ||
| 116 | return item.severity >= .medium || (showsUnchanged && item.changeType == .unchanged) | ||
| 117 | } | ||
| 118 | return DomainDiffSection(id: section.id, title: section.title, items: items) | ||
| 119 | } | ||
| 120 | .filter { !$0.items.isEmpty } | ||
| 121 | } | ||
| 122 | |||
| 123 | private var hasLowSeverityChanges: Bool { | ||
| 124 | sections.flatMap(\.items).contains { $0.hasChanges && $0.severity == .low } | ||
| 125 | } | ||
| 126 | |||
| 127 | var body: some View { | ||
| 128 | VStack(alignment: .leading, spacing: 12) { | ||
| 129 | HStack { | ||
| 130 | SectionTitleView(title: title) | ||
| 131 | Spacer() | ||
| 132 | if hasLowSeverityChanges { | ||
| 133 | Button(showsLowSeverity ? "Hide Low" : "Show Low") { | ||
| 134 | showsLowSeverity.toggle() | ||
| 135 | } | ||
| 136 | .buttonStyle(.bordered) | ||
| 137 | .font(.system(.caption, design: .monospaced)) | ||
| 138 | } | ||
| 139 | } | ||
| 140 | if let contextNote { | ||
| 141 | MessageCardView(text: contextNote, isError: false) | ||
| 142 | } | ||
| 143 | if filteredSections.isEmpty { | ||
| 144 | MessageCardView(text: "No comparison data available", isError: false) | ||
| 145 | } else { | ||
| 146 | ForEach(filteredSections) { section in | ||
| 147 | CardView(allowsHorizontalScroll: false) { | ||
| 148 | DisclosureGroup(isExpanded: binding(for: section)) { | ||
| 149 | let visibleItems = showsUnchanged ? section.items : section.items.filter(\.hasChanges) | ||
| 150 | |||
| 151 | ForEach(visibleItems) { item in | ||
| 152 | VStack(alignment: .leading, spacing: 6) { | ||
| 153 | HStack { | ||
| 154 | Text(item.label) | ||
| 155 | .font(.system(.caption, design: .monospaced)) | ||
| 156 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 157 | Spacer() | ||
| 158 | Text("\(item.changeType.marker) \(item.severity.title) • \(changeLabel(for: item.changeType))") | ||
| 159 | .font(.system(.caption2, design: .monospaced)) | ||
| 160 | .foregroundStyle(changeTone(for: item).foreground) | ||
| 161 | .padding(.horizontal, 8) | ||
| 162 | .padding(.vertical, 4) | ||
| 163 | .background(changeTone(for: item).surface) | ||
| 164 | .clipShape(Capsule()) | ||
| 165 | } | ||
| 166 | |||
| 167 | if let oldValue = item.oldValue { | ||
| 168 | VStack(alignment: .leading, spacing: 2) { | ||
| 169 | Text("Old") | ||
| 170 | .font(.system(.caption2, design: .monospaced)) | ||
| 171 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 172 | Text(oldValue) | ||
| 173 | .font(.system(.caption2, design: .monospaced)) | ||
| 174 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 175 | .textSelection(.enabled) | ||
| 176 | } | ||
| 177 | } | ||
| 178 | |||
| 179 | if let newValue = item.newValue { | ||
| 180 | VStack(alignment: .leading, spacing: 2) { | ||
| 181 | Text("New") | ||
| 182 | .font(.system(.caption2, design: .monospaced)) | ||
| 183 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 184 | Text(newValue) | ||
| 185 | .font(.system(.caption, design: .monospaced)) | ||
| 186 | .foregroundStyle(item.hasChanges ? .primary : .secondary) | ||
| 187 | .textSelection(.enabled) | ||
| 188 | } | ||
| 189 | } | ||
| 190 | } | ||
| 191 | .padding(10) | ||
| 192 | .background(item.hasChanges ? changeTone(for: item).surface : Color(.appSurface)) | ||
| 193 | .cornerRadius(8) | ||
| 194 | } | ||
| 195 | } label: { | ||
| 196 | HStack { | ||
| 197 | Text(section.title) | ||
| 198 | .font(.system(.subheadline, design: .monospaced)) | ||
| 199 | .fontWeight(.semibold) | ||
| 200 | .foregroundStyle(sectionColor(section)) | ||
| 201 | Spacer() | ||
| 202 | Text(section.severity.title) | ||
| 203 | .font(.system(.caption2, design: .monospaced)) | ||
| 204 | .foregroundStyle(sectionColor(section)) | ||
| 205 | } | ||
| 206 | } | ||
| 207 | } | ||
| 208 | .id(section.id) | ||
| 209 | .overlay { | ||
| 210 | if highlightedSectionID == section.id { | ||
| 211 | RoundedRectangle(cornerRadius: 12) | ||
| 212 | .stroke(Color(.statusInfo).opacity(0.55), lineWidth: 1) | ||
| 213 | } | ||
| 214 | } | ||
| 215 | } | ||
| 216 | } | ||
| 217 | } | ||
| 218 | .onAppear { | ||
| 219 | collapsedSections = Set(sections.filter { !showsUnchanged && !$0.hasChanges }.map(\.id)) | ||
| 220 | } | ||
| 221 | } | ||
| 222 | |||
| 223 | private func changeLabel(for changeType: DiffChangeType) -> String { | ||
| 224 | switch changeType { | ||
| 225 | case .added: | ||
| 226 | return "Added" | ||
| 227 | case .removed: | ||
| 228 | return "Removed" | ||
| 229 | case .changed: | ||
| 230 | return "Changed" | ||
| 231 | case .unchanged: | ||
| 232 | return "Unchanged" | ||
| 233 | } | ||
| 234 | } | ||
| 235 | |||
| 236 | private func changeTone(for item: DomainDiffItem) -> AppStatusTone { | ||
| 237 | if item.changeType == .unchanged { | ||
| 238 | return .neutral | ||
| 239 | } | ||
| 240 | |||
| 241 | switch item.severity { | ||
| 242 | case .low: | ||
| 243 | return .info | ||
| 244 | case .medium: | ||
| 245 | return .warning | ||
| 246 | case .high: | ||
| 247 | return .critical | ||
| 248 | } | ||
| 249 | } | ||
| 250 | |||
| 251 | private func sectionColor(_ section: DomainDiffSection) -> Color { | ||
| 252 | switch section.severity { | ||
| 253 | case .low: | ||
| 254 | return .blue | ||
| 255 | case .medium: | ||
| 256 | return Color(.statusWarning) | ||
| 257 | case .high: | ||
| 258 | return Color(.statusCritical) | ||
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | private func binding(for section: DomainDiffSection) -> Binding<Bool> { | ||
| 263 | Binding( | ||
| 264 | get: { !collapsedSections.contains(section.id) }, | ||
| 265 | set: { isExpanded in | ||
| 266 | if isExpanded { | ||
| 267 | collapsedSections.remove(section.id) | ||
| 268 | } else { | ||
| 269 | collapsedSections.insert(section.id) | ||
| 270 | } | ||
| 271 | } | ||
| 272 | ) | ||
| 273 | } | ||
| 274 | } | ||
DomainDig/DomainSectionView.swift added +161
| @@ -0,0 +1,161 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | // One inspection section: the availability and domain card. Pure presentation | ||
| 4 | // over the view model's report data; the shared primitives it builds on | ||
| 5 | // (CardView, SectionTitleView, LabeledValueRow, ResultColors, appLoadingStyle) | ||
| 6 | // live in ResultPrimitives.swift. | ||
| 7 | |||
| 8 | struct DomainSectionView: View { | ||
| 9 | @Environment(\.appDensity) private var appDensity | ||
| 10 | @Binding var isCollapsed: Bool | ||
| 11 | let rows: [InfoRowViewData] | ||
| 12 | let suggestions: [DomainSuggestionViewData] | ||
| 13 | let showSuggestions: Bool | ||
| 14 | let availabilityLoading: Bool | ||
| 15 | let suggestionsLoading: Bool | ||
| 16 | let provenance: SectionProvenance? | ||
| 17 | let confidence: ConfidenceLevel? | ||
| 18 | let snapshotNote: String? | ||
| 19 | let trackedDomain: TrackedDomain? | ||
| 20 | let workflows: [DomainWorkflow] | ||
| 21 | let trackingLimitMessage: String? | ||
| 22 | let onTrack: () -> Void | ||
| 23 | let onTogglePinned: () -> Void | ||
| 24 | let onEditNote: (() -> Void)? | ||
| 25 | let onAddToWorkflow: (() -> Void)? | ||
| 26 | let onOpenWorkflow: ((DomainWorkflow) -> Void)? | ||
| 27 | let onRunWorkflow: ((DomainWorkflow) -> Void)? | ||
| 28 | |||
| 29 | var body: some View { | ||
| 30 | CollapsibleSectionView(title: "Domain", isCollapsed: $isCollapsed) { | ||
| 31 | if let trackedDomain { | ||
| 32 | HStack(spacing: 8) { | ||
| 33 | // Icon-only: the header also carries Pin and Note, and the | ||
| 34 | // full "Tracked" pill compresses at larger text sizes. | ||
| 35 | // VoiceOver still hears the word via the label. | ||
| 36 | Image(systemName: "eye.fill") | ||
| 37 | .font(appDensity.font(.caption)) | ||
| 38 | .foregroundStyle(Color(.statusPositive)) | ||
| 39 | .padding(6) | ||
| 40 | .background(Color(.statusPositiveSurface), in: Circle()) | ||
| 41 | .fixedSize() | ||
| 42 | .accessibilityLabel("Tracked") | ||
| 43 | Button { | ||
| 44 | onTogglePinned() | ||
| 45 | } label: { | ||
| 46 | Image(systemName: trackedDomain.isPinned ? "pin.fill" : "pin") | ||
| 47 | } | ||
| 48 | .buttonStyle(.bordered) | ||
| 49 | .font(appDensity.font(.caption)) | ||
| 50 | .accessibilityLabel("Pin domain") | ||
| 51 | .accessibilityValue(trackedDomain.isPinned ? "Pinned" : "Not pinned") | ||
| 52 | .accessibilityAddTraits(trackedDomain.isPinned ? .isSelected : []) | ||
| 53 | if let onEditNote { | ||
| 54 | Button("Note") { | ||
| 55 | onEditNote() | ||
| 56 | } | ||
| 57 | .buttonStyle(.bordered) | ||
| 58 | .font(appDensity.font(.caption)) | ||
| 59 | // Never compress into a vertical letter column. | ||
| 60 | .fixedSize() | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } else { | ||
| 64 | Button("Track") { | ||
| 65 | AppHaptics.track() | ||
| 66 | onTrack() | ||
| 67 | } | ||
| 68 | .buttonStyle(.bordered) | ||
| 69 | .font(appDensity.font(.caption)) | ||
| 70 | .fixedSize() | ||
| 71 | } | ||
| 72 | } content: { | ||
| 73 | CardView(allowsHorizontalScroll: false) { | ||
| 74 | SectionTrustMetadataView( | ||
| 75 | provenance: provenance, | ||
| 76 | confidence: confidence, | ||
| 77 | note: snapshotNote == nil ? nil : "Audit note present" | ||
| 78 | ) | ||
| 79 | ForEach(rows) { row in | ||
| 80 | LabeledValueRow(row: row) | ||
| 81 | } | ||
| 82 | if let trackedDomain { | ||
| 83 | TrackedDomainDetailHeaderView(trackedDomain: trackedDomain) | ||
| 84 | .padding(.top, 4) | ||
| 85 | } else if let trackingLimitMessage { | ||
| 86 | MessageRowView(text: trackingLimitMessage, isError: false) | ||
| 87 | .padding(.top, 4) | ||
| 88 | } | ||
| 89 | if let onAddToWorkflow { | ||
| 90 | Button { | ||
| 91 | onAddToWorkflow() | ||
| 92 | } label: { | ||
| 93 | Label("Add to workflow", systemImage: "plus.rectangle.on.folder") | ||
| 94 | .font(appDensity.font(.caption)) | ||
| 95 | } | ||
| 96 | .buttonStyle(.bordered) | ||
| 97 | .padding(.top, 4) | ||
| 98 | } | ||
| 99 | if !workflows.isEmpty { | ||
| 100 | VStack(alignment: .leading, spacing: 8) { | ||
| 101 | Text("Part of workflow") | ||
| 102 | .font(appDensity.font(.caption)) | ||
| 103 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 104 | |||
| 105 | ForEach(workflows) { workflow in | ||
| 106 | HStack { | ||
| 107 | Text(workflow.name) | ||
| 108 | .font(appDensity.font(.caption)) | ||
| 109 | .foregroundStyle(.primary) | ||
| 110 | Spacer() | ||
| 111 | if let onOpenWorkflow { | ||
| 112 | Button("Open") { | ||
| 113 | onOpenWorkflow(workflow) | ||
| 114 | } | ||
| 115 | .buttonStyle(.bordered) | ||
| 116 | .font(appDensity.font(.caption2)) | ||
| 117 | } | ||
| 118 | if let onRunWorkflow { | ||
| 119 | Button("Run") { | ||
| 120 | onRunWorkflow(workflow) | ||
| 121 | } | ||
| 122 | .buttonStyle(.bordered) | ||
| 123 | .font(appDensity.font(.caption2)) | ||
| 124 | } | ||
| 125 | } | ||
| 126 | } | ||
| 127 | } | ||
| 128 | .padding(.top, 4) | ||
| 129 | } | ||
| 130 | if availabilityLoading { | ||
| 131 | ProgressView("Checking availability…") | ||
| 132 | .appLoadingStyle() | ||
| 133 | .padding(.top, 4) | ||
| 134 | } | ||
| 135 | if showSuggestions { | ||
| 136 | Text("Suggestions") | ||
| 137 | .font(appDensity.font(.caption)) | ||
| 138 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 139 | .padding(.top, 4) | ||
| 140 | if suggestionsLoading { | ||
| 141 | ProgressView("Checking alternatives…") | ||
| 142 | .appLoadingStyle() | ||
| 143 | } else if suggestions.isEmpty { | ||
| 144 | MessageRowView(text: "No suggestions", isError: false) | ||
| 145 | } else { | ||
| 146 | ForEach(suggestions) { suggestion in | ||
| 147 | HStack { | ||
| 148 | Text(suggestion.domain) | ||
| 149 | .font(appDensity.font(.caption)) | ||
| 150 | .foregroundStyle(.primary) | ||
| 151 | .textSelection(.enabled) | ||
| 152 | Spacer() | ||
| 153 | AppStatusBadgeView(model: AppStatusFactory.availability(suggestion.availabilityStatus)) | ||
| 154 | } | ||
| 155 | } | ||
| 156 | } | ||
| 157 | } | ||
| 158 | } | ||
| 159 | } | ||
| 160 | } | ||
| 161 | } | ||
DomainDig/EmailSectionView.swift added +80
| @@ -0,0 +1,80 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | // One inspection section: the email security card. Pure presentation over the | ||
| 4 | // view model's report data; the shared primitives it builds on (CardView, | ||
| 5 | // SectionTitleView, LabeledValueRow, ResultColors, appLoadingStyle) live in | ||
| 6 | // ResultPrimitives.swift. | ||
| 7 | |||
| 8 | struct EmailSectionView: View { | ||
| 9 | @Environment(\.appDensity) private var appDensity | ||
| 10 | @Binding var isCollapsed: Bool | ||
| 11 | let rows: [EmailRowViewData] | ||
| 12 | let assessment: EmailSecuritySummary? | ||
| 13 | let loading: Bool | ||
| 14 | let provenance: SectionProvenance? | ||
| 15 | let confidence: ConfidenceLevel? | ||
| 16 | let error: String? | ||
| 17 | |||
| 18 | var body: some View { | ||
| 19 | CollapsibleSectionView(title: "Email", isCollapsed: $isCollapsed) { | ||
| 20 | CardView { | ||
| 21 | SectionTrustMetadataView(provenance: provenance, confidence: confidence) | ||
| 22 | HStack { | ||
| 23 | Spacer() | ||
| 24 | AppStatusBadgeView(model: AppStatusFactory.email(nil, error: error)) | ||
| 25 | .opacity(loading ? 0 : 1) | ||
| 26 | } | ||
| 27 | if let assessment, let grade = assessment.grade { | ||
| 28 | LabeledValueRow(row: InfoRowViewData(label: "Grade", value: grade.rawValue, tone: grade.tone)) | ||
| 29 | if !assessment.reasons.isEmpty { | ||
| 30 | Text(assessment.reasons.joined(separator: " | ")) | ||
| 31 | .font(appDensity.font(.caption2)) | ||
| 32 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 33 | } | ||
| 34 | } | ||
| 35 | if loading { | ||
| 36 | ProgressView("Checking email records…") | ||
| 37 | .appLoadingStyle() | ||
| 38 | } else if let error { | ||
| 39 | MessageRowView(text: error, isError: true) | ||
| 40 | } else if rows.isEmpty { | ||
| 41 | MessageRowView(text: "No email security records found", isError: false) | ||
| 42 | } else { | ||
| 43 | ForEach(rows) { row in | ||
| 44 | VStack(alignment: .leading, spacing: 4) { | ||
| 45 | HStack(spacing: 8) { | ||
| 46 | Text(row.label) | ||
| 47 | .font(appDensity.font(.caption)) | ||
| 48 | .foregroundStyle(Color(.statusInfo)) | ||
| 49 | .frame(width: 76, alignment: .leading) | ||
| 50 | AppStatusBadgeView(model: emailRowBadge(row)) | ||
| 51 | } | ||
| 52 | Text(row.detail) | ||
| 53 | .font(appDensity.font(.caption2)) | ||
| 54 | .foregroundStyle(.primary) | ||
| 55 | .textSelection(.enabled) | ||
| 56 | if let auxiliaryDetail = row.auxiliaryDetail { | ||
| 57 | Text(auxiliaryDetail) | ||
| 58 | .font(appDensity.font(.caption2)) | ||
| 59 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | private func emailRowBadge(_ row: EmailRowViewData) -> AppStatusBadgeModel { | ||
| 69 | switch row.statusTone { | ||
| 70 | case .success: | ||
| 71 | return .init(title: row.status, systemImage: "checkmark.shield.fill", foregroundColor: Color(.statusPositive), backgroundColor: Color(.statusPositiveSurface)) | ||
| 72 | case .warning: | ||
| 73 | return .init(title: row.status, systemImage: "shield.lefthalf.filled", foregroundColor: Color(.statusWarning), backgroundColor: Color(.statusWarningSurface)) | ||
| 74 | case .failure: | ||
| 75 | return .init(title: row.status, systemImage: "minus.circle", foregroundColor: Color(.appTextSecondary), backgroundColor: Color(.appSurfaceElevated)) | ||
| 76 | case .primary, .secondary: | ||
| 77 | return .init(title: row.status, systemImage: "circle", foregroundColor: Color(.appTextSecondary), backgroundColor: Color(.appSurfaceElevated)) | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } | ||
DomainDig/IntelligenceSectionView.swift added +126
| @@ -0,0 +1,126 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | // One inspection section: the derived risk and timeline card. Pure | ||
| 4 | // presentation over the view model's report data; the shared primitives it | ||
| 5 | // builds on (CardView, SectionTitleView, LabeledValueRow, ResultColors, | ||
| 6 | // appLoadingStyle) live in ResultPrimitives.swift. | ||
| 7 | |||
| 8 | struct IntelligenceSectionView: View { | ||
| 9 | @Environment(\.appDensity) private var appDensity | ||
| 10 | @Binding var isCollapsed: Bool | ||
| 11 | let report: DomainReport | ||
| 12 | let showsPlaceholder: Bool | ||
| 13 | |||
| 14 | var body: some View { | ||
| 15 | CollapsibleSectionView(title: "Data+ Intelligence", isCollapsed: $isCollapsed) { | ||
| 16 | CardView(allowsHorizontalScroll: false) { | ||
| 17 | if showsPlaceholder { | ||
| 18 | MessageRowView(text: "Richer intelligence history, hosting analysis, and risk signals are available in Pro+", isError: false) | ||
| 19 | } else { | ||
| 20 | if let provider = report.inferredProvider { | ||
| 21 | intelligenceBlock(title: "Infrastructure") { | ||
| 22 | LabeledValueRow(row: .init(label: "Provider", value: provider.name, tone: .primary)) | ||
| 23 | if !provider.evidence.isEmpty { | ||
| 24 | MessageRowView(text: provider.evidence.joined(separator: " • "), isError: false) | ||
| 25 | } | ||
| 26 | if !report.priorProviders.isEmpty { | ||
| 27 | LabeledValueRow(row: .init(label: "Prior", value: report.priorProviders.joined(separator: ", "), tone: .secondary)) | ||
| 28 | } | ||
| 29 | } | ||
| 30 | } | ||
| 31 | if let classification = report.domainClassification { | ||
| 32 | intelligenceBlock(title: "Classification") { | ||
| 33 | LabeledValueRow(row: .init(label: "Purpose", value: classification.kind.title, tone: .primary)) | ||
| 34 | MessageRowView(text: classification.reasons.joined(separator: " • "), isError: false) | ||
| 35 | } | ||
| 36 | } | ||
| 37 | intelligenceBlock(title: "Risk Signals") { | ||
| 38 | if report.riskSignals.isEmpty { | ||
| 39 | MessageRowView(text: "No material historical risk signals detected", isError: false) | ||
| 40 | } else { | ||
| 41 | ForEach(report.riskSignals.prefix(4)) { signal in | ||
| 42 | VStack(alignment: .leading, spacing: 3) { | ||
| 43 | Text(signal.title) | ||
| 44 | .font(appDensity.font(.caption, weight: .semibold)) | ||
| 45 | Text(signal.detail) | ||
| 46 | .font(appDensity.font(.caption2)) | ||
| 47 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
| 52 | intelligenceBlock(title: "Ownership History") { | ||
| 53 | if report.ownershipTransitions.isEmpty { | ||
| 54 | MessageRowView(text: "No ownership transitions observed locally", isError: false) | ||
| 55 | } else { | ||
| 56 | ForEach(report.ownershipTransitions.prefix(4)) { event in | ||
| 57 | intelligenceEventRow(date: event.date, title: event.summary) | ||
| 58 | } | ||
| 59 | } | ||
| 60 | } | ||
| 61 | intelligenceBlock(title: "Hosting History") { | ||
| 62 | if report.hostingTransitions.isEmpty { | ||
| 63 | MessageRowView(text: "No hosting transitions observed locally", isError: false) | ||
| 64 | } else { | ||
| 65 | ForEach(report.hostingTransitions.prefix(4)) { event in | ||
| 66 | intelligenceEventRow(date: event.date, title: event.summary) | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | intelligenceBlock(title: "Subdomain Intelligence") { | ||
| 71 | if report.subdomainHistory.isEmpty { | ||
| 72 | MessageRowView(text: "No subdomain history available", isError: false) | ||
| 73 | } else { | ||
| 74 | ForEach(report.subdomainHistory.prefix(5)) { item in | ||
| 75 | VStack(alignment: .leading, spacing: 3) { | ||
| 76 | HStack { | ||
| 77 | Text(item.hostname) | ||
| 78 | .font(appDensity.font(.caption)) | ||
| 79 | Spacer() | ||
| 80 | if item.isEphemeral { | ||
| 81 | Text("Ephemeral") | ||
| 82 | .font(appDensity.font(.caption2)) | ||
| 83 | .foregroundStyle(Color(.statusWarning)) | ||
| 84 | } | ||
| 85 | } | ||
| 86 | Text("First \(item.firstSeen.formatted(date: .abbreviated, time: .omitted)) • Last \(item.lastSeen.formatted(date: .abbreviated, time: .omitted)) • Seen \(item.recurrenceCount)x") | ||
| 87 | .font(appDensity.font(.caption2)) | ||
| 88 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 89 | } | ||
| 90 | } | ||
| 91 | } | ||
| 92 | } | ||
| 93 | intelligenceBlock(title: "Timeline") { | ||
| 94 | if report.intelligenceTimeline.isEmpty { | ||
| 95 | MessageRowView(text: "No inferred intelligence events yet", isError: false) | ||
| 96 | } else { | ||
| 97 | ForEach(report.intelligenceTimeline.prefix(5)) { event in | ||
| 98 | intelligenceEventRow(date: event.date, title: "\(event.title): \(event.detail)") | ||
| 99 | } | ||
| 100 | } | ||
| 101 | } | ||
| 102 | } | ||
| 103 | } | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | @ViewBuilder | ||
| 108 | private func intelligenceBlock<Content: View>(title: String, @ViewBuilder content: () -> Content) -> some View { | ||
| 109 | VStack(alignment: .leading, spacing: 8) { | ||
| 110 | Text(title) | ||
| 111 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 112 | .foregroundStyle(Color(.statusInfo)) | ||
| 113 | content() | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | private func intelligenceEventRow(date: Date, title: String) -> some View { | ||
| 118 | VStack(alignment: .leading, spacing: 3) { | ||
| 119 | Text(date.formatted(date: .abbreviated, time: .omitted)) | ||
| 120 | .font(appDensity.font(.caption2)) | ||
| 121 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 122 | Text(title) | ||
| 123 | .font(appDensity.font(.caption)) | ||
| 124 | } | ||
| 125 | } | ||
| 126 | } | ||
DomainDig/LookupSummaryViews.swift added +253
| @@ -0,0 +1,253 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | // The summary strip above the result sections: risk, insights, the sticky | ||
| 4 | // header, progress and the status banner. Split out of ContentView.swift (A13). | ||
| 5 | |||
| 6 | struct SummaryView: View { | ||
| 7 | @Environment(\.appDensity) private var appDensity | ||
| 8 | let fields: [SummaryFieldViewData] | ||
| 9 | |||
| 10 | var body: some View { | ||
| 11 | VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) { | ||
| 12 | SectionTitleView(title: "Summary") | ||
| 13 | LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())], spacing: appDensity.metrics.cardSpacing) { | ||
| 14 | ForEach(fields) { field in | ||
| 15 | VStack(alignment: .leading, spacing: appDensity.metrics.rowSpacing) { | ||
| 16 | Text(field.label) | ||
| 17 | .font(appDensity.font(.caption2)) | ||
| 18 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 19 | Text(field.value) | ||
| 20 | .font(appDensity.font(.caption)) | ||
| 21 | .foregroundStyle(ResultColors.color(for: field.tone)) | ||
| 22 | .lineLimit(2) | ||
| 23 | .textSelection(.enabled) | ||
| 24 | } | ||
| 25 | .frame(minHeight: appDensity.metrics.rowMinHeight + 12, alignment: .topLeading) | ||
| 26 | .frame(maxWidth: .infinity, alignment: .leading) | ||
| 27 | .padding(appDensity.metrics.cardPadding) | ||
| 28 | .background(Color(.appSurface)) | ||
| 29 | .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius)) | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | struct RiskSummaryCardView: View { | ||
| 37 | @Environment(\.appDensity) private var appDensity | ||
| 38 | let report: DomainReport | ||
| 39 | |||
| 40 | private var topFactors: [RiskFactor] { | ||
| 41 | Array(report.riskAssessment.factors.prefix(3)) | ||
| 42 | } | ||
| 43 | |||
| 44 | var body: some View { | ||
| 45 | VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) { | ||
| 46 | SectionTitleView(title: "Risk") | ||
| 47 | CardView(allowsHorizontalScroll: false) { | ||
| 48 | HStack(alignment: .firstTextBaseline) { | ||
| 49 | VStack(alignment: .leading, spacing: 4) { | ||
| 50 | Text("\(report.riskAssessment.score)") | ||
| 51 | .font(appDensity.font(.largeTitle, weight: .bold)) | ||
| 52 | .foregroundStyle(levelColor) | ||
| 53 | Text(report.riskAssessment.level.title) | ||
| 54 | .font(appDensity.font(.caption)) | ||
| 55 | .foregroundStyle(levelColor) | ||
| 56 | } | ||
| 57 | Spacer() | ||
| 58 | Text("Deterministic") | ||
| 59 | .font(appDensity.font(.caption2)) | ||
| 60 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 61 | } | ||
| 62 | |||
| 63 | if topFactors.isEmpty { | ||
| 64 | Text("No major risk factors identified") | ||
| 65 | .font(appDensity.font(.caption)) | ||
| 66 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 67 | } else { | ||
| 68 | ForEach(Array(topFactors.enumerated()), id: \.offset) { _, factor in | ||
| 69 | HStack(alignment: .top, spacing: 8) { | ||
| 70 | Circle() | ||
| 71 | .fill(factorColor(factor.impact)) | ||
| 72 | .frame(width: 8, height: 8) | ||
| 73 | .padding(.top, 5) | ||
| 74 | Text(factor.description) | ||
| 75 | .font(appDensity.font(.caption)) | ||
| 76 | .foregroundStyle(.primary) | ||
| 77 | } | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | private var levelColor: Color { | ||
| 85 | switch report.riskAssessment.level { | ||
| 86 | case .low: | ||
| 87 | return Color(.statusPositive) | ||
| 88 | case .medium: | ||
| 89 | return Color(.statusWarning) | ||
| 90 | case .high: | ||
| 91 | return Color(.statusCritical) | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | private func factorColor(_ impact: RiskImpact) -> Color { | ||
| 96 | switch impact { | ||
| 97 | case .positive: | ||
| 98 | return Color(.statusPositive) | ||
| 99 | case .neutral: | ||
| 100 | return .secondary | ||
| 101 | case .negative: | ||
| 102 | return Color(.statusCritical) | ||
| 103 | } | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | struct InsightsSummaryCardView: View { | ||
| 108 | @Environment(\.appDensity) private var appDensity | ||
| 109 | let insights: [String] | ||
| 110 | |||
| 111 | var body: some View { | ||
| 112 | VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) { | ||
| 113 | SectionTitleView(title: "Insights") | ||
| 114 | CardView(allowsHorizontalScroll: false) { | ||
| 115 | if insights.isEmpty { | ||
| 116 | Text("No deterministic insights triggered") | ||
| 117 | .font(appDensity.font(.caption)) | ||
| 118 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 119 | } else { | ||
| 120 | ForEach(Array(insights.enumerated()), id: \.offset) { _, insight in | ||
| 121 | HStack(alignment: .top, spacing: 8) { | ||
| 122 | Image(systemName: "chart.line.uptrend.xyaxis") | ||
| 123 | .font(appDensity.font(.caption2)) | ||
| 124 | .foregroundStyle(Color(.statusInfo)) | ||
| 125 | .padding(.top, 2) | ||
| 126 | Text(insight) | ||
| 127 | .font(appDensity.font(.caption)) | ||
| 128 | .foregroundStyle(.primary) | ||
| 129 | } | ||
| 130 | } | ||
| 131 | } | ||
| 132 | } | ||
| 133 | } | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | struct StickyLookupSummaryView: View { | ||
| 138 | @Environment(\.appDensity) private var appDensity | ||
| 139 | |||
| 140 | let domain: String | ||
| 141 | let availability: DomainAvailabilityStatus? | ||
| 142 | let primaryIP: String? | ||
| 143 | let sslInfo: SSLCertificateInfo? | ||
| 144 | let sslError: String? | ||
| 145 | let emailSecurity: EmailSecurityResult? | ||
| 146 | let emailError: String? | ||
| 147 | let changeSummary: DomainChangeSummary? | ||
| 148 | |||
| 149 | var body: some View { | ||
| 150 | CardView(allowsHorizontalScroll: false) { | ||
| 151 | VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) { | ||
| 152 | HStack(alignment: .center, spacing: 10) { | ||
| 153 | Text(domain) | ||
| 154 | .font(appDensity.font(.headline, weight: .semibold)) | ||
| 155 | .foregroundStyle(.primary) | ||
| 156 | .lineLimit(1) | ||
| 157 | Spacer(minLength: 6) | ||
| 158 | AppCopyButton(value: domain, label: "Copy domain") | ||
| 159 | } | ||
| 160 | |||
| 161 | ScrollView(.horizontal, showsIndicators: false) { | ||
| 162 | HStack(spacing: 8) { | ||
| 163 | AppStatusBadgeView(model: AppStatusFactory.availability(availability)) | ||
| 164 | AppStatusBadgeView(model: AppStatusFactory.tls(sslInfo: sslInfo, error: sslError)) | ||
| 165 | AppStatusBadgeView(model: AppStatusFactory.email(emailSecurity, error: emailError)) | ||
| 166 | AppStatusBadgeView(model: AppStatusFactory.change(changeSummary)) | ||
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 170 | if let primaryIP { | ||
| 171 | HStack(spacing: 8) { | ||
| 172 | Label(primaryIP, systemImage: "network") | ||
| 173 | .font(appDensity.font(.caption)) | ||
| 174 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 175 | Spacer(minLength: 6) | ||
| 176 | AppCopyButton(value: primaryIP, label: "Copy IP") | ||
| 177 | } | ||
| 178 | } | ||
| 179 | } | ||
| 180 | } | ||
| 181 | .shadow(color: .black.opacity(0.12), radius: 14, y: 6) | ||
| 182 | } | ||
| 183 | } | ||
| 184 | |||
| 185 | struct LookupProgressOverviewView: View { | ||
| 186 | @Environment(\.appDensity) private var appDensity | ||
| 187 | let steps: [String] | ||
| 188 | |||
| 189 | var body: some View { | ||
| 190 | CardView(allowsHorizontalScroll: false) { | ||
| 191 | HStack(spacing: 8) { | ||
| 192 | ProgressView() | ||
| 193 | .controlSize(.small) | ||
| 194 | VStack(alignment: .leading, spacing: 4) { | ||
| 195 | Text("Running lookup…") | ||
| 196 | .font(appDensity.font(.caption)) | ||
| 197 | .foregroundStyle(.primary) | ||
| 198 | Text(steps.isEmpty ? "Preparing requests" : steps.joined(separator: " • ")) | ||
| 199 | .font(appDensity.font(.caption2)) | ||
| 200 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 201 | } | ||
| 202 | Spacer() | ||
| 203 | } | ||
| 204 | } | ||
| 205 | } | ||
| 206 | } | ||
| 207 | |||
| 208 | struct LookupStatusBannerView: View { | ||
| 209 | @Environment(\.appDensity) private var appDensity | ||
| 210 | let message: String | ||
| 211 | let resultSource: LookupResultSource | ||
| 212 | |||
| 213 | var body: some View { | ||
| 214 | HStack(spacing: 8) { | ||
| 215 | Image(systemName: iconName) | ||
| 216 | .font(.caption) | ||
| 217 | Text(message) | ||
| 218 | .font(appDensity.font(.caption)) | ||
| 219 | Spacer() | ||
| 220 | } | ||
| 221 | .foregroundStyle(color) | ||
| 222 | .padding(appDensity.metrics.cardPadding - 2) | ||
| 223 | .frame(maxWidth: .infinity, alignment: .leading) | ||
| 224 | .background(color.opacity(0.12)) | ||
| 225 | .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius)) | ||
| 226 | } | ||
| 227 | |||
| 228 | private var color: Color { | ||
| 229 | switch resultSource { | ||
| 230 | case .live: | ||
| 231 | return Color(.statusPositive) | ||
| 232 | case .cached: | ||
| 233 | return .secondary | ||
| 234 | case .mixed: | ||
| 235 | return Color(.statusWarning) | ||
| 236 | case .snapshot: | ||
| 237 | return Color(.statusWarning) | ||
| 238 | } | ||
| 239 | } | ||
| 240 | |||
| 241 | private var iconName: String { | ||
| 242 | switch resultSource { | ||
| 243 | case .live: | ||
| 244 | return "bolt.horizontal" | ||
| 245 | case .cached: | ||
| 246 | return "clock.arrow.trianglehead.counterclockwise.rotate.90" | ||
| 247 | case .mixed: | ||
| 248 | return "arrow.triangle.branch" | ||
| 249 | case .snapshot: | ||
| 250 | return "archivebox" | ||
| 251 | } | ||
| 252 | } | ||
| 253 | } | ||
DomainDig/NetworkSectionView.swift added +249
| @@ -0,0 +1,249 @@ | |||
| 1 | import MapKit | ||
| 2 | import SwiftUI | ||
| 3 | |||
| 4 | // One inspection section: the reachability, location and ports cards. Pure | ||
| 5 | // presentation over the view model's report data; the shared primitives it | ||
| 6 | // builds on (CardView, SectionTitleView, LabeledValueRow, ResultColors, | ||
| 7 | // appLoadingStyle) live in ResultPrimitives.swift. | ||
| 8 | |||
| 9 | struct NetworkSectionView: View { | ||
| 10 | @Environment(\.appDensity) private var appDensity | ||
| 11 | @Binding var isCollapsed: Bool | ||
| 12 | @Binding var customPortsExpanded: Bool | ||
| 13 | @Binding var customPortInput: String | ||
| 14 | let onScanCustomPorts: () -> Void | ||
| 15 | |||
| 16 | private let reachabilityRows: [ReachabilityRowViewData] | ||
| 17 | private let reachabilityLoading: Bool | ||
| 18 | private let reachabilityError: String? | ||
| 19 | private let reachabilityProvenance: SectionProvenance? | ||
| 20 | private let locationRows: [InfoRowViewData] | ||
| 21 | private let geolocation: IPGeolocation? | ||
| 22 | private let geolocationLoading: Bool | ||
| 23 | private let geolocationError: String? | ||
| 24 | private let geolocationProvenance: SectionProvenance? | ||
| 25 | private let geolocationConfidence: ConfidenceLevel? | ||
| 26 | private let standardPortRows: [PortScanRowViewData] | ||
| 27 | private let customPortRows: [PortScanRowViewData] | ||
| 28 | private let portScanLoading: Bool | ||
| 29 | private let portScanError: String? | ||
| 30 | private let portScanProvenance: SectionProvenance? | ||
| 31 | private let customPortScanLoading: Bool | ||
| 32 | private let customPortScanError: String? | ||
| 33 | private let isCloudflareProxied: Bool | ||
| 34 | |||
| 35 | init( | ||
| 36 | isCollapsed: Binding<Bool>, | ||
| 37 | customPortsExpanded: Binding<Bool>, | ||
| 38 | customPortInput: Binding<String>, | ||
| 39 | data: NetworkSectionViewData, | ||
| 40 | onScanCustomPorts: @escaping () -> Void | ||
| 41 | ) { | ||
| 42 | _isCollapsed = isCollapsed | ||
| 43 | _customPortsExpanded = customPortsExpanded | ||
| 44 | _customPortInput = customPortInput | ||
| 45 | self.onScanCustomPorts = onScanCustomPorts | ||
| 46 | reachabilityRows = data.reachabilityRows | ||
| 47 | reachabilityLoading = data.reachability.isLoading | ||
| 48 | reachabilityError = data.reachability.error | ||
| 49 | reachabilityProvenance = data.reachability.provenance | ||
| 50 | locationRows = data.locationRows | ||
| 51 | geolocation = data.geolocation | ||
| 52 | geolocationLoading = data.location.isLoading | ||
| 53 | geolocationError = data.location.error | ||
| 54 | geolocationProvenance = data.location.provenance | ||
| 55 | geolocationConfidence = data.location.confidence | ||
| 56 | standardPortRows = data.standardPortRows | ||
| 57 | customPortRows = data.customPortRows | ||
| 58 | portScanLoading = data.portScan.isLoading | ||
| 59 | portScanError = data.portScan.error | ||
| 60 | portScanProvenance = data.portScan.provenance | ||
| 61 | customPortScanLoading = data.customPortScan.isLoading | ||
| 62 | customPortScanError = data.customPortScan.error | ||
| 63 | isCloudflareProxied = data.isCloudflareProxied | ||
| 64 | } | ||
| 65 | |||
| 66 | var body: some View { | ||
| 67 | CollapsibleSectionView(title: "Network", isCollapsed: $isCollapsed) { | ||
| 68 | CardView { | ||
| 69 | Text("Reachability") | ||
| 70 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 71 | .foregroundStyle(Color(.statusInfo)) | ||
| 72 | SectionTrustMetadataView(provenance: reachabilityProvenance, confidence: nil) | ||
| 73 | if reachabilityLoading { | ||
| 74 | ProgressView("Checking ports…") | ||
| 75 | .appLoadingStyle() | ||
| 76 | } else if let reachabilityError { | ||
| 77 | MessageRowView(text: reachabilityError, isError: true) | ||
| 78 | } else { | ||
| 79 | ForEach(reachabilityRows) { row in | ||
| 80 | HStack { | ||
| 81 | Text(row.portLabel) | ||
| 82 | .font(appDensity.font(.caption)) | ||
| 83 | Spacer() | ||
| 84 | Text(row.latencyLabel) | ||
| 85 | .font(appDensity.font(.caption2)) | ||
| 86 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 87 | AppStatusBadgeView(model: reachabilityBadge(row)) | ||
| 88 | } | ||
| 89 | } | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | CardView(allowsHorizontalScroll: false) { | ||
| 94 | Text("Location") | ||
| 95 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 96 | .foregroundStyle(Color(.statusInfo)) | ||
| 97 | SectionTrustMetadataView(provenance: geolocationProvenance, confidence: geolocationConfidence) | ||
| 98 | if geolocationLoading { | ||
| 99 | ProgressView("Looking up location…") | ||
| 100 | .appLoadingStyle() | ||
| 101 | } else if let geolocationError, geolocation == nil { | ||
| 102 | MessageRowView(text: geolocationError, isError: geolocationError != "No A record available") | ||
| 103 | } else if let geolocation { | ||
| 104 | ForEach(locationRows) { row in | ||
| 105 | LabeledValueRow(row: row) | ||
| 106 | } | ||
| 107 | if let latitude = geolocation.latitude, let longitude = geolocation.longitude { | ||
| 108 | let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude) | ||
| 109 | Map(initialPosition: .region(MKCoordinateRegion( | ||
| 110 | center: coordinate, | ||
| 111 | span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1) | ||
| 112 | ))) { | ||
| 113 | Marker(geolocation.ip, coordinate: coordinate) | ||
| 114 | } | ||
| 115 | .mapStyle(.standard) | ||
| 116 | .frame(maxWidth: .infinity) | ||
| 117 | .frame(height: 180) | ||
| 118 | .cornerRadius(8) | ||
| 119 | } | ||
| 120 | } else { | ||
| 121 | MessageRowView(text: "No location data available", isError: false) | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | CardView(allowsHorizontalScroll: false) { | ||
| 126 | Text("Port Scan") | ||
| 127 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 128 | .foregroundStyle(Color(.statusInfo)) | ||
| 129 | SectionTrustMetadataView(provenance: portScanProvenance, confidence: nil) | ||
| 130 | |||
| 131 | if isCloudflareProxied { | ||
| 132 | Text("Domain is behind Cloudflare's proxy. Results reflect the edge, not the origin.") | ||
| 133 | .font(appDensity.font(.caption2)) | ||
| 134 | .foregroundStyle(Color(.statusWarning)) | ||
| 135 | .fixedSize(horizontal: false, vertical: true) | ||
| 136 | } | ||
| 137 | |||
| 138 | if portScanLoading { | ||
| 139 | ProgressView("Scanning ports…") | ||
| 140 | .appLoadingStyle() | ||
| 141 | } else if let portScanError, standardPortRows.isEmpty { | ||
| 142 | MessageRowView(text: portScanError, isError: true) | ||
| 143 | } else { | ||
| 144 | Text("Standard Ports") | ||
| 145 | .font(.system(.caption, design: .monospaced)) | ||
| 146 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 147 | PortRowsView(rows: standardPortRows) | ||
| 148 | } | ||
| 149 | |||
| 150 | DisclosureGroup("Custom Ports", isExpanded: $customPortsExpanded) { | ||
| 151 | VStack(alignment: .leading, spacing: 10) { | ||
| 152 | TextField("8888, 9000, 27017", text: $customPortInput) | ||
| 153 | .font(appDensity.font(.caption)) | ||
| 154 | .textInputAutocapitalization(.never) | ||
| 155 | .autocorrectionDisabled() | ||
| 156 | .keyboardType(.numberPad) | ||
| 157 | .padding(10) | ||
| 158 | .background(Color(.appSurface)) | ||
| 159 | .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius)) | ||
| 160 | |||
| 161 | Button("Scan") { | ||
| 162 | AppHaptics.refresh() | ||
| 163 | onScanCustomPorts() | ||
| 164 | } | ||
| 165 | .buttonStyle(.borderedProminent) | ||
| 166 | .tint(Color(.accentFill)) | ||
| 167 | .disabled(customPortScanLoading) | ||
| 168 | |||
| 169 | if customPortScanLoading { | ||
| 170 | ProgressView("Scanning custom ports…") | ||
| 171 | .appLoadingStyle() | ||
| 172 | } else if let customPortScanError { | ||
| 173 | MessageRowView(text: customPortScanError, isError: true) | ||
| 174 | } else { | ||
| 175 | PortRowsView(rows: customPortRows) | ||
| 176 | } | ||
| 177 | } | ||
| 178 | .padding(.top, 8) | ||
| 179 | } | ||
| 180 | .font(.system(.caption, design: .monospaced)) | ||
| 181 | .tint(.secondary) | ||
| 182 | } | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 | private func reachabilityBadge(_ row: ReachabilityRowViewData) -> AppStatusBadgeModel { | ||
| 187 | switch row.statusTone { | ||
| 188 | case .success: | ||
| 189 | return .init(title: row.statusLabel, systemImage: "checkmark.circle.fill", foregroundColor: Color(.statusPositive), backgroundColor: Color(.statusPositiveSurface)) | ||
| 190 | case .warning: | ||
| 191 | return .init(title: row.statusLabel, systemImage: "exclamationmark.triangle.fill", foregroundColor: Color(.statusWarning), backgroundColor: Color(.statusWarningSurface)) | ||
| 192 | case .failure: | ||
| 193 | return .init(title: row.statusLabel, systemImage: "xmark.circle.fill", foregroundColor: Color(.statusCritical), backgroundColor: Color(.statusCriticalSurface)) | ||
| 194 | case .primary, .secondary: | ||
| 195 | return .init(title: row.statusLabel, systemImage: "circle", foregroundColor: Color(.appTextSecondary), backgroundColor: Color(.appSurfaceElevated)) | ||
| 196 | } | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | struct PortRowsView: View { | ||
| 201 | @Environment(\.appDensity) private var appDensity | ||
| 202 | let rows: [PortScanRowViewData] | ||
| 203 | |||
| 204 | var body: some View { | ||
| 205 | if rows.isEmpty { | ||
| 206 | MessageRowView(text: "No results", isError: false) | ||
| 207 | } else { | ||
| 208 | ForEach(rows) { row in | ||
| 209 | VStack(alignment: .leading, spacing: appDensity.metrics.rowSpacing - 1) { | ||
| 210 | HStack { | ||
| 211 | Text(row.portLabel) | ||
| 212 | .font(appDensity.font(.caption)) | ||
| 213 | .frame(width: 52, alignment: .leading) | ||
| 214 | Text(row.service) | ||
| 215 | .font(appDensity.font(.caption)) | ||
| 216 | .foregroundStyle(.primary) | ||
| 217 | Spacer() | ||
| 218 | if let durationLabel = row.durationLabel { | ||
| 219 | Text(durationLabel) | ||
| 220 | .font(appDensity.font(.caption2)) | ||
| 221 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 222 | } | ||
| 223 | AppStatusBadgeView(model: portBadge(row)) | ||
| 224 | } | ||
| 225 | if let banner = row.banner { | ||
| 226 | Text(banner) | ||
| 227 | .font(appDensity.font(.caption2)) | ||
| 228 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 229 | .padding(.leading, 8) | ||
| 230 | } | ||
| 231 | } | ||
| 232 | .frame(minHeight: appDensity.metrics.rowMinHeight, alignment: .topLeading) | ||
| 233 | } | ||
| 234 | } | ||
| 235 | } | ||
| 236 | |||
| 237 | private func portBadge(_ row: PortScanRowViewData) -> AppStatusBadgeModel { | ||
| 238 | switch row.statusTone { | ||
| 239 | case .success: | ||
| 240 | return .init(title: row.statusLabel, systemImage: "checkmark.circle.fill", foregroundColor: Color(.statusPositive), backgroundColor: Color(.statusPositiveSurface)) | ||
| 241 | case .warning: | ||
| 242 | return .init(title: row.statusLabel, systemImage: "exclamationmark.triangle.fill", foregroundColor: Color(.statusWarning), backgroundColor: Color(.statusWarningSurface)) | ||
| 243 | case .failure: | ||
| 244 | return .init(title: row.statusLabel, systemImage: "xmark.circle.fill", foregroundColor: Color(.statusCritical), backgroundColor: Color(.statusCriticalSurface)) | ||
| 245 | case .primary, .secondary: | ||
| 246 | return .init(title: row.statusLabel, systemImage: "circle", foregroundColor: Color(.appTextSecondary), backgroundColor: Color(.appSurfaceElevated)) | ||
| 247 | } | ||
| 248 | } | ||
| 249 | } | ||
DomainDig/OwnershipSectionView.swift added +103
| @@ -0,0 +1,103 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | // One inspection section: the registration and ownership card. Pure | ||
| 4 | // presentation over the view model's report data; the shared primitives it | ||
| 5 | // builds on (CardView, SectionTitleView, LabeledValueRow, ResultColors, | ||
| 6 | // appLoadingStyle) live in ResultPrimitives.swift. | ||
| 7 | |||
| 8 | struct OwnershipSectionView: View { | ||
| 9 | @Environment(\.appDensity) private var appDensity | ||
| 10 | @Binding var isCollapsed: Bool | ||
| 11 | let rows: [InfoRowViewData] | ||
| 12 | let loading: Bool | ||
| 13 | let error: String? | ||
| 14 | let provenance: SectionProvenance? | ||
| 15 | let confidence: ConfidenceLevel? | ||
| 16 | let history: [DomainOwnershipHistoryEvent] | ||
| 17 | let historyLoading: Bool | ||
| 18 | let historyError: String? | ||
| 19 | let onLoadHistory: (() -> Void)? | ||
| 20 | |||
| 21 | init( | ||
| 22 | isCollapsed: Binding<Bool>, | ||
| 23 | rows: [InfoRowViewData], | ||
| 24 | loading: Bool, | ||
| 25 | error: String?, | ||
| 26 | provenance: SectionProvenance?, | ||
| 27 | confidence: ConfidenceLevel?, | ||
| 28 | history: [DomainOwnershipHistoryEvent] = [], | ||
| 29 | historyLoading: Bool = false, | ||
| 30 | historyError: String? = nil, | ||
| 31 | onLoadHistory: (() -> Void)? = nil | ||
| 32 | ) { | ||
| 33 | _isCollapsed = isCollapsed | ||
| 34 | self.rows = rows | ||
| 35 | self.loading = loading | ||
| 36 | self.error = error | ||
| 37 | self.provenance = provenance | ||
| 38 | self.confidence = confidence | ||
| 39 | self.history = history | ||
| 40 | self.historyLoading = historyLoading | ||
| 41 | self.historyError = historyError | ||
| 42 | self.onLoadHistory = onLoadHistory | ||
| 43 | } | ||
| 44 | |||
| 45 | var body: some View { | ||
| 46 | CollapsibleSectionView(title: "Ownership", isCollapsed: $isCollapsed) { | ||
| 47 | CardView(allowsHorizontalScroll: false) { | ||
| 48 | SectionTrustMetadataView(provenance: provenance, confidence: confidence) | ||
| 49 | if loading { | ||
| 50 | ProgressView("Fetching RDAP ownership…") | ||
| 51 | .appLoadingStyle() | ||
| 52 | } else { | ||
| 53 | ForEach(rows) { row in | ||
| 54 | LabeledValueRow(row: row) | ||
| 55 | } | ||
| 56 | if let error, rows.allSatisfy({ $0.value == "Unavailable" }) { | ||
| 57 | MessageRowView(text: error, isError: error != "Unavailable") | ||
| 58 | .padding(.top, 4) | ||
| 59 | } | ||
| 60 | historyBlock | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | @ViewBuilder | ||
| 67 | private var historyBlock: some View { | ||
| 68 | VStack(alignment: .leading, spacing: 8) { | ||
| 69 | HStack { | ||
| 70 | Text("History") | ||
| 71 | .font(appDensity.font(.caption)) | ||
| 72 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 73 | Spacer() | ||
| 74 | if let onLoadHistory, history.isEmpty, !historyLoading { | ||
| 75 | Button("Load") { | ||
| 76 | onLoadHistory() | ||
| 77 | } | ||
| 78 | .buttonStyle(.bordered) | ||
| 79 | .font(appDensity.font(.caption2)) | ||
| 80 | } | ||
| 81 | } | ||
| 82 | if historyLoading { | ||
| 83 | ProgressView("Loading history…") | ||
| 84 | .appLoadingStyle() | ||
| 85 | } else if !history.isEmpty { | ||
| 86 | ForEach(history) { event in | ||
| 87 | VStack(alignment: .leading, spacing: 3) { | ||
| 88 | Text(event.date.formatted(date: .abbreviated, time: .omitted)) | ||
| 89 | .font(appDensity.font(.caption2)) | ||
| 90 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 91 | Text(event.summary) | ||
| 92 | .font(appDensity.font(.caption)) | ||
| 93 | Text(event.source) | ||
| 94 | .font(appDensity.font(.caption2)) | ||
| 95 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 96 | } | ||
| 97 | } | ||
| 98 | } else if let historyError { | ||
| 99 | MessageRowView(text: historyError, isError: false) | ||
| 100 | } | ||
| 101 | } | ||
| 102 | } | ||
| 103 | } | ||
DomainDig/ResultPrimitives.swift added +325
| @@ -0,0 +1,325 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | // The shared presentation primitives every result view builds on — cards, | ||
| 4 | // rows, section titles, trust metadata, colours — and the small formatting | ||
| 5 | // extensions that go with them. Split out of ContentView.swift (A13). | ||
| 6 | |||
| 7 | struct TrackedDomainDetailHeaderView: View { | ||
| 8 | let trackedDomain: TrackedDomain | ||
| 9 | |||
| 10 | var body: some View { | ||
| 11 | VStack(alignment: .leading, spacing: 4) { | ||
| 12 | if let note = trackedDomain.note?.nilIfEmpty { | ||
| 13 | LabeledValueRow(row: InfoRowViewData(label: "Tracking Note", value: note, tone: .secondary)) | ||
| 14 | } | ||
| 15 | HStack(spacing: 8) { | ||
| 16 | if trackedDomain.isPinned { | ||
| 17 | Label("Pinned", systemImage: "pin.fill") | ||
| 18 | } | ||
| 19 | Text("Last refresh \(trackedDomain.updatedAt.formatted(date: .abbreviated, time: .shortened))") | ||
| 20 | } | ||
| 21 | .font(.system(.caption2, design: .monospaced)) | ||
| 22 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 23 | } | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | struct SectionTitleView: View { | ||
| 28 | @Environment(\.appDensity) private var appDensity | ||
| 29 | let title: String | ||
| 30 | |||
| 31 | var body: some View { | ||
| 32 | Text(title) | ||
| 33 | .font(appDensity.font(.headline, design: .default, weight: .semibold)) | ||
| 34 | .foregroundStyle(.primary) | ||
| 35 | .accessibilityAddTraits(.isHeader) | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | /// A card that wraps its content by default. | ||
| 40 | /// | ||
| 41 | /// `allowsHorizontalScroll` used to default to `true`, so nine call sites put | ||
| 42 | /// their content behind a horizontal gesture instead of letting it wrap — a | ||
| 43 | /// WCAG 1.4.10 (Reflow) failure, and the mechanism behind clipped rows at large | ||
| 44 | /// text sizes. It also forced VoiceOver and Switch Control users onto a nested | ||
| 45 | /// scroll axis to reach data. | ||
| 46 | /// | ||
| 47 | /// The default is now `false`. Where horizontal scrolling genuinely suits wide | ||
| 48 | /// tabular content, it is still opt-in — but it is suppressed at accessibility | ||
| 49 | /// text sizes, where wrapping always beats a hidden axis. | ||
| 50 | struct CardView<Content: View>: View { | ||
| 51 | @Environment(\.appDensity) private var appDensity | ||
| 52 | @Environment(\.dynamicTypeSize) private var dynamicTypeSize | ||
| 53 | let allowsHorizontalScroll: Bool | ||
| 54 | let content: Content | ||
| 55 | |||
| 56 | init(allowsHorizontalScroll: Bool = false, @ViewBuilder content: () -> Content) { | ||
| 57 | self.allowsHorizontalScroll = allowsHorizontalScroll | ||
| 58 | self.content = content() | ||
| 59 | } | ||
| 60 | |||
| 61 | var body: some View { | ||
| 62 | Group { | ||
| 63 | if allowsHorizontalScroll, !dynamicTypeSize.isAccessibilitySize { | ||
| 64 | ScrollView(.horizontal) { | ||
| 65 | cardContent | ||
| 66 | .scrollTargetLayout() | ||
| 67 | } | ||
| 68 | .scrollBounceBehavior(.basedOnSize, axes: .horizontal) | ||
| 69 | } else { | ||
| 70 | cardContent | ||
| 71 | .frame(maxWidth: .infinity, alignment: .leading) | ||
| 72 | } | ||
| 73 | } | ||
| 74 | .frame(maxWidth: .infinity, alignment: .leading) | ||
| 75 | .padding(appDensity.metrics.cardPadding) | ||
| 76 | .background(Color(.appSurface)) | ||
| 77 | .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius)) | ||
| 78 | } | ||
| 79 | |||
| 80 | private var cardContent: some View { | ||
| 81 | VStack(alignment: .leading, spacing: appDensity.metrics.cardSpacing) { | ||
| 82 | content | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | struct LoadingCardView: View { | ||
| 88 | let text: String | ||
| 89 | |||
| 90 | var body: some View { | ||
| 91 | CardView { | ||
| 92 | ProgressView(text) | ||
| 93 | .appLoadingStyle() | ||
| 94 | .frame(maxWidth: .infinity, alignment: .center) | ||
| 95 | } | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | struct MessageCardView: View { | ||
| 100 | let text: String | ||
| 101 | let isError: Bool | ||
| 102 | |||
| 103 | var body: some View { | ||
| 104 | CardView { | ||
| 105 | MessageRowView(text: text, isError: isError) | ||
| 106 | } | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | struct MessageRowView: View { | ||
| 111 | @Environment(\.appDensity) private var appDensity | ||
| 112 | let text: String | ||
| 113 | let isError: Bool | ||
| 114 | |||
| 115 | var body: some View { | ||
| 116 | Label(text, systemImage: isError ? "exclamationmark.triangle.fill" : "info.circle") | ||
| 117 | .font(appDensity.font(.caption)) | ||
| 118 | .foregroundStyle(isError ? Color(.statusCritical) : .secondary) | ||
| 119 | .lineLimit(nil) | ||
| 120 | .fixedSize(horizontal: false, vertical: true) | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | struct SectionTrustMetadataView: View { | ||
| 125 | @Environment(\.appDensity) private var appDensity | ||
| 126 | let provenance: SectionProvenance? | ||
| 127 | let confidence: ConfidenceLevel? | ||
| 128 | let note: String? | ||
| 129 | |||
| 130 | init(provenance: SectionProvenance?, confidence: ConfidenceLevel?, note: String? = nil) { | ||
| 131 | self.provenance = provenance | ||
| 132 | self.confidence = confidence | ||
| 133 | self.note = note | ||
| 134 | } | ||
| 135 | |||
| 136 | var body: some View { | ||
| 137 | if provenance != nil || confidence != nil || note != nil { | ||
| 138 | VStack(alignment: .leading, spacing: 6) { | ||
| 139 | HStack(spacing: 8) { | ||
| 140 | if let confidence { | ||
| 141 | Text("Confidence \(confidence.title)") | ||
| 142 | .font(appDensity.font(.caption2)) | ||
| 143 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 144 | } | ||
| 145 | if let provenance { | ||
| 146 | Text(provenance.provider ?? provenance.source) | ||
| 147 | .font(appDensity.font(.caption2)) | ||
| 148 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 149 | Text(provenance.resultSource.label) | ||
| 150 | .font(appDensity.font(.caption2)) | ||
| 151 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 152 | } | ||
| 153 | } | ||
| 154 | DisclosureGroup("Details") { | ||
| 155 | VStack(alignment: .leading, spacing: 4) { | ||
| 156 | if let provenance { | ||
| 157 | LabeledValueRow(row: .init(label: "Method", value: provenance.source, tone: .secondary)) | ||
| 158 | if let provider = provenance.provider { | ||
| 159 | LabeledValueRow(row: .init(label: "Provider", value: provider, tone: .secondary)) | ||
| 160 | } | ||
| 161 | if let resolver = provenance.resolver { | ||
| 162 | LabeledValueRow(row: .init(label: "Resolver", value: resolver, tone: .secondary)) | ||
| 163 | } | ||
| 164 | LabeledValueRow(row: .init(label: "Collected", value: provenance.collectedAt.formatted(date: .abbreviated, time: .shortened), tone: .secondary)) | ||
| 165 | LabeledValueRow(row: .init(label: "Mode", value: provenance.resultSource.label, tone: .secondary)) | ||
| 166 | } | ||
| 167 | if let note { | ||
| 168 | LabeledValueRow(row: .init(label: "Note", value: note, tone: .secondary)) | ||
| 169 | } | ||
| 170 | } | ||
| 171 | .padding(.top, 4) | ||
| 172 | } | ||
| 173 | .font(appDensity.font(.caption)) | ||
| 174 | .tint(.secondary) | ||
| 175 | } | ||
| 176 | } | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | struct LabeledValueRow: View { | ||
| 181 | @Environment(\.appDensity) private var appDensity | ||
| 182 | @Environment(\.accessibilityDifferentiateWithoutColor) private var differentiateWithoutColor | ||
| 183 | let row: InfoRowViewData | ||
| 184 | |||
| 185 | var body: some View { | ||
| 186 | VStack(alignment: .leading, spacing: appDensity.metrics.rowSpacing - 1) { | ||
| 187 | HStack(alignment: .top, spacing: 8) { | ||
| 188 | VStack(alignment: .leading, spacing: appDensity.metrics.rowSpacing - 1) { | ||
| 189 | Text(row.label) | ||
| 190 | .font(appDensity.font(.caption2)) | ||
| 191 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 192 | HStack(alignment: .firstTextBaseline, spacing: 4) { | ||
| 193 | if differentiateWithoutColor, let symbol = toneSymbol { | ||
| 194 | Image(systemName: symbol) | ||
| 195 | .font(appDensity.font(.caption2)) | ||
| 196 | .foregroundStyle(ResultColors.color(for: row.tone)) | ||
| 197 | .accessibilityHidden(true) | ||
| 198 | } | ||
| 199 | valueText | ||
| 200 | } | ||
| 201 | } | ||
| 202 | .frame(maxWidth: .infinity, alignment: .leading) | ||
| 203 | .layoutPriority(1) | ||
| 204 | Spacer(minLength: 6) | ||
| 205 | if !row.value.isEmpty, row.value != "Unavailable" { | ||
| 206 | AppCopyButton(value: row.value, label: "Copy \(row.label)") | ||
| 207 | } | ||
| 208 | } | ||
| 209 | } | ||
| 210 | .frame(minHeight: appDensity.metrics.rowMinHeight, alignment: .topLeading) | ||
| 211 | } | ||
| 212 | |||
| 213 | /// A leading symbol for warning/failure tones, shown only under Differentiate | ||
| 214 | /// Without Color so tone is not conveyed by text colour alone. Hidden from | ||
| 215 | /// VoiceOver — the value text already carries the meaning. | ||
| 216 | private var toneSymbol: String? { | ||
| 217 | switch row.tone { | ||
| 218 | case .warning: return "exclamationmark.triangle.fill" | ||
| 219 | case .failure: return "xmark.octagon.fill" | ||
| 220 | default: return nil | ||
| 221 | } | ||
| 222 | } | ||
| 223 | |||
| 224 | @ViewBuilder | ||
| 225 | private var valueText: some View { | ||
| 226 | let base = Text(row.value) | ||
| 227 | .font(appDensity.font(.caption)) | ||
| 228 | .foregroundStyle(ResultColors.color(for: row.tone)) | ||
| 229 | |||
| 230 | switch row.speechStyle { | ||
| 231 | case .plain: | ||
| 232 | base | ||
| 233 | .lineLimit(nil) | ||
| 234 | .fixedSize(horizontal: false, vertical: true) | ||
| 235 | .textSelection(.enabled) | ||
| 236 | case .technical: | ||
| 237 | // Record values and identifiers: keep punctuation audible (SPF/DMARC | ||
| 238 | // separators are semantically load-bearing) and let VoiceOver use its | ||
| 239 | // code-reading heuristics. | ||
| 240 | base | ||
| 241 | .speechAlwaysIncludesPunctuation() | ||
| 242 | .accessibilityTextContentType(.sourceCode) | ||
| 243 | .lineLimit(nil) | ||
| 244 | .fixedSize(horizontal: false, vertical: true) | ||
| 245 | .textSelection(.enabled) | ||
| 246 | } | ||
| 247 | } | ||
| 248 | } | ||
| 249 | |||
| 250 | /// Maps a row's semantic tone onto the app palette. | ||
| 251 | /// | ||
| 252 | /// See `Docs/ACCESSIBILITY.md` for the measured contrast ratios behind these | ||
| 253 | /// colours. Never reach for a literal (`Color(.statusCritical)`, `Color(.statusWarning)`, …) — the system | ||
| 254 | /// palette fails WCAG AA badly in light mode (systemYellow is 1.28:1 on white). | ||
| 255 | enum ResultColors { | ||
| 256 | static func color(for tone: ResultTone) -> Color { | ||
| 257 | switch tone { | ||
| 258 | case .primary: | ||
| 259 | return .primary | ||
| 260 | case .secondary: | ||
| 261 | return .secondary | ||
| 262 | case .success: | ||
| 263 | return Color(.statusPositive) | ||
| 264 | case .warning: | ||
| 265 | return Color(.statusWarning) | ||
| 266 | case .failure: | ||
| 267 | return Color(.statusCritical) | ||
| 268 | } | ||
| 269 | } | ||
| 270 | } | ||
| 271 | |||
| 272 | extension DateFormatter { | ||
| 273 | static let certDate: DateFormatter = { | ||
| 274 | let formatter = DateFormatter() | ||
| 275 | formatter.dateStyle = .medium | ||
| 276 | formatter.timeStyle = .short | ||
| 277 | return formatter | ||
| 278 | }() | ||
| 279 | } | ||
| 280 | |||
| 281 | extension View { | ||
| 282 | func appLoadingStyle() -> some View { | ||
| 283 | font(.system(.caption, design: .monospaced)) | ||
| 284 | } | ||
| 285 | } | ||
| 286 | |||
| 287 | private extension String { | ||
| 288 | var nilIfEmpty: String? { | ||
| 289 | isEmpty ? nil : self | ||
| 290 | } | ||
| 291 | } | ||
| 292 | |||
| 293 | extension ChangeImpactClassification { | ||
| 294 | var tone: AppStatusTone { | ||
| 295 | switch self { | ||
| 296 | case .informational: return .neutral | ||
| 297 | case .warning: return .warning | ||
| 298 | case .critical: return .critical | ||
| 299 | } | ||
| 300 | } | ||
| 301 | } | ||
| 302 | |||
| 303 | extension TLSGrade { | ||
| 304 | var tone: ResultTone { | ||
| 305 | switch self { | ||
| 306 | case .a: return .success | ||
| 307 | case .f: return .failure | ||
| 308 | default: return .warning | ||
| 309 | } | ||
| 310 | } | ||
| 311 | } | ||
| 312 | |||
| 313 | extension EmailSecurityGrade { | ||
| 314 | var tone: ResultTone { | ||
| 315 | switch self { | ||
| 316 | case .a: return .success | ||
| 317 | case .f: return .failure | ||
| 318 | default: return .warning | ||
| 319 | } | ||
| 320 | } | ||
| 321 | } | ||
| 322 | |||
| 323 | #Preview { | ||
| 324 | ContentView(viewModel: DomainViewModel()) | ||
| 325 | } | ||
DomainDig/ResultSectionViews.swift deleted −1225
| @@ -1,1225 +0,0 @@ | |||
| 1 | import MapKit | ||
| 2 | import SwiftUI | ||
| 3 | |||
| 4 | // Result detail section views extracted from ContentView.swift — one per | ||
| 5 | // inspection domain (availability/DNS, ownership, intelligence, subdomains, | ||
| 6 | // DNS records, web, email, network, ports). Pure presentation over the | ||
| 7 | // view-model report data; the shared primitives (CardView, SectionTitleView, | ||
| 8 | // LabeledValueRow, ResultColors, appLoadingStyle) remain in ContentView.swift. | ||
| 9 | |||
| 10 | struct DomainSectionView: View { | ||
| 11 | @Environment(\.appDensity) private var appDensity | ||
| 12 | @Binding var isCollapsed: Bool | ||
| 13 | let rows: [InfoRowViewData] | ||
| 14 | let suggestions: [DomainSuggestionViewData] | ||
| 15 | let showSuggestions: Bool | ||
| 16 | let availabilityLoading: Bool | ||
| 17 | let suggestionsLoading: Bool | ||
| 18 | let provenance: SectionProvenance? | ||
| 19 | let confidence: ConfidenceLevel? | ||
| 20 | let snapshotNote: String? | ||
| 21 | let trackedDomain: TrackedDomain? | ||
| 22 | let workflows: [DomainWorkflow] | ||
| 23 | let trackingLimitMessage: String? | ||
| 24 | let onTrack: () -> Void | ||
| 25 | let onTogglePinned: () -> Void | ||
| 26 | let onEditNote: (() -> Void)? | ||
| 27 | let onAddToWorkflow: (() -> Void)? | ||
| 28 | let onOpenWorkflow: ((DomainWorkflow) -> Void)? | ||
| 29 | let onRunWorkflow: ((DomainWorkflow) -> Void)? | ||
| 30 | |||
| 31 | var body: some View { | ||
| 32 | CollapsibleSectionView(title: "Domain", isCollapsed: $isCollapsed) { | ||
| 33 | if let trackedDomain { | ||
| 34 | HStack(spacing: 8) { | ||
| 35 | // Icon-only: the header also carries Pin and Note, and the | ||
| 36 | // full "Tracked" pill compresses at larger text sizes. | ||
| 37 | // VoiceOver still hears the word via the label. | ||
| 38 | Image(systemName: "eye.fill") | ||
| 39 | .font(appDensity.font(.caption)) | ||
| 40 | .foregroundStyle(Color(.statusPositive)) | ||
| 41 | .padding(6) | ||
| 42 | .background(Color(.statusPositiveSurface), in: Circle()) | ||
| 43 | .fixedSize() | ||
| 44 | .accessibilityLabel("Tracked") | ||
| 45 | Button { | ||
| 46 | onTogglePinned() | ||
| 47 | } label: { | ||
| 48 | Image(systemName: trackedDomain.isPinned ? "pin.fill" : "pin") | ||
| 49 | } | ||
| 50 | .buttonStyle(.bordered) | ||
| 51 | .font(appDensity.font(.caption)) | ||
| 52 | .accessibilityLabel("Pin domain") | ||
| 53 | .accessibilityValue(trackedDomain.isPinned ? "Pinned" : "Not pinned") | ||
| 54 | .accessibilityAddTraits(trackedDomain.isPinned ? .isSelected : []) | ||
| 55 | if let onEditNote { | ||
| 56 | Button("Note") { | ||
| 57 | onEditNote() | ||
| 58 | } | ||
| 59 | .buttonStyle(.bordered) | ||
| 60 | .font(appDensity.font(.caption)) | ||
| 61 | // Never compress into a vertical letter column. | ||
| 62 | .fixedSize() | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } else { | ||
| 66 | Button("Track") { | ||
| 67 | AppHaptics.track() | ||
| 68 | onTrack() | ||
| 69 | } | ||
| 70 | .buttonStyle(.bordered) | ||
| 71 | .font(appDensity.font(.caption)) | ||
| 72 | .fixedSize() | ||
| 73 | } | ||
| 74 | } content: { | ||
| 75 | CardView(allowsHorizontalScroll: false) { | ||
| 76 | SectionTrustMetadataView( | ||
| 77 | provenance: provenance, | ||
| 78 | confidence: confidence, | ||
| 79 | note: snapshotNote == nil ? nil : "Audit note present" | ||
| 80 | ) | ||
| 81 | ForEach(rows) { row in | ||
| 82 | LabeledValueRow(row: row) | ||
| 83 | } | ||
| 84 | if let trackedDomain { | ||
| 85 | TrackedDomainDetailHeaderView(trackedDomain: trackedDomain) | ||
| 86 | .padding(.top, 4) | ||
| 87 | } else if let trackingLimitMessage { | ||
| 88 | MessageRowView(text: trackingLimitMessage, isError: false) | ||
| 89 | .padding(.top, 4) | ||
| 90 | } | ||
| 91 | if let onAddToWorkflow { | ||
| 92 | Button { | ||
| 93 | onAddToWorkflow() | ||
| 94 | } label: { | ||
| 95 | Label("Add to workflow", systemImage: "plus.rectangle.on.folder") | ||
| 96 | .font(appDensity.font(.caption)) | ||
| 97 | } | ||
| 98 | .buttonStyle(.bordered) | ||
| 99 | .padding(.top, 4) | ||
| 100 | } | ||
| 101 | if !workflows.isEmpty { | ||
| 102 | VStack(alignment: .leading, spacing: 8) { | ||
| 103 | Text("Part of workflow") | ||
| 104 | .font(appDensity.font(.caption)) | ||
| 105 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 106 | |||
| 107 | ForEach(workflows) { workflow in | ||
| 108 | HStack { | ||
| 109 | Text(workflow.name) | ||
| 110 | .font(appDensity.font(.caption)) | ||
| 111 | .foregroundStyle(.primary) | ||
| 112 | Spacer() | ||
| 113 | if let onOpenWorkflow { | ||
| 114 | Button("Open") { | ||
| 115 | onOpenWorkflow(workflow) | ||
| 116 | } | ||
| 117 | .buttonStyle(.bordered) | ||
| 118 | .font(appDensity.font(.caption2)) | ||
| 119 | } | ||
| 120 | if let onRunWorkflow { | ||
| 121 | Button("Run") { | ||
| 122 | onRunWorkflow(workflow) | ||
| 123 | } | ||
| 124 | .buttonStyle(.bordered) | ||
| 125 | .font(appDensity.font(.caption2)) | ||
| 126 | } | ||
| 127 | } | ||
| 128 | } | ||
| 129 | } | ||
| 130 | .padding(.top, 4) | ||
| 131 | } | ||
| 132 | if availabilityLoading { | ||
| 133 | ProgressView("Checking availability…") | ||
| 134 | .appLoadingStyle() | ||
| 135 | .padding(.top, 4) | ||
| 136 | } | ||
| 137 | if showSuggestions { | ||
| 138 | Text("Suggestions") | ||
| 139 | .font(appDensity.font(.caption)) | ||
| 140 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 141 | .padding(.top, 4) | ||
| 142 | if suggestionsLoading { | ||
| 143 | ProgressView("Checking alternatives…") | ||
| 144 | .appLoadingStyle() | ||
| 145 | } else if suggestions.isEmpty { | ||
| 146 | MessageRowView(text: "No suggestions", isError: false) | ||
| 147 | } else { | ||
| 148 | ForEach(suggestions) { suggestion in | ||
| 149 | HStack { | ||
| 150 | Text(suggestion.domain) | ||
| 151 | .font(appDensity.font(.caption)) | ||
| 152 | .foregroundStyle(.primary) | ||
| 153 | .textSelection(.enabled) | ||
| 154 | Spacer() | ||
| 155 | AppStatusBadgeView(model: AppStatusFactory.availability(suggestion.availabilityStatus)) | ||
| 156 | } | ||
| 157 | } | ||
| 158 | } | ||
| 159 | } | ||
| 160 | } | ||
| 161 | } | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | struct OwnershipSectionView: View { | ||
| 166 | @Environment(\.appDensity) private var appDensity | ||
| 167 | @Binding var isCollapsed: Bool | ||
| 168 | let rows: [InfoRowViewData] | ||
| 169 | let loading: Bool | ||
| 170 | let error: String? | ||
| 171 | let provenance: SectionProvenance? | ||
| 172 | let confidence: ConfidenceLevel? | ||
| 173 | let history: [DomainOwnershipHistoryEvent] | ||
| 174 | let historyLoading: Bool | ||
| 175 | let historyError: String? | ||
| 176 | let onLoadHistory: (() -> Void)? | ||
| 177 | |||
| 178 | init( | ||
| 179 | isCollapsed: Binding<Bool>, | ||
| 180 | rows: [InfoRowViewData], | ||
| 181 | loading: Bool, | ||
| 182 | error: String?, | ||
| 183 | provenance: SectionProvenance?, | ||
| 184 | confidence: ConfidenceLevel?, | ||
| 185 | history: [DomainOwnershipHistoryEvent] = [], | ||
| 186 | historyLoading: Bool = false, | ||
| 187 | historyError: String? = nil, | ||
| 188 | onLoadHistory: (() -> Void)? = nil | ||
| 189 | ) { | ||
| 190 | _isCollapsed = isCollapsed | ||
| 191 | self.rows = rows | ||
| 192 | self.loading = loading | ||
| 193 | self.error = error | ||
| 194 | self.provenance = provenance | ||
| 195 | self.confidence = confidence | ||
| 196 | self.history = history | ||
| 197 | self.historyLoading = historyLoading | ||
| 198 | self.historyError = historyError | ||
| 199 | self.onLoadHistory = onLoadHistory | ||
| 200 | } | ||
| 201 | |||
| 202 | var body: some View { | ||
| 203 | CollapsibleSectionView(title: "Ownership", isCollapsed: $isCollapsed) { | ||
| 204 | CardView(allowsHorizontalScroll: false) { | ||
| 205 | SectionTrustMetadataView(provenance: provenance, confidence: confidence) | ||
| 206 | if loading { | ||
| 207 | ProgressView("Fetching RDAP ownership…") | ||
| 208 | .appLoadingStyle() | ||
| 209 | } else { | ||
| 210 | ForEach(rows) { row in | ||
| 211 | LabeledValueRow(row: row) | ||
| 212 | } | ||
| 213 | if let error, rows.allSatisfy({ $0.value == "Unavailable" }) { | ||
| 214 | MessageRowView(text: error, isError: error != "Unavailable") | ||
| 215 | .padding(.top, 4) | ||
| 216 | } | ||
| 217 | historyBlock | ||
| 218 | } | ||
| 219 | } | ||
| 220 | } | ||
| 221 | } | ||
| 222 | |||
| 223 | @ViewBuilder | ||
| 224 | private var historyBlock: some View { | ||
| 225 | VStack(alignment: .leading, spacing: 8) { | ||
| 226 | HStack { | ||
| 227 | Text("History") | ||
| 228 | .font(appDensity.font(.caption)) | ||
| 229 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 230 | Spacer() | ||
| 231 | if let onLoadHistory, history.isEmpty, !historyLoading { | ||
| 232 | Button("Load") { | ||
| 233 | onLoadHistory() | ||
| 234 | } | ||
| 235 | .buttonStyle(.bordered) | ||
| 236 | .font(appDensity.font(.caption2)) | ||
| 237 | } | ||
| 238 | } | ||
| 239 | if historyLoading { | ||
| 240 | ProgressView("Loading history…") | ||
| 241 | .appLoadingStyle() | ||
| 242 | } else if !history.isEmpty { | ||
| 243 | ForEach(history) { event in | ||
| 244 | VStack(alignment: .leading, spacing: 3) { | ||
| 245 | Text(event.date.formatted(date: .abbreviated, time: .omitted)) | ||
| 246 | .font(appDensity.font(.caption2)) | ||
| 247 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 248 | Text(event.summary) | ||
| 249 | .font(appDensity.font(.caption)) | ||
| 250 | Text(event.source) | ||
| 251 | .font(appDensity.font(.caption2)) | ||
| 252 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 253 | } | ||
| 254 | } | ||
| 255 | } else if let historyError { | ||
| 256 | MessageRowView(text: historyError, isError: false) | ||
| 257 | } | ||
| 258 | } | ||
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | struct IntelligenceSectionView: View { | ||
| 263 | @Environment(\.appDensity) private var appDensity | ||
| 264 | @Binding var isCollapsed: Bool | ||
| 265 | let report: DomainReport | ||
| 266 | let showsPlaceholder: Bool | ||
| 267 | |||
| 268 | var body: some View { | ||
| 269 | CollapsibleSectionView(title: "Data+ Intelligence", isCollapsed: $isCollapsed) { | ||
| 270 | CardView(allowsHorizontalScroll: false) { | ||
| 271 | if showsPlaceholder { | ||
| 272 | MessageRowView(text: "Richer intelligence history, hosting analysis, and risk signals are available in Pro+", isError: false) | ||
| 273 | } else { | ||
| 274 | if let provider = report.inferredProvider { | ||
| 275 | intelligenceBlock(title: "Infrastructure") { | ||
| 276 | LabeledValueRow(row: .init(label: "Provider", value: provider.name, tone: .primary)) | ||
| 277 | if !provider.evidence.isEmpty { | ||
| 278 | MessageRowView(text: provider.evidence.joined(separator: " • "), isError: false) | ||
| 279 | } | ||
| 280 | if !report.priorProviders.isEmpty { | ||
| 281 | LabeledValueRow(row: .init(label: "Prior", value: report.priorProviders.joined(separator: ", "), tone: .secondary)) | ||
| 282 | } | ||
| 283 | } | ||
| 284 | } | ||
| 285 | if let classification = report.domainClassification { | ||
| 286 | intelligenceBlock(title: "Classification") { | ||
| 287 | LabeledValueRow(row: .init(label: "Purpose", value: classification.kind.title, tone: .primary)) | ||
| 288 | MessageRowView(text: classification.reasons.joined(separator: " • "), isError: false) | ||
| 289 | } | ||
| 290 | } | ||
| 291 | intelligenceBlock(title: "Risk Signals") { | ||
| 292 | if report.riskSignals.isEmpty { | ||
| 293 | MessageRowView(text: "No material historical risk signals detected", isError: false) | ||
| 294 | } else { | ||
| 295 | ForEach(report.riskSignals.prefix(4)) { signal in | ||
| 296 | VStack(alignment: .leading, spacing: 3) { | ||
| 297 | Text(signal.title) | ||
| 298 | .font(appDensity.font(.caption, weight: .semibold)) | ||
| 299 | Text(signal.detail) | ||
| 300 | .font(appDensity.font(.caption2)) | ||
| 301 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 302 | } | ||
| 303 | } | ||
| 304 | } | ||
| 305 | } | ||
| 306 | intelligenceBlock(title: "Ownership History") { | ||
| 307 | if report.ownershipTransitions.isEmpty { | ||
| 308 | MessageRowView(text: "No ownership transitions observed locally", isError: false) | ||
| 309 | } else { | ||
| 310 | ForEach(report.ownershipTransitions.prefix(4)) { event in | ||
| 311 | intelligenceEventRow(date: event.date, title: event.summary) | ||
| 312 | } | ||
| 313 | } | ||
| 314 | } | ||
| 315 | intelligenceBlock(title: "Hosting History") { | ||
| 316 | if report.hostingTransitions.isEmpty { | ||
| 317 | MessageRowView(text: "No hosting transitions observed locally", isError: false) | ||
| 318 | } else { | ||
| 319 | ForEach(report.hostingTransitions.prefix(4)) { event in | ||
| 320 | intelligenceEventRow(date: event.date, title: event.summary) | ||
| 321 | } | ||
| 322 | } | ||
| 323 | } | ||
| 324 | intelligenceBlock(title: "Subdomain Intelligence") { | ||
| 325 | if report.subdomainHistory.isEmpty { | ||
| 326 | MessageRowView(text: "No subdomain history available", isError: false) | ||
| 327 | } else { | ||
| 328 | ForEach(report.subdomainHistory.prefix(5)) { item in | ||
| 329 | VStack(alignment: .leading, spacing: 3) { | ||
| 330 | HStack { | ||
| 331 | Text(item.hostname) | ||
| 332 | .font(appDensity.font(.caption)) | ||
| 333 | Spacer() | ||
| 334 | if item.isEphemeral { | ||
| 335 | Text("Ephemeral") | ||
| 336 | .font(appDensity.font(.caption2)) | ||
| 337 | .foregroundStyle(Color(.statusWarning)) | ||
| 338 | } | ||
| 339 | } | ||
| 340 | Text("First \(item.firstSeen.formatted(date: .abbreviated, time: .omitted)) • Last \(item.lastSeen.formatted(date: .abbreviated, time: .omitted)) • Seen \(item.recurrenceCount)x") | ||
| 341 | .font(appDensity.font(.caption2)) | ||
| 342 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 343 | } | ||
| 344 | } | ||
| 345 | } | ||
| 346 | } | ||
| 347 | intelligenceBlock(title: "Timeline") { | ||
| 348 | if report.intelligenceTimeline.isEmpty { | ||
| 349 | MessageRowView(text: "No inferred intelligence events yet", isError: false) | ||
| 350 | } else { | ||
| 351 | ForEach(report.intelligenceTimeline.prefix(5)) { event in | ||
| 352 | intelligenceEventRow(date: event.date, title: "\(event.title): \(event.detail)") | ||
| 353 | } | ||
| 354 | } | ||
| 355 | } | ||
| 356 | } | ||
| 357 | } | ||
| 358 | } | ||
| 359 | } | ||
| 360 | |||
| 361 | @ViewBuilder | ||
| 362 | private func intelligenceBlock<Content: View>(title: String, @ViewBuilder content: () -> Content) -> some View { | ||
| 363 | VStack(alignment: .leading, spacing: 8) { | ||
| 364 | Text(title) | ||
| 365 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 366 | .foregroundStyle(Color(.statusInfo)) | ||
| 367 | content() | ||
| 368 | } | ||
| 369 | } | ||
| 370 | |||
| 371 | private func intelligenceEventRow(date: Date, title: String) -> some View { | ||
| 372 | VStack(alignment: .leading, spacing: 3) { | ||
| 373 | Text(date.formatted(date: .abbreviated, time: .omitted)) | ||
| 374 | .font(appDensity.font(.caption2)) | ||
| 375 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 376 | Text(title) | ||
| 377 | .font(appDensity.font(.caption)) | ||
| 378 | } | ||
| 379 | } | ||
| 380 | } | ||
| 381 | |||
| 382 | struct SubdomainsSectionView: View { | ||
| 383 | @Environment(\.appDensity) private var appDensity | ||
| 384 | @Binding var isCollapsed: Bool | ||
| 385 | let rows: [SubdomainRowViewData] | ||
| 386 | let groups: [SubdomainGroup] | ||
| 387 | let loading: Bool | ||
| 388 | let error: String? | ||
| 389 | let provenance: SectionProvenance? | ||
| 390 | let confidence: ConfidenceLevel? | ||
| 391 | let showsExtendedPlaceholder: Bool | ||
| 392 | let extendedCount: Int | ||
| 393 | let extendedLoading: Bool | ||
| 394 | let extendedError: String? | ||
| 395 | let onLoadExtended: (() -> Void)? | ||
| 396 | |||
| 397 | init( | ||
| 398 | isCollapsed: Binding<Bool>, | ||
| 399 | rows: [SubdomainRowViewData], | ||
| 400 | groups: [SubdomainGroup], | ||
| 401 | loading: Bool, | ||
| 402 | error: String?, | ||
| 403 | provenance: SectionProvenance?, | ||
| 404 | confidence: ConfidenceLevel?, | ||
| 405 | showsExtendedPlaceholder: Bool, | ||
| 406 | extendedCount: Int = 0, | ||
| 407 | extendedLoading: Bool = false, | ||
| 408 | extendedError: String? = nil, | ||
| 409 | onLoadExtended: (() -> Void)? = nil | ||
| 410 | ) { | ||
| 411 | _isCollapsed = isCollapsed | ||
| 412 | self.rows = rows | ||
| 413 | self.groups = groups | ||
| 414 | self.loading = loading | ||
| 415 | self.error = error | ||
| 416 | self.provenance = provenance | ||
| 417 | self.confidence = confidence | ||
| 418 | self.showsExtendedPlaceholder = showsExtendedPlaceholder | ||
| 419 | self.extendedCount = extendedCount | ||
| 420 | self.extendedLoading = extendedLoading | ||
| 421 | self.extendedError = extendedError | ||
| 422 | self.onLoadExtended = onLoadExtended | ||
| 423 | } | ||
| 424 | |||
| 425 | var body: some View { | ||
| 426 | CollapsibleSectionView(title: "Subdomains", isCollapsed: $isCollapsed, subtitle: "\(rows.count) found") { | ||
| 427 | CardView(allowsHorizontalScroll: false) { | ||
| 428 | SectionTrustMetadataView(provenance: provenance, confidence: confidence) | ||
| 429 | if loading { | ||
| 430 | ProgressView("Checking certificate transparency…") | ||
| 431 | .appLoadingStyle() | ||
| 432 | } else if rows.isEmpty { | ||
| 433 | MessageRowView(text: error ?? "No passive subdomains found", isError: false) | ||
| 434 | if showsExtendedPlaceholder { | ||
| 435 | MessageRowView(text: "Extended subdomain discovery available in Pro+", isError: false) | ||
| 436 | .padding(.top, 4) | ||
| 437 | } | ||
| 438 | } else { | ||
| 439 | if let onLoadExtended, extendedCount == 0, !extendedLoading, !showsExtendedPlaceholder { | ||
| 440 | Button("Load extended results") { | ||
| 441 | onLoadExtended() | ||
| 442 | } | ||
| 443 | .buttonStyle(.bordered) | ||
| 444 | .font(appDensity.font(.caption2)) | ||
| 445 | } | ||
| 446 | groupList | ||
| 447 | subdomainRows | ||
| 448 | extendedStatus | ||
| 449 | } | ||
| 450 | } | ||
| 451 | } | ||
| 452 | } | ||
| 453 | |||
| 454 | @ViewBuilder | ||
| 455 | private var extendedStatus: some View { | ||
| 456 | if extendedLoading { | ||
| 457 | ProgressView("Loading extended subdomains…") | ||
| 458 | .appLoadingStyle() | ||
| 459 | .padding(.top, 4) | ||
| 460 | } else if extendedCount > 0 { | ||
| 461 | MessageRowView(text: "\(extendedCount) extended results included", isError: false) | ||
| 462 | .padding(.top, 4) | ||
| 463 | } else if let extendedError { | ||
| 464 | MessageRowView(text: extendedError, isError: false) | ||
| 465 | .padding(.top, 4) | ||
| 466 | } else if showsExtendedPlaceholder { | ||
| 467 | MessageRowView(text: "Extended subdomain discovery available in Pro+", isError: false) | ||
| 468 | .padding(.top, 4) | ||
| 469 | } | ||
| 470 | } | ||
| 471 | |||
| 472 | @ViewBuilder | ||
| 473 | private var groupList: some View { | ||
| 474 | if !groups.isEmpty { | ||
| 475 | Text("Groups") | ||
| 476 | .font(appDensity.font(.caption2)) | ||
| 477 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 478 | ForEach(groups) { group in | ||
| 479 | HStack { | ||
| 480 | Text("\(group.label).*") | ||
| 481 | .font(appDensity.font(.caption)) | ||
| 482 | .foregroundStyle(Color(.statusInfo)) | ||
| 483 | Spacer() | ||
| 484 | Text("\(group.subdomains.count)") | ||
| 485 | .font(appDensity.font(.caption2)) | ||
| 486 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 487 | } | ||
| 488 | } | ||
| 489 | } | ||
| 490 | } | ||
| 491 | |||
| 492 | @ViewBuilder | ||
| 493 | private var subdomainRows: some View { | ||
| 494 | ForEach(rows) { row in | ||
| 495 | HStack(spacing: 8) { | ||
| 496 | Text(row.hostname) | ||
| 497 | .font(appDensity.font(.caption)) | ||
| 498 | .foregroundStyle(.primary) | ||
| 499 | .textSelection(.enabled) | ||
| 500 | Spacer() | ||
| 501 | if row.isInteresting { | ||
| 502 | Text("Interesting") | ||
| 503 | .font(.system(.caption2, design: .monospaced)) | ||
| 504 | .foregroundStyle(Color(.statusWarning)) | ||
| 505 | .padding(.horizontal, 8) | ||
| 506 | .padding(.vertical, 4) | ||
| 507 | .background(Color(.statusWarningSurface)) | ||
| 508 | .clipShape(Capsule()) | ||
| 509 | } | ||
| 510 | } | ||
| 511 | } | ||
| 512 | } | ||
| 513 | } | ||
| 514 | |||
| 515 | struct DNSSectionView: View { | ||
| 516 | @Environment(\.appDensity) private var appDensity | ||
| 517 | @Binding var isCollapsed: Bool | ||
| 518 | let dnssecLabel: String? | ||
| 519 | let patternSummary: DNSPatternSummary? | ||
| 520 | let sections: [DNSRecordSectionViewData] | ||
| 521 | let ptrMessage: SectionMessageViewData? | ||
| 522 | let loading: Bool | ||
| 523 | let dnsProvenance: SectionProvenance? | ||
| 524 | let ptrProvenance: SectionProvenance? | ||
| 525 | let sectionError: String? | ||
| 526 | let history: [DNSHistoryEvent] | ||
| 527 | let historyLoading: Bool | ||
| 528 | let historyError: String? | ||
| 529 | let onLoadHistory: (() -> Void)? | ||
| 530 | |||
| 531 | init( | ||
| 532 | isCollapsed: Binding<Bool>, | ||
| 533 | dnssecLabel: String?, | ||
| 534 | patternSummary: DNSPatternSummary?, | ||
| 535 | sections: [DNSRecordSectionViewData], | ||
| 536 | ptrMessage: SectionMessageViewData?, | ||
| 537 | loading: Bool, | ||
| 538 | dnsProvenance: SectionProvenance?, | ||
| 539 | ptrProvenance: SectionProvenance?, | ||
| 540 | sectionError: String?, | ||
| 541 | history: [DNSHistoryEvent] = [], | ||
| 542 | historyLoading: Bool = false, | ||
| 543 | historyError: String? = nil, | ||
| 544 | onLoadHistory: (() -> Void)? = nil | ||
| 545 | ) { | ||
| 546 | _isCollapsed = isCollapsed | ||
| 547 | self.dnssecLabel = dnssecLabel | ||
| 548 | self.patternSummary = patternSummary | ||
| 549 | self.sections = sections | ||
| 550 | self.ptrMessage = ptrMessage | ||
| 551 | self.loading = loading | ||
| 552 | self.dnsProvenance = dnsProvenance | ||
| 553 | self.ptrProvenance = ptrProvenance | ||
| 554 | self.sectionError = sectionError | ||
| 555 | self.history = history | ||
| 556 | self.historyLoading = historyLoading | ||
| 557 | self.historyError = historyError | ||
| 558 | self.onLoadHistory = onLoadHistory | ||
| 559 | } | ||
| 560 | |||
| 561 | var body: some View { | ||
| 562 | CollapsibleSectionView(title: "DNS", isCollapsed: $isCollapsed, subtitle: dnssecLabel) { | ||
| 563 | if loading { | ||
| 564 | LoadingCardView(text: "Querying DNS…") | ||
| 565 | } else if let sectionError, sections.isEmpty { | ||
| 566 | MessageCardView(text: sectionError, isError: true) | ||
| 567 | } else { | ||
| 568 | provenanceCard | ||
| 569 | ForEach(sections) { section in | ||
| 570 | CardView { | ||
| 571 | Text(section.title) | ||
| 572 | .font(.system(.subheadline, design: .monospaced)) | ||
| 573 | .fontWeight(.semibold) | ||
| 574 | .foregroundStyle(Color(.statusInfo)) | ||
| 575 | |||
| 576 | if let message = section.message { | ||
| 577 | MessageRowView(text: message.text, isError: message.isError) | ||
| 578 | } | ||
| 579 | |||
| 580 | ForEach(section.rows) { row in | ||
| 581 | LabeledValueRow(row: row) | ||
| 582 | } | ||
| 583 | |||
| 584 | if let wildcardTitle = section.wildcardTitle { | ||
| 585 | Text(wildcardTitle) | ||
| 586 | .font(.system(.caption, design: .monospaced)) | ||
| 587 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 588 | .padding(.top, 4) | ||
| 589 | ForEach(section.wildcardRows) { row in | ||
| 590 | LabeledValueRow(row: row) | ||
| 591 | } | ||
| 592 | } | ||
| 593 | } | ||
| 594 | } | ||
| 595 | |||
| 596 | if let ptrMessage { | ||
| 597 | CardView { | ||
| 598 | Text("PTR") | ||
| 599 | .font(.system(.subheadline, design: .monospaced)) | ||
| 600 | .fontWeight(.semibold) | ||
| 601 | .foregroundStyle(Color(.statusInfo)) | ||
| 602 | SectionTrustMetadataView(provenance: ptrProvenance, confidence: nil) | ||
| 603 | MessageRowView(text: ptrMessage.text, isError: ptrMessage.isError) | ||
| 604 | } | ||
| 605 | } | ||
| 606 | |||
| 607 | CardView(allowsHorizontalScroll: false) { | ||
| 608 | HStack { | ||
| 609 | Text("History") | ||
| 610 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 611 | .foregroundStyle(Color(.statusInfo)) | ||
| 612 | Spacer() | ||
| 613 | if let onLoadHistory, history.isEmpty, !historyLoading { | ||
| 614 | Button("Load") { | ||
| 615 | onLoadHistory() | ||
| 616 | } | ||
| 617 | .buttonStyle(.bordered) | ||
| 618 | .font(appDensity.font(.caption2)) | ||
| 619 | } | ||
| 620 | } | ||
| 621 | historyContent | ||
| 622 | } | ||
| 623 | } | ||
| 624 | } | ||
| 625 | } | ||
| 626 | |||
| 627 | @ViewBuilder | ||
| 628 | private var historyContent: some View { | ||
| 629 | if historyLoading { | ||
| 630 | ProgressView("Loading DNS history…") | ||
| 631 | .appLoadingStyle() | ||
| 632 | } else if !history.isEmpty { | ||
| 633 | ForEach(history) { event in | ||
| 634 | VStack(alignment: .leading, spacing: 3) { | ||
| 635 | Text(event.date.formatted(date: .abbreviated, time: .omitted)) | ||
| 636 | .font(appDensity.font(.caption2)) | ||
| 637 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 638 | Text(event.summary) | ||
| 639 | .font(appDensity.font(.caption)) | ||
| 640 | if !event.aRecords.isEmpty { | ||
| 641 | Text("A: \(event.aRecords.joined(separator: ", "))") | ||
| 642 | .font(appDensity.font(.caption2)) | ||
| 643 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 644 | } | ||
| 645 | if !event.nameservers.isEmpty { | ||
| 646 | Text("NS: \(event.nameservers.joined(separator: ", "))") | ||
| 647 | .font(appDensity.font(.caption2)) | ||
| 648 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 649 | } | ||
| 650 | } | ||
| 651 | } | ||
| 652 | } else if let historyError { | ||
| 653 | MessageRowView(text: historyError, isError: false) | ||
| 654 | } | ||
| 655 | } | ||
| 656 | |||
| 657 | @ViewBuilder | ||
| 658 | private var provenanceCard: some View { | ||
| 659 | if dnsProvenance != nil { | ||
| 660 | CardView(allowsHorizontalScroll: false) { | ||
| 661 | SectionTrustMetadataView(provenance: dnsProvenance, confidence: nil) | ||
| 662 | if let patternSummary { | ||
| 663 | if !patternSummary.providers.isEmpty { | ||
| 664 | MessageRowView(text: "Providers: \(patternSummary.providers.joined(separator: ", "))", isError: false) | ||
| 665 | } | ||
| 666 | if !patternSummary.patterns.isEmpty { | ||
| 667 | ForEach(Array(patternSummary.patterns.enumerated()), id: \.offset) { _, pattern in | ||
| 668 | MessageRowView(text: pattern, isError: false) | ||
| 669 | } | ||
| 670 | } | ||
| 671 | } | ||
| 672 | } | ||
| 673 | } | ||
| 674 | } | ||
| 675 | } | ||
| 676 | |||
| 677 | struct WebSectionView: View { | ||
| 678 | @Environment(\.appDensity) private var appDensity | ||
| 679 | @Binding var isCollapsed: Bool | ||
| 680 | |||
| 681 | private let certificateRows: [InfoRowViewData] | ||
| 682 | private let sslInfo: SSLCertificateInfo? | ||
| 683 | private let tlsSummary: WebResultSummary? | ||
| 684 | private let sslLoading: Bool | ||
| 685 | private let sslError: String? | ||
| 686 | private let tlsProvenance: SectionProvenance? | ||
| 687 | private let responseRows: [InfoRowViewData] | ||
| 688 | private let headers: [HTTPHeader] | ||
| 689 | private let headersLoading: Bool | ||
| 690 | private let headersError: String? | ||
| 691 | private let httpProvenance: SectionProvenance? | ||
| 692 | private let redirects: [RedirectHopViewData] | ||
| 693 | private let redirectLoading: Bool | ||
| 694 | private let redirectError: String? | ||
| 695 | private let redirectProvenance: SectionProvenance? | ||
| 696 | private let finalURL: String? | ||
| 697 | |||
| 698 | init(isCollapsed: Binding<Bool>, data: WebSectionViewData) { | ||
| 699 | _isCollapsed = isCollapsed | ||
| 700 | certificateRows = data.certificateRows | ||
| 701 | sslInfo = data.sslInfo | ||
| 702 | tlsSummary = data.tlsSummary | ||
| 703 | sslLoading = data.tls.isLoading | ||
| 704 | sslError = data.tls.error | ||
| 705 | tlsProvenance = data.tls.provenance | ||
| 706 | responseRows = data.responseRows | ||
| 707 | headers = data.headers | ||
| 708 | headersLoading = data.http.isLoading | ||
| 709 | headersError = data.http.error | ||
| 710 | httpProvenance = data.http.provenance | ||
| 711 | redirects = data.redirectRows | ||
| 712 | redirectLoading = data.redirect.isLoading | ||
| 713 | redirectError = data.redirect.error | ||
| 714 | redirectProvenance = data.redirect.provenance | ||
| 715 | finalURL = data.finalURL | ||
| 716 | } | ||
| 717 | |||
| 718 | var body: some View { | ||
| 719 | CollapsibleSectionView(title: "Web", isCollapsed: $isCollapsed) { | ||
| 720 | CardView { | ||
| 721 | HStack { | ||
| 722 | Text("TLS") | ||
| 723 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 724 | .foregroundStyle(Color(.statusInfo)) | ||
| 725 | Spacer() | ||
| 726 | if !sslLoading { | ||
| 727 | AppStatusBadgeView(model: AppStatusFactory.tls(sslInfo: sslInfo, error: sslError)) | ||
| 728 | } | ||
| 729 | } | ||
| 730 | SectionTrustMetadataView(provenance: tlsProvenance, confidence: nil) | ||
| 731 | if !sslLoading, let tlsSummary { | ||
| 732 | LabeledValueRow(row: InfoRowViewData(label: "TLS Grade", value: tlsSummary.tlsGrade.rawValue, tone: tlsSummary.tlsGrade.tone)) | ||
| 733 | ForEach(Array(tlsSummary.tlsHighlights.enumerated()), id: \.offset) { _, highlight in | ||
| 734 | MessageRowView(text: highlight, isError: isTLSHighlightError(highlight)) | ||
| 735 | } | ||
| 736 | } | ||
| 737 | if sslLoading { | ||
| 738 | ProgressView("Checking certificate…") | ||
| 739 | .appLoadingStyle() | ||
| 740 | } else if let sslError { | ||
| 741 | MessageRowView(text: sslError, isError: true) | ||
| 742 | } else { | ||
| 743 | ForEach(certificateRows) { row in | ||
| 744 | LabeledValueRow(row: row) | ||
| 745 | } | ||
| 746 | if let sslInfo, !sslInfo.subjectAltNames.isEmpty { | ||
| 747 | Text("SANs") | ||
| 748 | .font(appDensity.font(.caption2)) | ||
| 749 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 750 | ForEach(sslInfo.subjectAltNames, id: \.self) { san in | ||
| 751 | HStack(alignment: .top, spacing: 8) { | ||
| 752 | Text(san) | ||
| 753 | .font(appDensity.font(.caption)) | ||
| 754 | .lineLimit(nil) | ||
| 755 | .fixedSize(horizontal: false, vertical: true) | ||
| 756 | .textSelection(.enabled) | ||
| 757 | Spacer() | ||
| 758 | AppCopyButton(value: san, label: "Copy certificate SAN") | ||
| 759 | } | ||
| 760 | } | ||
| 761 | } | ||
| 762 | } | ||
| 763 | } | ||
| 764 | |||
| 765 | CardView { | ||
| 766 | Text("Headers") | ||
| 767 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 768 | .foregroundStyle(Color(.statusInfo)) | ||
| 769 | SectionTrustMetadataView(provenance: httpProvenance, confidence: nil) | ||
| 770 | if headersLoading { | ||
| 771 | ProgressView("Fetching headers…") | ||
| 772 | .appLoadingStyle() | ||
| 773 | } else if let headersError { | ||
| 774 | MessageRowView(text: headersError, isError: true) | ||
| 775 | } else { | ||
| 776 | ForEach(responseRows) { row in | ||
| 777 | LabeledValueRow(row: row) | ||
| 778 | } | ||
| 779 | if headers.isEmpty { | ||
| 780 | MessageRowView(text: "No HTTP headers returned", isError: false) | ||
| 781 | } else { | ||
| 782 | ForEach(headers) { header in | ||
| 783 | HStack(alignment: .top, spacing: 4) { | ||
| 784 | Text(header.name + ":") | ||
| 785 | .font(appDensity.font(.caption)) | ||
| 786 | .foregroundStyle(header.isSecurityHeader ? Color(.statusWarning) : Color(.statusInfo)) | ||
| 787 | Text(header.value) | ||
| 788 | .font(appDensity.font(.caption)) | ||
| 789 | .foregroundStyle(.primary) | ||
| 790 | .textSelection(.enabled) | ||
| 791 | } | ||
| 792 | } | ||
| 793 | } | ||
| 794 | } | ||
| 795 | } | ||
| 796 | |||
| 797 | CardView { | ||
| 798 | HStack { | ||
| 799 | Text("Redirects") | ||
| 800 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 801 | .foregroundStyle(Color(.statusInfo)) | ||
| 802 | Spacer() | ||
| 803 | if let finalURL { | ||
| 804 | AppCopyButton(value: finalURL, label: "Copy redirect URL") | ||
| 805 | } | ||
| 806 | } | ||
| 807 | SectionTrustMetadataView(provenance: redirectProvenance, confidence: nil) | ||
| 808 | if redirectLoading { | ||
| 809 | ProgressView("Tracing redirects…") | ||
| 810 | .appLoadingStyle() | ||
| 811 | } else if let redirectError { | ||
| 812 | MessageRowView(text: redirectError, isError: true) | ||
| 813 | } else if redirects.isEmpty { | ||
| 814 | MessageRowView(text: "No redirect data available", isError: false) | ||
| 815 | } else { | ||
| 816 | if let finalURL { | ||
| 817 | LabeledValueRow(row: InfoRowViewData(label: "Final URL", value: finalURL, tone: .secondary)) | ||
| 818 | } | ||
| 819 | ForEach(redirects) { redirect in | ||
| 820 | HStack(alignment: .top, spacing: 6) { | ||
| 821 | Text(redirect.stepLabel) | ||
| 822 | .font(appDensity.font(.caption)) | ||
| 823 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 824 | .frame(width: 16, alignment: .trailing) | ||
| 825 | Text(redirect.statusCode) | ||
| 826 | .font(appDensity.font(.caption)) | ||
| 827 | .foregroundStyle(Color(.statusInfo)) | ||
| 828 | .frame(width: 36, alignment: .leading) | ||
| 829 | Text(redirect.url) | ||
| 830 | .font(appDensity.font(.caption)) | ||
| 831 | .textSelection(.enabled) | ||
| 832 | if redirect.isFinal { | ||
| 833 | Text("(final)") | ||
| 834 | .font(appDensity.font(.caption2)) | ||
| 835 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 836 | } | ||
| 837 | Spacer(minLength: 8) | ||
| 838 | AppCopyButton(value: redirect.url, label: "Copy redirect URL") | ||
| 839 | } | ||
| 840 | } | ||
| 841 | } | ||
| 842 | } | ||
| 843 | } | ||
| 844 | } | ||
| 845 | |||
| 846 | private func isTLSHighlightError(_ highlight: String) -> Bool { | ||
| 847 | let normalized = highlight.lowercased() | ||
| 848 | if normalized.contains("no weak tls indicators were detected") { | ||
| 849 | return false | ||
| 850 | } | ||
| 851 | return normalized.contains("expires") | ||
| 852 | || normalized.contains("weak") | ||
| 853 | || normalized.contains("tls 1.0") | ||
| 854 | || normalized.contains("tls 1.1") | ||
| 855 | } | ||
| 856 | } | ||
| 857 | |||
| 858 | struct EmailSectionView: View { | ||
| 859 | @Environment(\.appDensity) private var appDensity | ||
| 860 | @Binding var isCollapsed: Bool | ||
| 861 | let rows: [EmailRowViewData] | ||
| 862 | let assessment: EmailSecuritySummary? | ||
| 863 | let loading: Bool | ||
| 864 | let provenance: SectionProvenance? | ||
| 865 | let confidence: ConfidenceLevel? | ||
| 866 | let error: String? | ||
| 867 | |||
| 868 | var body: some View { | ||
| 869 | CollapsibleSectionView(title: "Email", isCollapsed: $isCollapsed) { | ||
| 870 | CardView { | ||
| 871 | SectionTrustMetadataView(provenance: provenance, confidence: confidence) | ||
| 872 | HStack { | ||
| 873 | Spacer() | ||
| 874 | AppStatusBadgeView(model: AppStatusFactory.email(nil, error: error)) | ||
| 875 | .opacity(loading ? 0 : 1) | ||
| 876 | } | ||
| 877 | if let assessment, let grade = assessment.grade { | ||
| 878 | LabeledValueRow(row: InfoRowViewData(label: "Grade", value: grade.rawValue, tone: grade.tone)) | ||
| 879 | if !assessment.reasons.isEmpty { | ||
| 880 | Text(assessment.reasons.joined(separator: " | ")) | ||
| 881 | .font(appDensity.font(.caption2)) | ||
| 882 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 883 | } | ||
| 884 | } | ||
| 885 | if loading { | ||
| 886 | ProgressView("Checking email records…") | ||
| 887 | .appLoadingStyle() | ||
| 888 | } else if let error { | ||
| 889 | MessageRowView(text: error, isError: true) | ||
| 890 | } else if rows.isEmpty { | ||
| 891 | MessageRowView(text: "No email security records found", isError: false) | ||
| 892 | } else { | ||
| 893 | ForEach(rows) { row in | ||
| 894 | VStack(alignment: .leading, spacing: 4) { | ||
| 895 | HStack(spacing: 8) { | ||
| 896 | Text(row.label) | ||
| 897 | .font(appDensity.font(.caption)) | ||
| 898 | .foregroundStyle(Color(.statusInfo)) | ||
| 899 | .frame(width: 76, alignment: .leading) | ||
| 900 | AppStatusBadgeView(model: emailRowBadge(row)) | ||
| 901 | } | ||
| 902 | Text(row.detail) | ||
| 903 | .font(appDensity.font(.caption2)) | ||
| 904 | .foregroundStyle(.primary) | ||
| 905 | .textSelection(.enabled) | ||
| 906 | if let auxiliaryDetail = row.auxiliaryDetail { | ||
| 907 | Text(auxiliaryDetail) | ||
| 908 | .font(appDensity.font(.caption2)) | ||
| 909 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 910 | } | ||
| 911 | } | ||
| 912 | } | ||
| 913 | } | ||
| 914 | } | ||
| 915 | } | ||
| 916 | } | ||
| 917 | |||
| 918 | private func emailRowBadge(_ row: EmailRowViewData) -> AppStatusBadgeModel { | ||
| 919 | switch row.statusTone { | ||
| 920 | case .success: | ||
| 921 | return .init(title: row.status, systemImage: "checkmark.shield.fill", foregroundColor: Color(.statusPositive), backgroundColor: Color(.statusPositiveSurface)) | ||
| 922 | case .warning: | ||
| 923 | return .init(title: row.status, systemImage: "shield.lefthalf.filled", foregroundColor: Color(.statusWarning), backgroundColor: Color(.statusWarningSurface)) | ||
| 924 | case .failure: | ||
| 925 | return .init(title: row.status, systemImage: "minus.circle", foregroundColor: Color(.appTextSecondary), backgroundColor: Color(.appSurfaceElevated)) | ||
| 926 | case .primary, .secondary: | ||
| 927 | return .init(title: row.status, systemImage: "circle", foregroundColor: Color(.appTextSecondary), backgroundColor: Color(.appSurfaceElevated)) | ||
| 928 | } | ||
| 929 | } | ||
| 930 | } | ||
| 931 | |||
| 932 | struct NetworkSectionView: View { | ||
| 933 | @Environment(\.appDensity) private var appDensity | ||
| 934 | @Binding var isCollapsed: Bool | ||
| 935 | @Binding var customPortsExpanded: Bool | ||
| 936 | @Binding var customPortInput: String | ||
| 937 | let onScanCustomPorts: () -> Void | ||
| 938 | |||
| 939 | private let reachabilityRows: [ReachabilityRowViewData] | ||
| 940 | private let reachabilityLoading: Bool | ||
| 941 | private let reachabilityError: String? | ||
| 942 | private let reachabilityProvenance: SectionProvenance? | ||
| 943 | private let locationRows: [InfoRowViewData] | ||
| 944 | private let geolocation: IPGeolocation? | ||
| 945 | private let geolocationLoading: Bool | ||
| 946 | private let geolocationError: String? | ||
| 947 | private let geolocationProvenance: SectionProvenance? | ||
| 948 | private let geolocationConfidence: ConfidenceLevel? | ||
| 949 | private let standardPortRows: [PortScanRowViewData] | ||
| 950 | private let customPortRows: [PortScanRowViewData] | ||
| 951 | private let portScanLoading: Bool | ||
| 952 | private let portScanError: String? | ||
| 953 | private let portScanProvenance: SectionProvenance? | ||
| 954 | private let customPortScanLoading: Bool | ||
| 955 | private let customPortScanError: String? | ||
| 956 | private let isCloudflareProxied: Bool | ||
| 957 | |||
| 958 | init( | ||
| 959 | isCollapsed: Binding<Bool>, | ||
| 960 | customPortsExpanded: Binding<Bool>, | ||
| 961 | customPortInput: Binding<String>, | ||
| 962 | data: NetworkSectionViewData, | ||
| 963 | onScanCustomPorts: @escaping () -> Void | ||
| 964 | ) { | ||
| 965 | _isCollapsed = isCollapsed | ||
| 966 | _customPortsExpanded = customPortsExpanded | ||
| 967 | _customPortInput = customPortInput | ||
| 968 | self.onScanCustomPorts = onScanCustomPorts | ||
| 969 | reachabilityRows = data.reachabilityRows | ||
| 970 | reachabilityLoading = data.reachability.isLoading | ||
| 971 | reachabilityError = data.reachability.error | ||
| 972 | reachabilityProvenance = data.reachability.provenance | ||
| 973 | locationRows = data.locationRows | ||
| 974 | geolocation = data.geolocation | ||
| 975 | geolocationLoading = data.location.isLoading | ||
| 976 | geolocationError = data.location.error | ||
| 977 | geolocationProvenance = data.location.provenance | ||
| 978 | geolocationConfidence = data.location.confidence | ||
| 979 | standardPortRows = data.standardPortRows | ||
| 980 | customPortRows = data.customPortRows | ||
| 981 | portScanLoading = data.portScan.isLoading | ||
| 982 | portScanError = data.portScan.error | ||
| 983 | portScanProvenance = data.portScan.provenance | ||
| 984 | customPortScanLoading = data.customPortScan.isLoading | ||
| 985 | customPortScanError = data.customPortScan.error | ||
| 986 | isCloudflareProxied = data.isCloudflareProxied | ||
| 987 | } | ||
| 988 | |||
| 989 | var body: some View { | ||
| 990 | CollapsibleSectionView(title: "Network", isCollapsed: $isCollapsed) { | ||
| 991 | CardView { | ||
| 992 | Text("Reachability") | ||
| 993 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 994 | .foregroundStyle(Color(.statusInfo)) | ||
| 995 | SectionTrustMetadataView(provenance: reachabilityProvenance, confidence: nil) | ||
| 996 | if reachabilityLoading { | ||
| 997 | ProgressView("Checking ports…") | ||
| 998 | .appLoadingStyle() | ||
| 999 | } else if let reachabilityError { | ||
| 1000 | MessageRowView(text: reachabilityError, isError: true) | ||
| 1001 | } else { | ||
| 1002 | ForEach(reachabilityRows) { row in | ||
| 1003 | HStack { | ||
| 1004 | Text(row.portLabel) | ||
| 1005 | .font(appDensity.font(.caption)) | ||
| 1006 | Spacer() | ||
| 1007 | Text(row.latencyLabel) | ||
| 1008 | .font(appDensity.font(.caption2)) | ||
| 1009 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 1010 | AppStatusBadgeView(model: reachabilityBadge(row)) | ||
| 1011 | } | ||
| 1012 | } | ||
| 1013 | } | ||
| 1014 | } | ||
| 1015 | |||
| 1016 | CardView(allowsHorizontalScroll: false) { | ||
| 1017 | Text("Location") | ||
| 1018 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 1019 | .foregroundStyle(Color(.statusInfo)) | ||
| 1020 | SectionTrustMetadataView(provenance: geolocationProvenance, confidence: geolocationConfidence) | ||
| 1021 | if geolocationLoading { | ||
| 1022 | ProgressView("Looking up location…") | ||
| 1023 | .appLoadingStyle() | ||
| 1024 | } else if let geolocationError, geolocation == nil { | ||
| 1025 | MessageRowView(text: geolocationError, isError: geolocationError != "No A record available") | ||
| 1026 | } else if let geolocation { | ||
| 1027 | ForEach(locationRows) { row in | ||
| 1028 | LabeledValueRow(row: row) | ||
| 1029 | } | ||
| 1030 | if let latitude = geolocation.latitude, let longitude = geolocation.longitude { | ||
| 1031 | let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude) | ||
| 1032 | Map(initialPosition: .region(MKCoordinateRegion( | ||
| 1033 | center: coordinate, | ||
| 1034 | span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1) | ||
| 1035 | ))) { | ||
| 1036 | Marker(geolocation.ip, coordinate: coordinate) | ||
| 1037 | } | ||
| 1038 | .mapStyle(.standard) | ||
| 1039 | .frame(maxWidth: .infinity) | ||
| 1040 | .frame(height: 180) | ||
| 1041 | .cornerRadius(8) | ||
| 1042 | } | ||
| 1043 | } else { | ||
| 1044 | MessageRowView(text: "No location data available", isError: false) | ||
| 1045 | } | ||
| 1046 | } | ||
| 1047 | |||
| 1048 | CardView(allowsHorizontalScroll: false) { | ||
| 1049 | Text("Port Scan") | ||
| 1050 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 1051 | .foregroundStyle(Color(.statusInfo)) | ||
| 1052 | SectionTrustMetadataView(provenance: portScanProvenance, confidence: nil) | ||
| 1053 | |||
| 1054 | if isCloudflareProxied { | ||
| 1055 | Text("Domain is behind Cloudflare's proxy. Results reflect the edge, not the origin.") | ||
| 1056 | .font(appDensity.font(.caption2)) | ||
| 1057 | .foregroundStyle(Color(.statusWarning)) | ||
| 1058 | .fixedSize(horizontal: false, vertical: true) | ||
| 1059 | } | ||
| 1060 | |||
| 1061 | if portScanLoading { | ||
| 1062 | ProgressView("Scanning ports…") | ||
| 1063 | .appLoadingStyle() | ||
| 1064 | } else if let portScanError, standardPortRows.isEmpty { | ||
| 1065 | MessageRowView(text: portScanError, isError: true) | ||
| 1066 | } else { | ||
| 1067 | Text("Standard Ports") | ||
| 1068 | .font(.system(.caption, design: .monospaced)) | ||
| 1069 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 1070 | PortRowsView(rows: standardPortRows) | ||
| 1071 | } | ||
| 1072 | |||
| 1073 | DisclosureGroup("Custom Ports", isExpanded: $customPortsExpanded) { | ||
| 1074 | VStack(alignment: .leading, spacing: 10) { | ||
| 1075 | TextField("8888, 9000, 27017", text: $customPortInput) | ||
| 1076 | .font(appDensity.font(.caption)) | ||
| 1077 | .textInputAutocapitalization(.never) | ||
| 1078 | .autocorrectionDisabled() | ||
| 1079 | .keyboardType(.numberPad) | ||
| 1080 | .padding(10) | ||
| 1081 | .background(Color(.appSurface)) | ||
| 1082 | .clipShape(RoundedRectangle(cornerRadius: appDensity.metrics.cardCornerRadius)) | ||
| 1083 | |||
| 1084 | Button("Scan") { | ||
| 1085 | AppHaptics.refresh() | ||
| 1086 | onScanCustomPorts() | ||
| 1087 | } | ||
| 1088 | .buttonStyle(.borderedProminent) | ||
| 1089 | .tint(Color(.accentFill)) | ||
| 1090 | .disabled(customPortScanLoading) | ||
| 1091 | |||
| 1092 | if customPortScanLoading { | ||
| 1093 | ProgressView("Scanning custom ports…") | ||
| 1094 | .appLoadingStyle() | ||
| 1095 | } else if let customPortScanError { | ||
| 1096 | MessageRowView(text: customPortScanError, isError: true) | ||
| 1097 | } else { | ||
| 1098 | PortRowsView(rows: customPortRows) | ||
| 1099 | } | ||
| 1100 | } | ||
| 1101 | .padding(.top, 8) | ||
| 1102 | } | ||
| 1103 | .font(.system(.caption, design: .monospaced)) | ||
| 1104 | .tint(.secondary) | ||
| 1105 | } | ||
| 1106 | } | ||
| 1107 | } | ||
| 1108 | |||
| 1109 | private func reachabilityBadge(_ row: ReachabilityRowViewData) -> AppStatusBadgeModel { | ||
| 1110 | switch row.statusTone { | ||
| 1111 | case .success: | ||
| 1112 | return .init(title: row.statusLabel, systemImage: "checkmark.circle.fill", foregroundColor: Color(.statusPositive), backgroundColor: Color(.statusPositiveSurface)) | ||
| 1113 | case .warning: | ||
| 1114 | return .init(title: row.statusLabel, systemImage: "exclamationmark.triangle.fill", foregroundColor: Color(.statusWarning), backgroundColor: Color(.statusWarningSurface)) | ||
| 1115 | case .failure: | ||
| 1116 | return .init(title: row.statusLabel, systemImage: "xmark.circle.fill", foregroundColor: Color(.statusCritical), backgroundColor: Color(.statusCriticalSurface)) | ||
| 1117 | case .primary, .secondary: | ||
| 1118 | return .init(title: row.statusLabel, systemImage: "circle", foregroundColor: Color(.appTextSecondary), backgroundColor: Color(.appSurfaceElevated)) | ||
| 1119 | } | ||
| 1120 | } | ||
| 1121 | } | ||
| 1122 | |||
| 1123 | struct PortRowsView: View { | ||
| 1124 | @Environment(\.appDensity) private var appDensity | ||
| 1125 | let rows: [PortScanRowViewData] | ||
| 1126 | |||
| 1127 | var body: some View { | ||
| 1128 | if rows.isEmpty { | ||
| 1129 | MessageRowView(text: "No results", isError: false) | ||
| 1130 | } else { | ||
| 1131 | ForEach(rows) { row in | ||
| 1132 | VStack(alignment: .leading, spacing: appDensity.metrics.rowSpacing - 1) { | ||
| 1133 | HStack { | ||
| 1134 | Text(row.portLabel) | ||
| 1135 | .font(appDensity.font(.caption)) | ||
| 1136 | .frame(width: 52, alignment: .leading) | ||
| 1137 | Text(row.service) | ||
| 1138 | .font(appDensity.font(.caption)) | ||
| 1139 | .foregroundStyle(.primary) | ||
| 1140 | Spacer() | ||
| 1141 | if let durationLabel = row.durationLabel { | ||
| 1142 | Text(durationLabel) | ||
| 1143 | .font(appDensity.font(.caption2)) | ||
| 1144 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 1145 | } | ||
| 1146 | AppStatusBadgeView(model: portBadge(row)) | ||
| 1147 | } | ||
| 1148 | if let banner = row.banner { | ||
| 1149 | Text(banner) | ||
| 1150 | .font(appDensity.font(.caption2)) | ||
| 1151 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 1152 | .padding(.leading, 8) | ||
| 1153 | } | ||
| 1154 | } | ||
| 1155 | .frame(minHeight: appDensity.metrics.rowMinHeight, alignment: .topLeading) | ||
| 1156 | } | ||
| 1157 | } | ||
| 1158 | } | ||
| 1159 | |||
| 1160 | private func portBadge(_ row: PortScanRowViewData) -> AppStatusBadgeModel { | ||
| 1161 | switch row.statusTone { | ||
| 1162 | case .success: | ||
| 1163 | return .init(title: row.statusLabel, systemImage: "checkmark.circle.fill", foregroundColor: Color(.statusPositive), backgroundColor: Color(.statusPositiveSurface)) | ||
| 1164 | case .warning: | ||
| 1165 | return .init(title: row.statusLabel, systemImage: "exclamationmark.triangle.fill", foregroundColor: Color(.statusWarning), backgroundColor: Color(.statusWarningSurface)) | ||
| 1166 | case .failure: | ||
| 1167 | return .init(title: row.statusLabel, systemImage: "xmark.circle.fill", foregroundColor: Color(.statusCritical), backgroundColor: Color(.statusCriticalSurface)) | ||
| 1168 | case .primary, .secondary: | ||
| 1169 | return .init(title: row.statusLabel, systemImage: "circle", foregroundColor: Color(.appTextSecondary), backgroundColor: Color(.appSurfaceElevated)) | ||
| 1170 | } | ||
| 1171 | } | ||
| 1172 | } | ||
| 1173 | |||
| 1174 | // MARK: - Section view data | ||
| 1175 | |||
| 1176 | /// What one card inside a result section needs to know about its own state: | ||
| 1177 | /// whether the data is still arriving, what failed, where it came from and how | ||
| 1178 | /// much to trust it. | ||
| 1179 | /// | ||
| 1180 | /// These four travelled as a positional group repeated once per card, which is | ||
| 1181 | /// how `NetworkSectionView` came to declare 22 init parameters and | ||
| 1182 | /// `WebSectionView` 17 (A10). The views keep their own stored properties — | ||
| 1183 | /// unpacking happens in the init, so the bodies are unchanged — but a caller | ||
| 1184 | /// now names three groups instead of counting out twenty-two arguments. | ||
| 1185 | struct SectionPanelViewData { | ||
| 1186 | var isLoading = false | ||
| 1187 | var error: String? | ||
| 1188 | var provenance: SectionProvenance? | ||
| 1189 | var confidence: ConfidenceLevel? | ||
| 1190 | } | ||
| 1191 | |||
| 1192 | /// The Web section's three cards: TLS, headers, redirects. | ||
| 1193 | struct WebSectionViewData { | ||
| 1194 | var tls = SectionPanelViewData() | ||
| 1195 | var certificateRows: [InfoRowViewData] = [] | ||
| 1196 | var sslInfo: SSLCertificateInfo? | ||
| 1197 | var tlsSummary: WebResultSummary? | ||
| 1198 | |||
| 1199 | var http = SectionPanelViewData() | ||
| 1200 | var responseRows: [InfoRowViewData] = [] | ||
| 1201 | var headers: [HTTPHeader] = [] | ||
| 1202 | |||
| 1203 | var redirect = SectionPanelViewData() | ||
| 1204 | var redirectRows: [RedirectHopViewData] = [] | ||
| 1205 | var finalURL: String? | ||
| 1206 | } | ||
| 1207 | |||
| 1208 | /// The Network section's cards: reachability, location, ports. Custom port | ||
| 1209 | /// scanning carries its own state because it runs separately, after the user | ||
| 1210 | /// asks for it. | ||
| 1211 | struct NetworkSectionViewData { | ||
| 1212 | var reachability = SectionPanelViewData() | ||
| 1213 | var reachabilityRows: [ReachabilityRowViewData] = [] | ||
| 1214 | |||
| 1215 | var location = SectionPanelViewData() | ||
| 1216 | var locationRows: [InfoRowViewData] = [] | ||
| 1217 | var geolocation: IPGeolocation? | ||
| 1218 | |||
| 1219 | var portScan = SectionPanelViewData() | ||
| 1220 | var standardPortRows: [PortScanRowViewData] = [] | ||
| 1221 | var customPortRows: [PortScanRowViewData] = [] | ||
| 1222 | var customPortScan = SectionPanelViewData() | ||
| 1223 | |||
| 1224 | var isCloudflareProxied = false | ||
| 1225 | } | ||
DomainDig/SectionViewData.swift added +57
| @@ -0,0 +1,57 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | // What each result section needs in order to draw itself. Split out of | ||
| 4 | // ResultSectionViews.swift along with the views that consume them (A13). | ||
| 5 | |||
| 6 | // MARK: - Section view data | ||
| 7 | |||
| 8 | /// What one card inside a result section needs to know about its own state: | ||
| 9 | /// whether the data is still arriving, what failed, where it came from and how | ||
| 10 | /// much to trust it. | ||
| 11 | /// | ||
| 12 | /// These four travelled as a positional group repeated once per card, which is | ||
| 13 | /// how `NetworkSectionView` came to declare 22 init parameters and | ||
| 14 | /// `WebSectionView` 17 (A10). The views keep their own stored properties — | ||
| 15 | /// unpacking happens in the init, so the bodies are unchanged — but a caller | ||
| 16 | /// now names three groups instead of counting out twenty-two arguments. | ||
| 17 | struct SectionPanelViewData { | ||
| 18 | var isLoading = false | ||
| 19 | var error: String? | ||
| 20 | var provenance: SectionProvenance? | ||
| 21 | var confidence: ConfidenceLevel? | ||
| 22 | } | ||
| 23 | |||
| 24 | /// The Web section's three cards: TLS, headers, redirects. | ||
| 25 | struct WebSectionViewData { | ||
| 26 | var tls = SectionPanelViewData() | ||
| 27 | var certificateRows: [InfoRowViewData] = [] | ||
| 28 | var sslInfo: SSLCertificateInfo? | ||
| 29 | var tlsSummary: WebResultSummary? | ||
| 30 | |||
| 31 | var http = SectionPanelViewData() | ||
| 32 | var responseRows: [InfoRowViewData] = [] | ||
| 33 | var headers: [HTTPHeader] = [] | ||
| 34 | |||
| 35 | var redirect = SectionPanelViewData() | ||
| 36 | var redirectRows: [RedirectHopViewData] = [] | ||
| 37 | var finalURL: String? | ||
| 38 | } | ||
| 39 | |||
| 40 | /// The Network section's cards: reachability, location, ports. Custom port | ||
| 41 | /// scanning carries its own state because it runs separately, after the user | ||
| 42 | /// asks for it. | ||
| 43 | struct NetworkSectionViewData { | ||
| 44 | var reachability = SectionPanelViewData() | ||
| 45 | var reachabilityRows: [ReachabilityRowViewData] = [] | ||
| 46 | |||
| 47 | var location = SectionPanelViewData() | ||
| 48 | var locationRows: [InfoRowViewData] = [] | ||
| 49 | var geolocation: IPGeolocation? | ||
| 50 | |||
| 51 | var portScan = SectionPanelViewData() | ||
| 52 | var standardPortRows: [PortScanRowViewData] = [] | ||
| 53 | var customPortRows: [PortScanRowViewData] = [] | ||
| 54 | var customPortScan = SectionPanelViewData() | ||
| 55 | |||
| 56 | var isCloudflareProxied = false | ||
| 57 | } | ||
DomainDig/SubdomainsSectionView.swift added +139
| @@ -0,0 +1,139 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | // One inspection section: the discovered subdomains card. Pure presentation | ||
| 4 | // over the view model's report data; the shared primitives it builds on | ||
| 5 | // (CardView, SectionTitleView, LabeledValueRow, ResultColors, appLoadingStyle) | ||
| 6 | // live in ResultPrimitives.swift. | ||
| 7 | |||
| 8 | struct SubdomainsSectionView: View { | ||
| 9 | @Environment(\.appDensity) private var appDensity | ||
| 10 | @Binding var isCollapsed: Bool | ||
| 11 | let rows: [SubdomainRowViewData] | ||
| 12 | let groups: [SubdomainGroup] | ||
| 13 | let loading: Bool | ||
| 14 | let error: String? | ||
| 15 | let provenance: SectionProvenance? | ||
| 16 | let confidence: ConfidenceLevel? | ||
| 17 | let showsExtendedPlaceholder: Bool | ||
| 18 | let extendedCount: Int | ||
| 19 | let extendedLoading: Bool | ||
| 20 | let extendedError: String? | ||
| 21 | let onLoadExtended: (() -> Void)? | ||
| 22 | |||
| 23 | init( | ||
| 24 | isCollapsed: Binding<Bool>, | ||
| 25 | rows: [SubdomainRowViewData], | ||
| 26 | groups: [SubdomainGroup], | ||
| 27 | loading: Bool, | ||
| 28 | error: String?, | ||
| 29 | provenance: SectionProvenance?, | ||
| 30 | confidence: ConfidenceLevel?, | ||
| 31 | showsExtendedPlaceholder: Bool, | ||
| 32 | extendedCount: Int = 0, | ||
| 33 | extendedLoading: Bool = false, | ||
| 34 | extendedError: String? = nil, | ||
| 35 | onLoadExtended: (() -> Void)? = nil | ||
| 36 | ) { | ||
| 37 | _isCollapsed = isCollapsed | ||
| 38 | self.rows = rows | ||
| 39 | self.groups = groups | ||
| 40 | self.loading = loading | ||
| 41 | self.error = error | ||
| 42 | self.provenance = provenance | ||
| 43 | self.confidence = confidence | ||
| 44 | self.showsExtendedPlaceholder = showsExtendedPlaceholder | ||
| 45 | self.extendedCount = extendedCount | ||
| 46 | self.extendedLoading = extendedLoading | ||
| 47 | self.extendedError = extendedError | ||
| 48 | self.onLoadExtended = onLoadExtended | ||
| 49 | } | ||
| 50 | |||
| 51 | var body: some View { | ||
| 52 | CollapsibleSectionView(title: "Subdomains", isCollapsed: $isCollapsed, subtitle: "\(rows.count) found") { | ||
| 53 | CardView(allowsHorizontalScroll: false) { | ||
| 54 | SectionTrustMetadataView(provenance: provenance, confidence: confidence) | ||
| 55 | if loading { | ||
| 56 | ProgressView("Checking certificate transparency…") | ||
| 57 | .appLoadingStyle() | ||
| 58 | } else if rows.isEmpty { | ||
| 59 | MessageRowView(text: error ?? "No passive subdomains found", isError: false) | ||
| 60 | if showsExtendedPlaceholder { | ||
| 61 | MessageRowView(text: "Extended subdomain discovery available in Pro+", isError: false) | ||
| 62 | .padding(.top, 4) | ||
| 63 | } | ||
| 64 | } else { | ||
| 65 | if let onLoadExtended, extendedCount == 0, !extendedLoading, !showsExtendedPlaceholder { | ||
| 66 | Button("Load extended results") { | ||
| 67 | onLoadExtended() | ||
| 68 | } | ||
| 69 | .buttonStyle(.bordered) | ||
| 70 | .font(appDensity.font(.caption2)) | ||
| 71 | } | ||
| 72 | groupList | ||
| 73 | subdomainRows | ||
| 74 | extendedStatus | ||
| 75 | } | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | @ViewBuilder | ||
| 81 | private var extendedStatus: some View { | ||
| 82 | if extendedLoading { | ||
| 83 | ProgressView("Loading extended subdomains…") | ||
| 84 | .appLoadingStyle() | ||
| 85 | .padding(.top, 4) | ||
| 86 | } else if extendedCount > 0 { | ||
| 87 | MessageRowView(text: "\(extendedCount) extended results included", isError: false) | ||
| 88 | .padding(.top, 4) | ||
| 89 | } else if let extendedError { | ||
| 90 | MessageRowView(text: extendedError, isError: false) | ||
| 91 | .padding(.top, 4) | ||
| 92 | } else if showsExtendedPlaceholder { | ||
| 93 | MessageRowView(text: "Extended subdomain discovery available in Pro+", isError: false) | ||
| 94 | .padding(.top, 4) | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | @ViewBuilder | ||
| 99 | private var groupList: some View { | ||
| 100 | if !groups.isEmpty { | ||
| 101 | Text("Groups") | ||
| 102 | .font(appDensity.font(.caption2)) | ||
| 103 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 104 | ForEach(groups) { group in | ||
| 105 | HStack { | ||
| 106 | Text("\(group.label).*") | ||
| 107 | .font(appDensity.font(.caption)) | ||
| 108 | .foregroundStyle(Color(.statusInfo)) | ||
| 109 | Spacer() | ||
| 110 | Text("\(group.subdomains.count)") | ||
| 111 | .font(appDensity.font(.caption2)) | ||
| 112 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 113 | } | ||
| 114 | } | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | @ViewBuilder | ||
| 119 | private var subdomainRows: some View { | ||
| 120 | ForEach(rows) { row in | ||
| 121 | HStack(spacing: 8) { | ||
| 122 | Text(row.hostname) | ||
| 123 | .font(appDensity.font(.caption)) | ||
| 124 | .foregroundStyle(.primary) | ||
| 125 | .textSelection(.enabled) | ||
| 126 | Spacer() | ||
| 127 | if row.isInteresting { | ||
| 128 | Text("Interesting") | ||
| 129 | .font(.system(.caption2, design: .monospaced)) | ||
| 130 | .foregroundStyle(Color(.statusWarning)) | ||
| 131 | .padding(.horizontal, 8) | ||
| 132 | .padding(.vertical, 4) | ||
| 133 | .background(Color(.statusWarningSurface)) | ||
| 134 | .clipShape(Capsule()) | ||
| 135 | } | ||
| 136 | } | ||
| 137 | } | ||
| 138 | } | ||
| 139 | } | ||
DomainDig/WebSectionView.swift added +187
| @@ -0,0 +1,187 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | // One inspection section: the TLS, headers and redirects cards. Pure | ||
| 4 | // presentation over the view model's report data; the shared primitives it | ||
| 5 | // builds on (CardView, SectionTitleView, LabeledValueRow, ResultColors, | ||
| 6 | // appLoadingStyle) live in ResultPrimitives.swift. | ||
| 7 | |||
| 8 | struct WebSectionView: View { | ||
| 9 | @Environment(\.appDensity) private var appDensity | ||
| 10 | @Binding var isCollapsed: Bool | ||
| 11 | |||
| 12 | private let certificateRows: [InfoRowViewData] | ||
| 13 | private let sslInfo: SSLCertificateInfo? | ||
| 14 | private let tlsSummary: WebResultSummary? | ||
| 15 | private let sslLoading: Bool | ||
| 16 | private let sslError: String? | ||
| 17 | private let tlsProvenance: SectionProvenance? | ||
| 18 | private let responseRows: [InfoRowViewData] | ||
| 19 | private let headers: [HTTPHeader] | ||
| 20 | private let headersLoading: Bool | ||
| 21 | private let headersError: String? | ||
| 22 | private let httpProvenance: SectionProvenance? | ||
| 23 | private let redirects: [RedirectHopViewData] | ||
| 24 | private let redirectLoading: Bool | ||
| 25 | private let redirectError: String? | ||
| 26 | private let redirectProvenance: SectionProvenance? | ||
| 27 | private let finalURL: String? | ||
| 28 | |||
| 29 | init(isCollapsed: Binding<Bool>, data: WebSectionViewData) { | ||
| 30 | _isCollapsed = isCollapsed | ||
| 31 | certificateRows = data.certificateRows | ||
| 32 | sslInfo = data.sslInfo | ||
| 33 | tlsSummary = data.tlsSummary | ||
| 34 | sslLoading = data.tls.isLoading | ||
| 35 | sslError = data.tls.error | ||
| 36 | tlsProvenance = data.tls.provenance | ||
| 37 | responseRows = data.responseRows | ||
| 38 | headers = data.headers | ||
| 39 | headersLoading = data.http.isLoading | ||
| 40 | headersError = data.http.error | ||
| 41 | httpProvenance = data.http.provenance | ||
| 42 | redirects = data.redirectRows | ||
| 43 | redirectLoading = data.redirect.isLoading | ||
| 44 | redirectError = data.redirect.error | ||
| 45 | redirectProvenance = data.redirect.provenance | ||
| 46 | finalURL = data.finalURL | ||
| 47 | } | ||
| 48 | |||
| 49 | var body: some View { | ||
| 50 | CollapsibleSectionView(title: "Web", isCollapsed: $isCollapsed) { | ||
| 51 | CardView { | ||
| 52 | HStack { | ||
| 53 | Text("TLS") | ||
| 54 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 55 | .foregroundStyle(Color(.statusInfo)) | ||
| 56 | Spacer() | ||
| 57 | if !sslLoading { | ||
| 58 | AppStatusBadgeView(model: AppStatusFactory.tls(sslInfo: sslInfo, error: sslError)) | ||
| 59 | } | ||
| 60 | } | ||
| 61 | SectionTrustMetadataView(provenance: tlsProvenance, confidence: nil) | ||
| 62 | if !sslLoading, let tlsSummary { | ||
| 63 | LabeledValueRow(row: InfoRowViewData(label: "TLS Grade", value: tlsSummary.tlsGrade.rawValue, tone: tlsSummary.tlsGrade.tone)) | ||
| 64 | ForEach(Array(tlsSummary.tlsHighlights.enumerated()), id: \.offset) { _, highlight in | ||
| 65 | MessageRowView(text: highlight, isError: isTLSHighlightError(highlight)) | ||
| 66 | } | ||
| 67 | } | ||
| 68 | if sslLoading { | ||
| 69 | ProgressView("Checking certificate…") | ||
| 70 | .appLoadingStyle() | ||
| 71 | } else if let sslError { | ||
| 72 | MessageRowView(text: sslError, isError: true) | ||
| 73 | } else { | ||
| 74 | ForEach(certificateRows) { row in | ||
| 75 | LabeledValueRow(row: row) | ||
| 76 | } | ||
| 77 | if let sslInfo, !sslInfo.subjectAltNames.isEmpty { | ||
| 78 | Text("SANs") | ||
| 79 | .font(appDensity.font(.caption2)) | ||
| 80 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 81 | ForEach(sslInfo.subjectAltNames, id: \.self) { san in | ||
| 82 | HStack(alignment: .top, spacing: 8) { | ||
| 83 | Text(san) | ||
| 84 | .font(appDensity.font(.caption)) | ||
| 85 | .lineLimit(nil) | ||
| 86 | .fixedSize(horizontal: false, vertical: true) | ||
| 87 | .textSelection(.enabled) | ||
| 88 | Spacer() | ||
| 89 | AppCopyButton(value: san, label: "Copy certificate SAN") | ||
| 90 | } | ||
| 91 | } | ||
| 92 | } | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | CardView { | ||
| 97 | Text("Headers") | ||
| 98 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 99 | .foregroundStyle(Color(.statusInfo)) | ||
| 100 | SectionTrustMetadataView(provenance: httpProvenance, confidence: nil) | ||
| 101 | if headersLoading { | ||
| 102 | ProgressView("Fetching headers…") | ||
| 103 | .appLoadingStyle() | ||
| 104 | } else if let headersError { | ||
| 105 | MessageRowView(text: headersError, isError: true) | ||
| 106 | } else { | ||
| 107 | ForEach(responseRows) { row in | ||
| 108 | LabeledValueRow(row: row) | ||
| 109 | } | ||
| 110 | if headers.isEmpty { | ||
| 111 | MessageRowView(text: "No HTTP headers returned", isError: false) | ||
| 112 | } else { | ||
| 113 | ForEach(headers) { header in | ||
| 114 | HStack(alignment: .top, spacing: 4) { | ||
| 115 | Text(header.name + ":") | ||
| 116 | .font(appDensity.font(.caption)) | ||
| 117 | .foregroundStyle(header.isSecurityHeader ? Color(.statusWarning) : Color(.statusInfo)) | ||
| 118 | Text(header.value) | ||
| 119 | .font(appDensity.font(.caption)) | ||
| 120 | .foregroundStyle(.primary) | ||
| 121 | .textSelection(.enabled) | ||
| 122 | } | ||
| 123 | } | ||
| 124 | } | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | CardView { | ||
| 129 | HStack { | ||
| 130 | Text("Redirects") | ||
| 131 | .font(appDensity.font(.subheadline, weight: .semibold)) | ||
| 132 | .foregroundStyle(Color(.statusInfo)) | ||
| 133 | Spacer() | ||
| 134 | if let finalURL { | ||
| 135 | AppCopyButton(value: finalURL, label: "Copy redirect URL") | ||
| 136 | } | ||
| 137 | } | ||
| 138 | SectionTrustMetadataView(provenance: redirectProvenance, confidence: nil) | ||
| 139 | if redirectLoading { | ||
| 140 | ProgressView("Tracing redirects…") | ||
| 141 | .appLoadingStyle() | ||
| 142 | } else if let redirectError { | ||
| 143 | MessageRowView(text: redirectError, isError: true) | ||
| 144 | } else if redirects.isEmpty { | ||
| 145 | MessageRowView(text: "No redirect data available", isError: false) | ||
| 146 | } else { | ||
| 147 | if let finalURL { | ||
| 148 | LabeledValueRow(row: InfoRowViewData(label: "Final URL", value: finalURL, tone: .secondary)) | ||
| 149 | } | ||
| 150 | ForEach(redirects) { redirect in | ||
| 151 | HStack(alignment: .top, spacing: 6) { | ||
| 152 | Text(redirect.stepLabel) | ||
| 153 | .font(appDensity.font(.caption)) | ||
| 154 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 155 | .frame(width: 16, alignment: .trailing) | ||
| 156 | Text(redirect.statusCode) | ||
| 157 | .font(appDensity.font(.caption)) | ||
| 158 | .foregroundStyle(Color(.statusInfo)) | ||
| 159 | .frame(width: 36, alignment: .leading) | ||
| 160 | Text(redirect.url) | ||
| 161 | .font(appDensity.font(.caption)) | ||
| 162 | .textSelection(.enabled) | ||
| 163 | if redirect.isFinal { | ||
| 164 | Text("(final)") | ||
| 165 | .font(appDensity.font(.caption2)) | ||
| 166 | .foregroundStyle(Color(.appTextSecondary)) | ||
| 167 | } | ||
| 168 | Spacer(minLength: 8) | ||
| 169 | AppCopyButton(value: redirect.url, label: "Copy redirect URL") | ||
| 170 | } | ||
| 171 | } | ||
| 172 | } | ||
| 173 | } | ||
| 174 | } | ||
| 175 | } | ||
| 176 | |||
| 177 | private func isTLSHighlightError(_ highlight: String) -> Bool { | ||
| 178 | let normalized = highlight.lowercased() | ||
| 179 | if normalized.contains("no weak tls indicators were detected") { | ||
| 180 | return false | ||
| 181 | } | ||
| 182 | return normalized.contains("expires") | ||
| 183 | || normalized.contains("weak") | ||
| 184 | || normalized.contains("tls 1.0") | ||
| 185 | || normalized.contains("tls 1.1") | ||
| 186 | } | ||
| 187 | } | ||