Commit eb13bc4912
eb13bc4912abfe8b022e54f4294f556bfd30a8d2
parent: d368dd804e
Verified · cmc
cmc <hello@cleberg.net> · 2026-10-14 14:13 UTC
App icon picker in the iOS Settings tab
Layout: unified · split
Sources/OrgPresentation/AppIcons.swift
added
+20
| @@ -0,0 +1,20 @@ |
| 1 | /// The app icons `scripts/make-icon.swift` draws, by id, in its order. |
| 2 | public enum AppIcons { |
| 3 | public static let ids = [ |
| 4 | "default", "midnight", "paper", "org", "sunset", "forest", "mono", "rainbow", "outline", "terminal", |
| 5 | "unicorn", "unicorn-night", "unicorn-pastel", |
| 6 | ] |
| 7 | |
| 8 | private static func words(_ id: String) -> [String] { id.split(separator: "-").map { $0.prefix(1).uppercased() + $0.dropFirst() } } |
| 9 | |
| 10 | public static func name(_ id: String) -> String { words(id).joined(separator: " ") } |
| 11 | |
| 12 | /// The iOS alternate icon's name; nil for the primary icon. |
| 13 | public static func alternateName(_ id: String) -> String? { |
| 14 | id == "default" ? nil : "AppIcon-" + words(id).joined() |
| 15 | } |
| 16 | |
| 17 | public static func id(alternateName: String?) -> String { |
| 18 | ids.first { self.alternateName($0) == alternateName && alternateName != nil } ?? "default" |
| 19 | } |
| 20 | } |
Sources/OrgstarMobile/AppIconScreen.swift
added
+49
| @@ -0,0 +1,49 @@ |
| 1 | #if os(iOS) |
| 2 | import OrgPresentation |
| 3 | import SwiftUI |
| 4 | import UIKit |
| 5 | |
| 6 | /// The app icons, as previews; tapping one makes it the home screen's icon. |
| 7 | struct AppIconScreen: View { |
| 8 | @State private var current = AppIcons.id(alternateName: UIApplication.shared.alternateIconName) |
| 9 | @State private var failure: String? |
| 10 | |
| 11 | var body: some View { |
| 12 | ScrollView { |
| 13 | LazyVGrid(columns: [GridItem(.adaptive(minimum: 88), spacing: 16)], spacing: 20) { |
| 14 | ForEach(AppIcons.ids, id: \.self) { id in |
| 15 | Button { choose(id) } label: { |
| 16 | VStack(spacing: 6) { |
| 17 | Image("IconPreview-\(id)") |
| 18 | .resizable() |
| 19 | .frame(width: 72, height: 72) |
| 20 | .clipShape(RoundedRectangle(cornerRadius: 16, style: .continuous)) |
| 21 | .overlay(RoundedRectangle(cornerRadius: 16, style: .continuous) |
| 22 | .strokeBorder(id == current ? Color.accentColor : .clear, lineWidth: 3).padding(-4)) |
| 23 | Text(AppIcons.name(id)).font(.caption).foregroundStyle(.primary) |
| 24 | } |
| 25 | } |
| 26 | .buttonStyle(.plain) |
| 27 | .accessibilityAddTraits(id == current ? .isSelected : []) |
| 28 | } |
| 29 | } |
| 30 | .padding() |
| 31 | if let failure { Text(failure).foregroundStyle(.red).padding(.horizontal) } |
| 32 | } |
| 33 | .navigationTitle("App Icon") |
| 34 | } |
| 35 | |
| 36 | private func choose(_ id: String) { |
| 37 | guard id != current, UIApplication.shared.supportsAlternateIcons else { return } |
| 38 | Task { |
| 39 | do { |
| 40 | try await UIApplication.shared.setAlternateIconName(AppIcons.alternateName(id)) |
| 41 | current = id |
| 42 | failure = nil |
| 43 | } catch { |
| 44 | failure = error.localizedDescription |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | #endif |
Sources/OrgstarMobile/SettingsScreen.swift
+5
| @@ -101,6 +101,11 @@ struct SettingsScreen: View { |
| 101 | 101 | } label: { |
| 102 | 102 | LabeledContent("Dark Theme", value: ThemePickerScreen.current(.dark).name) |
| 103 | 103 | } |
| 104 | NavigationLink { |
| 105 | AppIconScreen() |
| 106 | } label: { |
| 107 | LabeledContent("App Icon", value: AppIcons.name(AppIcons.id(alternateName: UIApplication.shared.alternateIconName))) |
| 108 | } |
| 104 | 109 | } |
| 105 | 110 | calendarSection |
| 106 | 111 | reminderSection |
Sources/OrgstarMobile/ThemePickerScreen.swift
+8 −7
| @@ -24,6 +24,7 @@ struct ThemePickerScreen: View { |
| 24 | 24 | if palette.id == current { Image(systemName: "checkmark").foregroundStyle(.tint) } |
| 25 | 25 | } |
| 26 | 26 | } |
| 27 | .buttonStyle(.plain) |
| 27 | 28 | } |
| 28 | 29 | .navigationTitle(appearance == .light ? "Light Theme" : "Dark Theme") |
| 29 | 30 | } |
| @@ -41,13 +42,13 @@ struct ThemePickerScreen: View { |
| 41 | 42 | } |
| 42 | 43 | let font = Font.system(.footnote, design: .monospaced) |
| 43 | 44 | return VStack(alignment: .leading, spacing: 2) { |
| 44 | | (Text("* ").foregroundColor(color("heading-1")) + Text("TODO ").foregroundColor(color("todo")).bold() |
| 45 | | + Text("Plan the trip ").foregroundColor(color("heading-1")).bold() + Text(":travel:").foregroundColor(color("tags"))) |
| 46 | | (Text(" SCHEDULED: ").foregroundColor(color("metadata")) + Text("<2026-10-20 Tue>").foregroundColor(color("timestamp"))) |
| 47 | | (Text(" Book via ").foregroundColor(color("foreground")) + Text("the site").foregroundColor(color("link")).underline() |
| 48 | | + Text(", ").foregroundColor(color("foreground")) + Text("~code~").foregroundColor(color("code"))) |
| 49 | | (Text("** ").foregroundColor(color("heading-2")) + Text("DONE ").foregroundColor(color("done")).bold() |
| 50 | | + Text("Passport").foregroundColor(color("heading-2")).bold()) |
| 45 | (Text(verbatim: "* ").foregroundColor(color("heading-1")) + Text(verbatim: "TODO ").foregroundColor(color("todo")).bold() |
| 46 | + Text(verbatim: "Plan the trip ").foregroundColor(color("heading-1")).bold() + Text(verbatim: ":travel:").foregroundColor(color("tags"))) |
| 47 | (Text(verbatim: " SCHEDULED: ").foregroundColor(color("metadata")) + Text(verbatim: "<2026-10-20 Tue>").foregroundColor(color("timestamp"))) |
| 48 | (Text(verbatim: " Book via ").foregroundColor(color("foreground")) + Text(verbatim: "the site").foregroundColor(color("link")).underline() |
| 49 | + Text(verbatim: ", ").foregroundColor(color("foreground")) + Text(verbatim: "~code~").foregroundColor(color("code"))) |
| 50 | (Text(verbatim: "** ").foregroundColor(color("heading-2")) + Text(verbatim: "DONE ").foregroundColor(color("done")).bold() |
| 51 | + Text(verbatim: "Passport").foregroundColor(color("heading-2")).bold()) |
| 51 | 52 | } |
| 52 | 53 | .font(font) |
| 53 | 54 | .padding(8) |
Tests/OrgPresentationTests/PaletteTests.swift
+9
| @@ -85,4 +85,13 @@ struct PaletteTests { |
| 85 | 85 | #expect(problems.isEmpty, "\(problems)") |
| 86 | 86 | #expect(spec.light.filter { light.colors[$0.key] != nil } == light.colors && spec.dark.filter { dark.colors[$0.key] != nil } == dark.colors) |
| 87 | 87 | } |
| 88 | |
| 89 | @Test func iconIdsMapToAlternateNames() { |
| 90 | #expect(AppIcons.ids.first == "default" && AppIcons.ids.count == 13) |
| 91 | #expect(AppIcons.alternateName("default") == nil) |
| 92 | #expect(AppIcons.alternateName("unicorn-night") == "AppIcon-UnicornNight") |
| 93 | #expect(AppIcons.id(alternateName: "AppIcon-UnicornNight") == "unicorn-night") |
| 94 | #expect(AppIcons.id(alternateName: nil) == "default" && AppIcons.id(alternateName: "AppIcon-Gone") == "default") |
| 95 | #expect(AppIcons.name("unicorn-pastel") == "Unicorn Pastel") |
| 96 | } |
| 88 | 97 | } |