Add an app icon per accent theme !49

merged merged by cmc on 2026-10-26 03:54 UTC · krz/domain-dig:alternate-app-icons into main

15 files changed, +385 −20

Layout: unified · split

Docs/ACCESSIBILITY.txt +20
@@ -184,6 +184,26 @@ These are latent rather than new: nothing in the section changed when Inspect
184184moved to a `List`. They need a seeded recent-searches fixture to be audited
185185properly, which the seed harness does not have.
186186
187## The empty-state screens are not reliably empty
188
189`AccessibilityAuditHarness.launch` only adds launch arguments; it never resets
190the app's store. A `seeded: true` test therefore leaves its fixtures behind, and
191any later non-seeded launch audits a populated app rather than an empty one.
192
193Measured: `testTrackedDomainsScreen` reports 1 finding and passes against a
194clean store, and 6 findings — including an enforced
195`[FAIL][dynamicType]` on `EditButton` — when a seeded test has run before it in
196the same invocation. Nothing about the screen changed between the two.
197
198So the enforced suite's result depends on execution order, which means the
199pre-push hook can report a failure that a re-run on a fresh simulator does not.
200When a `[FAIL]` appears, check it against a clean store before believing it.
201
202Fixing it properly means the harness resetting the app's store between
203launches — a launch argument that wipes the suite's `UserDefaults` domain
204would do it, and would also let the recent-searches section below be audited on
205purpose rather than by accident.
206
187207## Why the floor runtime needs its own run
188208
189209**Audit coverage is not nested across OS versions.** Each runtime reports
DomainDig.xcodeproj/project.pbxproj +4
@@ -631,7 +631,9 @@
631631 8B7800752F6090E400933221 /* Debug */ = {
632632 isa = XCBuildConfiguration;
633633 buildSettings = {
634 ASSETCATALOG_COMPILER_ALTERNATE_APPICON_NAMES = "AppIconGraphite AppIconForest AppIconPlum";
634635 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
636 ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
635637 ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
636638 CODE_SIGN_ENTITLEMENTS = DomainDig/DomainDig.entitlements;
637639 CODE_SIGN_STYLE = Automatic;
@@ -668,7 +670,9 @@
668670 8B7800762F6090E400933221 /* Release */ = {
669671 isa = XCBuildConfiguration;
670672 buildSettings = {
673 ASSETCATALOG_COMPILER_ALTERNATE_APPICON_NAMES = "AppIconGraphite AppIconForest AppIconPlum";
671674 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
675 ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
672676 ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
673677 CODE_SIGN_ENTITLEMENTS = DomainDig/DomainDig.entitlements;
674678 CODE_SIGN_STYLE = Automatic;
DomainDig/Assets.xcassets/AppIcon.appiconset/AppIcon.png added

Binary file not shown.

DomainDig/Assets.xcassets/AppIcon.appiconset/Contents.json +20 −20
@@ -1,36 +1,36 @@
11{
2 "images" : [
2 "images": [
33 {
4 "filename" : "domaindig.png",
5 "idiom" : "universal",
6 "platform" : "ios",
7 "size" : "1024x1024"
4 "filename": "AppIcon.png",
5 "idiom": "universal",
6 "platform": "ios",
7 "size": "1024x1024"
88 },
99 {
10 "appearances" : [
10 "appearances": [
1111 {
12 "appearance" : "luminosity",
13 "value" : "dark"
12 "appearance": "luminosity",
13 "value": "dark"
1414 }
1515 ],
16 "idiom" : "universal",
17 "platform" : "ios",
18 "size" : "1024x1024"
16 "idiom": "universal",
17 "platform": "ios",
18 "size": "1024x1024"
1919 },
2020 {
21 "appearances" : [
21 "appearances": [
2222 {
23 "appearance" : "luminosity",
24 "value" : "tinted"
23 "appearance": "luminosity",
24 "value": "tinted"
2525 }
2626 ],
27 "idiom" : "universal",
28 "platform" : "ios",
29 "size" : "1024x1024"
27 "idiom": "universal",
28 "platform": "ios",
29 "size": "1024x1024"
3030 }
3131 ],
32 "info" : {
33 "author" : "xcode",
34 "version" : 1
32 "info": {
33 "author": "xcode",
34 "version": 1
3535 }
3636}
DomainDig/Assets.xcassets/AppIcon.appiconset/domaindig.png deleted

Binary file not shown.

DomainDig/Assets.xcassets/AppIconForest.appiconset/AppIconForest.png added

Binary file not shown.

DomainDig/Assets.xcassets/AppIconForest.appiconset/Contents.json added +36
@@ -0,0 +1,36 @@
1{
2 "images": [
3 {
4 "filename": "AppIconForest.png",
5 "idiom": "universal",
6 "platform": "ios",
7 "size": "1024x1024"
8 },
9 {
10 "appearances": [
11 {
12 "appearance": "luminosity",
13 "value": "dark"
14 }
15 ],
16 "idiom": "universal",
17 "platform": "ios",
18 "size": "1024x1024"
19 },
20 {
21 "appearances": [
22 {
23 "appearance": "luminosity",
24 "value": "tinted"
25 }
26 ],
27 "idiom": "universal",
28 "platform": "ios",
29 "size": "1024x1024"
30 }
31 ],
32 "info": {
33 "author": "xcode",
34 "version": 1
35 }
36}
DomainDig/Assets.xcassets/AppIconGraphite.appiconset/AppIconGraphite.png added

Binary file not shown.

DomainDig/Assets.xcassets/AppIconGraphite.appiconset/Contents.json added +36
@@ -0,0 +1,36 @@
1{
2 "images": [
3 {
4 "filename": "AppIconGraphite.png",
5 "idiom": "universal",
6 "platform": "ios",
7 "size": "1024x1024"
8 },
9 {
10 "appearances": [
11 {
12 "appearance": "luminosity",
13 "value": "dark"
14 }
15 ],
16 "idiom": "universal",
17 "platform": "ios",
18 "size": "1024x1024"
19 },
20 {
21 "appearances": [
22 {
23 "appearance": "luminosity",
24 "value": "tinted"
25 }
26 ],
27 "idiom": "universal",
28 "platform": "ios",
29 "size": "1024x1024"
30 }
31 ],
32 "info": {
33 "author": "xcode",
34 "version": 1
35 }
36}
DomainDig/Assets.xcassets/AppIconPlum.appiconset/AppIconPlum.png added

Binary file not shown.

DomainDig/Assets.xcassets/AppIconPlum.appiconset/Contents.json added +36
@@ -0,0 +1,36 @@
1{
2 "images": [
3 {
4 "filename": "AppIconPlum.png",
5 "idiom": "universal",
6 "platform": "ios",
7 "size": "1024x1024"
8 },
9 {
10 "appearances": [
11 {
12 "appearance": "luminosity",
13 "value": "dark"
14 }
15 ],
16 "idiom": "universal",
17 "platform": "ios",
18 "size": "1024x1024"
19 },
20 {
21 "appearances": [
22 {
23 "appearance": "luminosity",
24 "value": "tinted"
25 }
26 ],
27 "idiom": "universal",
28 "platform": "ios",
29 "size": "1024x1024"
30 }
31 ],
32 "info": {
33 "author": "xcode",
34 "version": 1
35 }
36}
DomainDig/DomainDigApp.swift +2
@@ -38,6 +38,8 @@ struct DomainDigApp: App {
3838 RootTabView(viewModel: viewModel)
3939 .environment(\.appDensity, AppDensity(rawValue: density) ?? .compact)
4040 .environment(\.theme, selectedAccent.theme)
41 .task { AppIconController.apply(selectedAccent) }
42 .onChange(of: accent) { _, _ in AppIconController.apply(selectedAccent) }
4143 // So standard controls pick the accent up too, not only the
4244 // views that name a token.
4345 .tint(selectedAccent == .default ? nil : selectedAccent.theme.accentFill)
DomainDig/Theme.swift +39
@@ -134,6 +134,45 @@ nonisolated enum AccentTheme: String, Codable, CaseIterable, Identifiable, Senda
134134 }
135135}
136136
137extension AccentTheme {
138 /// The alternate app icon for this accent, or `nil` for the primary one.
139 ///
140 /// The names match the asset catalog's icon sets, which
141 /// `ASSETCATALOG_COMPILER_ALTERNATE_APPICON_NAMES` lists.
142 var alternateIconName: String? {
143 switch self {
144 case .default: return nil
145 case .graphite: return "AppIconGraphite"
146 case .forest: return "AppIconForest"
147 case .plum: return "AppIconPlum"
148 }
149 }
150}
151
152/// Keeps the home-screen icon on whichever accent is in force.
153///
154/// The icon follows the accent rather than being a second picker: iOS shows its
155/// own "You have changed the icon" alert on every change and there is no public
156/// way to suppress it, so two pickers would mean two alerts for what a user
157/// thinks of as one choice.
158@MainActor
159enum AppIconController {
160 /// Idempotent, so it is safe to call on launch as well as on change —
161 /// which is what reverts the icon when a lapsed tier drops the accent back
162 /// to default.
163 static func apply(_ accent: AccentTheme) {
164 guard UIApplication.shared.supportsAlternateIcons else { return }
165
166 let desired = accent.alternateIconName
167 guard UIApplication.shared.alternateIconName != desired else { return }
168
169 UIApplication.shared.setAlternateIconName(desired) { error in
170 guard let error else { return }
171 DomainDebugLog.error("AppIcon.setFailed name=\(desired ?? "primary") error=\(error.localizedDescription)")
172 }
173 }
174}
175
137176nonisolated private struct ThemeKey: EnvironmentKey {
138177 static let defaultValue = Theme.default
139178}
DomainDigTests/ThemeTests.swift +37
@@ -109,6 +109,43 @@ final class ThemeTests: XCTestCase {
109109 XCTAssertEqual(FeatureAccessService.upgradeMessage(for: .accentTheme), "Available in Pro+")
110110 }
111111
112 // MARK: App icons
113
114 /// The alternate icon names are strings matched against the asset catalog
115 /// at runtime, so a typo fails the same silent way a wrong colorset name
116 /// would — `setAlternateIconName` just reports an error and the icon stays
117 /// put. This is the parity check for them.
118 func testEveryAccentsIconNameHasAnIconSet() throws {
119 let catalog = URL(fileURLWithPath: #filePath)
120 .deletingLastPathComponent()
121 .deletingLastPathComponent()
122 .appendingPathComponent("DomainDig/Assets.xcassets")
123 let sets = Set(
124 try FileManager.default.contentsOfDirectory(atPath: catalog.path)
125 .filter { $0.hasSuffix(".appiconset") }
126 .map { String($0.dropLast(".appiconset".count)) }
127 )
128
129 for accent in AccentTheme.allCases {
130 guard let name = accent.alternateIconName else { continue }
131 XCTAssertTrue(sets.contains(name), "\(accent) names '\(name)', which is not an icon set")
132 }
133
134 // And the other direction: an icon set nothing selects is dead weight
135 // in the bundle.
136 let named = Set(AccentTheme.allCases.compactMap(\.alternateIconName)).union(["AppIcon"])
137 XCTAssertEqual(sets.subtracting(named), [], "these icon sets are unreachable")
138 }
139
140 /// The default accent uses the primary icon, which is what `nil` means to
141 /// `setAlternateIconName`.
142 func testTheDefaultAccentUsesThePrimaryIcon() {
143 XCTAssertNil(AccentTheme.default.alternateIconName)
144 for accent in AccentTheme.allCases where accent != .default {
145 XCTAssertNotNil(accent.alternateIconName, "\(accent) should have its own icon")
146 }
147 }
148
112149 // MARK: Badge models carry tokens
113150
114151 /// The badges are built outside a view body, which is why their colours are
Scripts/make-app-icons.swift added +155
@@ -0,0 +1,155 @@
1#!/usr/bin/env swift
2
3// Renders the app icon set, one per accent theme.
4//
5// The artwork is generated rather than drawn by hand so it is reproducible and
6// reviewable as source. The mark is the namespace itself: the DNS is a tree
7// from the root down, which is what the app reads, and no other category of app
8// uses it — a magnifying glass would have said "search", which is not the same
9// thing and is every other icon in the category.
10//
11// Only the ground colour changes between themes, so the four read as one app.
12//
13// Usage: swift Scripts/make-app-icons.swift <output-directory>
14//
15// Writes <name>-1024.png per theme. iOS masks the corners itself, so these are
16// full-bleed squares with no rounding and no alpha.
17
18import CoreGraphics
19import Foundation
20import ImageIO
21import UniformTypeIdentifiers
22
23let side = 1024
24let size = CGFloat(side)
25
26struct Theme {
27 let name: String
28 /// Top and bottom of the ground gradient. The bottom carries the same hue
29 /// darker, so the mark keeps its contrast across the whole square.
30 let top: (CGFloat, CGFloat, CGFloat)
31 let bottom: (CGFloat, CGFloat, CGFloat)
32}
33
34let themes = [
35 Theme(name: "AppIcon", top: (0.00, 0.25, 0.87), bottom: (0.00, 0.10, 0.45)),
36 Theme(name: "AppIconGraphite", top: (0.34, 0.36, 0.40), bottom: (0.16, 0.17, 0.20)),
37 Theme(name: "AppIconForest", top: (0.16, 0.48, 0.32), bottom: (0.06, 0.22, 0.15)),
38 Theme(name: "AppIconPlum", top: (0.50, 0.24, 0.52), bottom: (0.24, 0.10, 0.26))
39]
40
41struct Failure: LocalizedError {
42 let message: String
43 init(_ message: String) { self.message = message }
44 var errorDescription: String? { message }
45}
46
47private func dot(_ context: CGContext, _ centre: CGPoint, _ radius: CGFloat) {
48 context.addEllipse(in: CGRect(
49 x: centre.x - radius,
50 y: centre.y - radius,
51 width: radius * 2,
52 height: radius * 2
53 ))
54 context.fillPath()
55}
56
57/// Root, two labels, four leaves — the shape of a hostname read right to left.
58private func drawNamespaceTree(_ context: CGContext) {
59 let nodeRadius = size * 0.056
60 let edgeWidth = size * 0.034
61
62 let root = CGPoint(x: size * 0.5, y: size * 0.775)
63 let labels = [
64 CGPoint(x: size * 0.305, y: size * 0.515),
65 CGPoint(x: size * 0.695, y: size * 0.515)
66 ]
67 let leaves = [
68 CGPoint(x: size * 0.215, y: size * 0.265),
69 CGPoint(x: size * 0.395, y: size * 0.265),
70 CGPoint(x: size * 0.605, y: size * 0.265),
71 CGPoint(x: size * 0.785, y: size * 0.265)
72 ]
73
74 // Edges first, slightly under full white so the nodes stay the emphasis.
75 context.setStrokeColor(CGColor(red: 1, green: 1, blue: 1, alpha: 0.82))
76 context.setLineWidth(edgeWidth)
77 context.setLineCap(.round)
78 for label in labels {
79 context.move(to: root)
80 context.addLine(to: label)
81 context.strokePath()
82 }
83 for (index, leaf) in leaves.enumerated() {
84 context.move(to: labels[index / 2])
85 context.addLine(to: leaf)
86 context.strokePath()
87 }
88
89 context.setFillColor(CGColor(red: 1, green: 1, blue: 1, alpha: 1))
90 dot(context, root, nodeRadius * 1.28)
91 for label in labels { dot(context, label, nodeRadius) }
92 for leaf in leaves { dot(context, leaf, nodeRadius * 0.80) }
93}
94
95func render(_ theme: Theme, to url: URL) throws {
96 let space = CGColorSpaceCreateDeviceRGB()
97 guard let context = CGContext(
98 data: nil,
99 width: side,
100 height: side,
101 bitsPerComponent: 8,
102 bytesPerRow: 0,
103 space: space,
104 bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue
105 ) else {
106 throw Failure("could not create a bitmap context")
107 }
108
109 let colors = [
110 CGColor(red: theme.top.0, green: theme.top.1, blue: theme.top.2, alpha: 1),
111 CGColor(red: theme.bottom.0, green: theme.bottom.1, blue: theme.bottom.2, alpha: 1)
112 ] as CFArray
113 guard let gradient = CGGradient(colorsSpace: space, colors: colors, locations: [0, 1]) else {
114 throw Failure("could not create the gradient")
115 }
116 context.drawLinearGradient(
117 gradient,
118 start: CGPoint(x: 0, y: size),
119 end: CGPoint(x: 0, y: 0),
120 options: []
121 )
122
123 drawNamespaceTree(context)
124
125 guard let image = context.makeImage() else {
126 throw Failure("could not render \(theme.name)")
127 }
128 guard let destination = CGImageDestinationCreateWithURL(
129 url as CFURL,
130 UTType.png.identifier as CFString,
131 1,
132 nil
133 ) else {
134 throw Failure("could not open \(url.path) for writing")
135 }
136 CGImageDestinationAddImage(destination, image, nil)
137 guard CGImageDestinationFinalize(destination) else {
138 throw Failure("could not write \(url.path)")
139 }
140}
141
142let arguments = CommandLine.arguments
143guard arguments.count == 2 else {
144 FileHandle.standardError.write(Data("usage: make-app-icons.swift <output-directory>\n".utf8))
145 exit(2)
146}
147
148let outputDirectory = URL(fileURLWithPath: arguments[1], isDirectory: true)
149try FileManager.default.createDirectory(at: outputDirectory, withIntermediateDirectories: true)
150
151for theme in themes {
152 let url = outputDirectory.appendingPathComponent("\(theme.name)-1024.png")
153 try render(theme, to: url)
154 print("wrote \(url.lastPathComponent)")
155}