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.
2public 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)
2import OrgPresentation
3import SwiftUI
4import UIKit
5
6/// The app icons, as previews; tapping one makes it the home screen's icon.
7struct 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 {
101101 } label: {
102102 LabeledContent("Dark Theme", value: ThemePickerScreen.current(.dark).name)
103103 }
104 NavigationLink {
105 AppIconScreen()
106 } label: {
107 LabeledContent("App Icon", value: AppIcons.name(AppIcons.id(alternateName: UIApplication.shared.alternateIconName)))
108 }
104109 }
105110 calendarSection
106111 reminderSection
Sources/OrgstarMobile/ThemePickerScreen.swift +8 −7
@@ -24,6 +24,7 @@ struct ThemePickerScreen: View {
2424 if palette.id == current { Image(systemName: "checkmark").foregroundStyle(.tint) }
2525 }
2626 }
27 .buttonStyle(.plain)
2728 }
2829 .navigationTitle(appearance == .light ? "Light Theme" : "Dark Theme")
2930 }
@@ -41,13 +42,13 @@ struct ThemePickerScreen: View {
4142 }
4243 let font = Font.system(.footnote, design: .monospaced)
4344 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())
5152 }
5253 .font(font)
5354 .padding(8)
Tests/OrgPresentationTests/PaletteTests.swift +9
@@ -85,4 +85,13 @@ struct PaletteTests {
8585 #expect(problems.isEmpty, "\(problems)")
8686 #expect(spec.light.filter { light.colors[$0.key] != nil } == light.colors && spec.dark.filter { dark.colors[$0.key] != nil } == dark.colors)
8787 }
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 }
8897}