1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
import SwiftUI
import WidgetKit
struct DomainDigEntry: TimelineEntry {
let date: Date
let data: DomainDigWidgetData
}
struct DomainDigProvider: TimelineProvider {
func placeholder(in _: Context) -> DomainDigEntry {
DomainDigEntry(date: Date(), data: .placeholder)
}
func getSnapshot(in context: Context, completion: @escaping (DomainDigEntry) -> Void) {
let data = context.isPreview ? .placeholder : (DomainDigWidgetStore.read() ?? .placeholder)
completion(DomainDigEntry(date: Date(), data: data))
}
func getTimeline(in _: Context, completion: @escaping (Timeline<DomainDigEntry>) -> Void) {
let data = DomainDigWidgetStore.read() ?? .empty
let entry = DomainDigEntry(date: Date(), data: data)
// The app reloads timelines on foreground and on watchlist changes; this
// periodic refresh is a backstop so cert countdowns stay roughly current.
let next = Calendar.current.date(byAdding: .hour, value: 6, to: Date())
?? Date().addingTimeInterval(6 * 3600)
completion(Timeline(entries: [entry], policy: .after(next)))
}
}
struct DomainDigPortfolioWidget: Widget {
let kind = "DomainDigPortfolioWidget"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: DomainDigProvider()) { entry in
DomainDigWidgetView(data: entry.data)
.containerBackground(.fill.tertiary, for: .widget)
// Clamped here and ONLY here. A widget canvas is a fixed
// system-defined size and WidgetKit truncates overflow with no
// scroll affordance, so unclamped accessibility sizes produce
// less readable output, not more. In-app there is always a
// scroll view, so nothing there is clamped.
.dynamicTypeSize(...DynamicTypeSize.accessibility1)
}
.configurationDisplayName("Domain Portfolio")
.description("Health and certificate status for your tracked domains.")
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
}
}
struct DomainDigWidgetView: View {
@Environment(\.widgetFamily) private var family
let data: DomainDigWidgetData
var body: some View {
if data.totalDomains == 0 {
emptyState
} else {
if family == .systemSmall {
smallView
} else {
mediumOrLargeView
}
}
}
private var emptyState: some View {
VStack(spacing: 6) {
Image(systemName: "magnifyingglass")
.font(.title2)
.foregroundStyle(Color(.appTextSecondary))
Text("No tracked domains")
.font(.caption)
.foregroundStyle(Color(.appTextSecondary))
.multilineTextAlignment(.center)
}
}
// MARK: Small
private var smallView: some View {
VStack(alignment: .leading, spacing: 8) {
HStack(spacing: 4) {
Image(systemName: "shield.lefthalf.filled")
Text("DomainDig")
.fontWeight(.semibold)
Spacer()
}
.font(.caption2)
.foregroundStyle(Color(.appTextSecondary))
Text("\(data.totalDomains)")
.font(.system(.largeTitle, design: .rounded, weight: .bold))
Text("tracked")
.font(.caption2)
.foregroundStyle(Color(.appTextSecondary))
Spacer(minLength: 0)
HStack(spacing: 10) {
countPill(data.healthyCount, .healthy, "healthy")
countPill(data.warningCount, .warning, "warning")
countPill(data.criticalCount, .critical, "critical")
}
}
}
private func countPill(_ value: Int, _ status: DomainDigWidgetStatus, _ label: String) -> some View {
HStack(spacing: 3) {
Image(systemName: symbol(for: status))
.font(.caption2)
.foregroundStyle(color(for: status))
Text("\(value)").font(.caption).fontWeight(.medium)
}
// A coloured dot and a number say nothing on their own.
.accessibilityElement(children: .ignore)
.accessibilityLabel("\(value) \(label)")
}
// MARK: Medium / Large
private var mediumOrLargeView: some View {
VStack(alignment: .leading, spacing: 10) {
HStack {
Label("Domain Portfolio", systemImage: "shield.lefthalf.filled")
.font(.caption)
.fontWeight(.semibold)
.foregroundStyle(Color(.appTextSecondary))
Spacer()
Text("\(data.totalDomains) tracked")
.font(.caption2)
.foregroundStyle(Color(.appTextSecondary))
}
HStack(spacing: 12) {
summaryStat(data.healthyCount, "Healthy", Color(.statusPositive))
summaryStat(data.warningCount, "Warning", Color(.statusWarning))
summaryStat(data.criticalCount, "Critical", Color(.statusCritical))
summaryStat(data.expiringSoonCount, "Expiring", Color(.statusWarning))
}
Divider()
VStack(spacing: 6) {
ForEach(data.domains.prefix(family == .systemLarge ? 6 : 3)) { domain in
Link(destination: DomainDigDeepLink.url(for: .detail(domain.domain))) {
domainRow(domain)
}
}
}
Spacer(minLength: 0)
}
}
private func summaryStat(_ value: Int, _ label: String, _ color: Color) -> some View {
VStack(alignment: .leading, spacing: 1) {
Text("\(value)")
.font(.headline)
.foregroundStyle(color)
Text(label)
.font(.caption2)
.foregroundStyle(Color(.appTextSecondary))
}
.frame(maxWidth: .infinity, alignment: .leading)
}
private func domainRow(_ domain: DomainDigWidgetDomain) -> some View {
HStack(spacing: 6) {
Image(systemName: symbol(for: domain.status))
.font(.caption2)
.foregroundStyle(color(for: domain.status))
if domain.isPinned {
Image(systemName: "pin.fill")
.font(.caption2)
.foregroundStyle(Color(.appTextSecondary))
}
Text(domain.domain)
.font(.caption)
.lineLimit(1)
Spacer(minLength: 4)
Text(certLabel(for: domain))
.font(.caption2)
.foregroundStyle(Color(.appTextSecondary))
}
// The status is a silent 8pt dot and the cert countdown is bare ("12d"),
// both meaningless to VoiceOver. Collapse the row into one spoken phrase.
.accessibilityElement(children: .ignore)
.accessibilityLabel(rowAccessibilityLabel(domain))
}
private func rowAccessibilityLabel(_ domain: DomainDigWidgetDomain) -> String {
var parts = [domain.domain, statusLabel(domain.status)]
if domain.isPinned { parts.append("pinned") }
parts.append(certAccessibilityLabel(domain))
return parts.joined(separator: ", ")
}
private func statusLabel(_ status: DomainDigWidgetStatus) -> String {
switch status {
case .healthy: return "healthy"
case .warning: return "warning"
case .critical: return "critical"
}
}
private func certAccessibilityLabel(_ domain: DomainDigWidgetDomain) -> String {
guard let days = domain.certDaysRemaining else { return "certificate status unknown" }
if days < 0 { return "certificate expired" }
return "certificate expires in \(days) day\(days == 1 ? "" : "s")"
}
private func certLabel(for domain: DomainDigWidgetDomain) -> String {
guard let days = domain.certDaysRemaining else { return "—" }
if days < 0 { return "expired" }
return "\(days)d"
}
private func color(for status: DomainDigWidgetStatus) -> Color {
switch status {
case .healthy: return Color(.statusPositive)
case .warning: return Color(.statusWarning)
case .critical: return Color(.statusCritical)
}
}
/// Same symbol vocabulary as the in-app badges, so status survives without
/// colour (Differentiate Without Color, greyscale, colour-blind viewers) and
/// reads consistently across surfaces.
private func symbol(for status: DomainDigWidgetStatus) -> String {
switch status {
case .healthy: return "checkmark.circle.fill"
case .warning: return "exclamationmark.triangle.fill"
case .critical: return "exclamationmark.octagon.fill"
}
}
}
|