Commit ed75375eb5

ed75375eb5b1fd99336b7369fc806c4c9f911dca

parent: eb13bc4912

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-14 14:17 UTC

App icon picker in Settings ▸ Appearance; Dock icon follows the appearance

Layout: unified · split

Sources/OrgPresentation/AppIcons.swift +9
@@ -18,3 +18,12 @@ public enum AppIcons {
18 ids.first { self.alternateName($0) == alternateName && alternateName != nil } ?? "default" 18 ids.first { self.alternateName($0) == alternateName && alternateName != nil } ?? "default"
19 } 19 }
20} 20}
21
22extension AppIcons {
23 /// The Mac's Dock icon file for `id` in an appearance, in `Contents/Resources/IconPreviews`;
24 /// nil for the default, which is the bundle's own icon.
25 public static func dockFile(_ id: String, dark: Bool) -> String? {
26 guard id != "default", ids.contains(id) else { return nil }
27 return "\(id)-\(dark ? "dark" : "light")"
28 }
29}
Sources/Orgstar/AppIconSection.swift added +42
@@ -0,0 +1,42 @@
1import AppKit
2import OrgPresentation
3import SwiftUI
4
5/// Settings ▸ Appearance ▸ App Icon: the icon the Dock shows while orgstar runs.
6struct AppIconSection: View {
7 @AppStorage("appIcon") private var appIcon = "default"
8
9 var body: some View {
10 Section {
11 LazyVGrid(columns: [GridItem(.adaptive(minimum: 72), spacing: 12)], spacing: 12) {
12 ForEach(AppIcons.ids, id: \.self) { id in
13 Button {
14 appIcon = id
15 DockIcon.apply()
16 } label: {
17 VStack(spacing: 4) {
18 preview(id)
19 .resizable()
20 .frame(width: 56, height: 56)
21 .padding(4)
22 .background(id == appIcon ? Color.accentColor.opacity(0.25) : .clear, in: RoundedRectangle(cornerRadius: 10))
23 Text(AppIcons.name(id)).font(.caption)
24 }
25 }
26 .buttonStyle(.plain)
27 .accessibilityAddTraits(id == appIcon ? .isSelected : [])
28 }
29 }
30 } header: {
31 Text("App Icon")
32 } footer: {
33 Text("The icon shows in the Dock while orgstar runs. Finder, and the Dock after orgstar quits, show the default icon.")
34 .settingsFooter()
35 }
36 }
37
38 private func preview(_ id: String) -> Image {
39 let url = Bundle.main.url(forResource: "\(id)-light", withExtension: "png", subdirectory: "IconPreviews")
40 return url.flatMap { NSImage(contentsOf: $0) }.map { Image(nsImage: $0) } ?? Image(nsImage: NSApp.applicationIconImage)
41 }
42}
Sources/Orgstar/DockIcon.swift added +28
@@ -0,0 +1,28 @@
1import AppKit
2import OrgPresentation
3
4/// The icon chosen in Settings ▸ Appearance, shown in the Dock while orgstar runs, in the
5/// variant for the current appearance.
6@MainActor
7enum DockIcon {
8 private static var observation: NSKeyValueObservation?
9
10 static func apply() {
11 let id = UserDefaults.standard.string(forKey: "appIcon") ?? "default"
12 let dark = NSApp.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]) == .darkAqua
13 guard let file = AppIcons.dockFile(id, dark: dark),
14 let url = Bundle.main.url(forResource: file, withExtension: "png", subdirectory: "IconPreviews") else {
15 NSApp.applicationIconImage = nil
16 return
17 }
18 NSApp.applicationIconImage = NSImage(contentsOf: url)
19 }
20
21 /// Applies now, and again whenever the appearance changes.
22 static func start() {
23 apply()
24 observation = NSApp.observe(\.effectiveAppearance) { _, _ in
25 Task { @MainActor in apply() }
26 }
27 }
28}
Sources/Orgstar/OrgstarApp.swift +3 −1
@@ -182,6 +182,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
182 let updates = Updates() 182 let updates = Updates()
183 183
184 func applicationDidFinishLaunching(_ notification: Notification) { 184 func applicationDidFinishLaunching(_ notification: Notification) {
185 DockIcon.start()
185 if SystemReminderCenter.isAvailable { UNUserNotificationCenter.current().delegate = self } 186 if SystemReminderCenter.isAvailable { UNUserNotificationCenter.current().delegate = self }
186 updates.start() 187 updates.start()
187 } 188 }
@@ -780,6 +781,7 @@ struct SettingsView: View {
780 private var appearance: some View { 781 private var appearance: some View {
781 Form { 782 Form {
782 ThemePickerSection() 783 ThemePickerSection()
784 AppIconSection()
783 Section { 785 Section {
784 Picker("Font", selection: $themeFont) { 786 Picker("Font", selection: $themeFont) {
785 Text("System monospaced").tag("") 787 Text("System monospaced").tag("")
@@ -822,7 +824,7 @@ struct SettingsView: View {
822 } 824 }
823 } 825 }
824 .formStyle(.grouped) 826 .formStyle(.grouped)
825 .frame(height: 380) 827 .frame(height: 620)
826 } 828 }
827 829
828 private var agenda: some View { 830 private var agenda: some View {
Tests/OrgPresentationTests/PaletteTests.swift +7
@@ -94,4 +94,11 @@ struct PaletteTests {
94 #expect(AppIcons.id(alternateName: nil) == "default" && AppIcons.id(alternateName: "AppIcon-Gone") == "default") 94 #expect(AppIcons.id(alternateName: nil) == "default" && AppIcons.id(alternateName: "AppIcon-Gone") == "default")
95 #expect(AppIcons.name("unicorn-pastel") == "Unicorn Pastel") 95 #expect(AppIcons.name("unicorn-pastel") == "Unicorn Pastel")
96 } 96 }
97
98 @Test func dockFilesFollowTheAppearance() {
99 #expect(AppIcons.dockFile("default", dark: true) == nil)
100 #expect(AppIcons.dockFile("gone", dark: false) == nil)
101 #expect(AppIcons.dockFile("unicorn", dark: false) == "unicorn-light")
102 #expect(AppIcons.dockFile("unicorn", dark: true) == "unicorn-dark")
103 }
97} 104}