Commit d944bf64f5
Verified · cmc
Layout: unified · split
DomainDig.xcodeproj/project.pbxproj +4
| @@ -631,7 +631,9 @@ | ||
| 631 | 631 | 8B7800752F6090E400933221 /* Debug */ = { |
| 632 | 632 | isa = XCBuildConfiguration; |
| 633 | 633 | buildSettings = { |
| 634 | ASSETCATALOG_COMPILER_ALTERNATE_APPICON_NAMES = "AppIconGraphite AppIconForest AppIconPlum"; | |
| 634 | 635 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; |
| 636 | ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; | |
| 635 | 637 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; |
| 636 | 638 | CODE_SIGN_ENTITLEMENTS = DomainDig/DomainDig.entitlements; |
| 637 | 639 | CODE_SIGN_STYLE = Automatic; |
| @@ -668,7 +670,9 @@ | ||
| 668 | 670 | 8B7800762F6090E400933221 /* Release */ = { |
| 669 | 671 | isa = XCBuildConfiguration; |
| 670 | 672 | buildSettings = { |
| 673 | ASSETCATALOG_COMPILER_ALTERNATE_APPICON_NAMES = "AppIconGraphite AppIconForest AppIconPlum"; | |
| 671 | 674 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; |
| 675 | ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; | |
| 672 | 676 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; |
| 673 | 677 | CODE_SIGN_ENTITLEMENTS = DomainDig/DomainDig.entitlements; |
| 674 | 678 | 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 @@ | ||
| 1 | 1 | { |
| 2 | "images" : [ | |
| 2 | "images": [ | |
| 3 | 3 | { |
| 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" | |
| 8 | 8 | }, |
| 9 | 9 | { |
| 10 | "appearances" : [ | |
| 10 | "appearances": [ | |
| 11 | 11 | { |
| 12 | "appearance" : "luminosity", | |
| 13 | "value" : "dark" | |
| 12 | "appearance": "luminosity", | |
| 13 | "value": "dark" | |
| 14 | 14 | } |
| 15 | 15 | ], |
| 16 | "idiom" : "universal", | |
| 17 | "platform" : "ios", | |
| 18 | "size" : "1024x1024" | |
| 16 | "idiom": "universal", | |
| 17 | "platform": "ios", | |
| 18 | "size": "1024x1024" | |
| 19 | 19 | }, |
| 20 | 20 | { |
| 21 | "appearances" : [ | |
| 21 | "appearances": [ | |
| 22 | 22 | { |
| 23 | "appearance" : "luminosity", | |
| 24 | "value" : "tinted" | |
| 23 | "appearance": "luminosity", | |
| 24 | "value": "tinted" | |
| 25 | 25 | } |
| 26 | 26 | ], |
| 27 | "idiom" : "universal", | |
| 28 | "platform" : "ios", | |
| 29 | "size" : "1024x1024" | |
| 27 | "idiom": "universal", | |
| 28 | "platform": "ios", | |
| 29 | "size": "1024x1024" | |
| 30 | 30 | } |
| 31 | 31 | ], |
| 32 | "info" : { | |
| 33 | "author" : "xcode", | |
| 34 | "version" : 1 | |
| 32 | "info": { | |
| 33 | "author": "xcode", | |
| 34 | "version": 1 | |
| 35 | 35 | } |
| 36 | 36 | } |
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 { | ||
| 38 | 38 | RootTabView(viewModel: viewModel) |
| 39 | 39 | .environment(\.appDensity, AppDensity(rawValue: density) ?? .compact) |
| 40 | 40 | .environment(\.theme, selectedAccent.theme) |
| 41 | .task { AppIconController.apply(selectedAccent) } | |
| 42 | .onChange(of: accent) { _, _ in AppIconController.apply(selectedAccent) } | |
| 41 | 43 | // So standard controls pick the accent up too, not only the |
| 42 | 44 | // views that name a token. |
| 43 | 45 | .tint(selectedAccent == .default ? nil : selectedAccent.theme.accentFill) |
DomainDig/Theme.swift +39
| @@ -134,6 +134,45 @@ nonisolated enum AccentTheme: String, Codable, CaseIterable, Identifiable, Senda | ||
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | extension 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 | |
| 159 | enum 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 | ||
| 137 | 176 | nonisolated private struct ThemeKey: EnvironmentKey { |
| 138 | 177 | static let defaultValue = Theme.default |
| 139 | 178 | } |
DomainDigTests/ThemeTests.swift +37
| @@ -109,6 +109,43 @@ final class ThemeTests: XCTestCase { | ||
| 109 | 109 | XCTAssertEqual(FeatureAccessService.upgradeMessage(for: .accentTheme), "Available in Pro+") |
| 110 | 110 | } |
| 111 | 111 | |
| 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 | ||
| 112 | 149 | // MARK: Badge models carry tokens |
| 113 | 150 | |
| 114 | 151 | /// 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 | ||
| 18 | import CoreGraphics | |
| 19 | import Foundation | |
| 20 | import ImageIO | |
| 21 | import UniformTypeIdentifiers | |
| 22 | ||
| 23 | let side = 1024 | |
| 24 | let size = CGFloat(side) | |
| 25 | ||
| 26 | struct 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 | ||
| 34 | let 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 | ||
| 41 | struct Failure: LocalizedError { | |
| 42 | let message: String | |
| 43 | init(_ message: String) { self.message = message } | |
| 44 | var errorDescription: String? { message } | |
| 45 | } | |
| 46 | ||
| 47 | private 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. | |
| 58 | private 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 | ||
| 95 | func 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 | ||
| 142 | let arguments = CommandLine.arguments | |
| 143 | guard arguments.count == 2 else { | |
| 144 | FileHandle.standardError.write(Data("usage: make-app-icons.swift <output-directory>\n".utf8)) | |
| 145 | exit(2) | |
| 146 | } | |
| 147 | ||
| 148 | let outputDirectory = URL(fileURLWithPath: arguments[1], isDirectory: true) | |
| 149 | try FileManager.default.createDirectory(at: outputDirectory, withIntermediateDirectories: true) | |
| 150 | ||
| 151 | for theme in themes { | |
| 152 | let url = outputDirectory.appendingPathComponent("\(theme.name)-1024.png") | |
| 153 | try render(theme, to: url) | |
| 154 | print("wrote \(url.lastPathComponent)") | |
| 155 | } | |