Commit f97aeb320e

f97aeb320eeb208cc7385b60b68a152ed5785bf9

parent: 90be8b7159

Verified · cmc

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

Theme picks apply at once; one-appearance themes leave the other to the system; Mac dark Dock icons on a tile

Layout: unified · split

Sources/OrgApp/AgendaSnapshot.swift +7 −1
@@ -145,7 +145,13 @@ public struct AgendaSnapshot: Codable, Equatable, Sendable {
145145 }
146146 var colors: [String: Hex] = [:]
147147 for key in ["agenda-today", "agenda-time", "agenda-date", "foreground", "agenda-background"] {
148 colors[key] = Hex { theme.color(key, dark: $0) }
148 if ThemeSpec.systemDefaults.contains(key) {
149 // Left to the system in an appearance the theme doesn't set: "" there.
150 let (light, dark) = (theme.color(key, dark: false), theme.color(key, dark: true))
151 if light != nil || dark != nil { colors[key] = Hex(light: light?.hex ?? "", dark: dark?.hex ?? "") }
152 } else {
153 colors[key] = Hex { theme.color(key, dark: $0) }
154 }
149155 }
150156 self.colors = colors
151157 self.generated = generated
Sources/OrgApp/ConfigSync.swift +2
@@ -144,6 +144,8 @@ public final class ConfigSync {
144144 guard current != original else { return }
145145 text = current
146146 try? current.write(to: target, atomically: true, encoding: .utf8)
147 // A theme picked in Settings; the watcher's reload sees the text unchanged and skips it.
148 readTheme()
147149 }
148150}
149151#endif
Sources/Orgstar/BacklinksPane.swift +2 −1
@@ -13,6 +13,7 @@ struct BacklinksPane: View {
1313 @State private var toHeading: [HeadingLocation] = []
1414 @State private var toFile: [HeadingLocation] = []
1515 @Environment(\.orgTheme) private var theme
16 @Environment(\.colorScheme) private var colorScheme
1617
1718 /// The heading at the caret.
1819 private var heading: OutlineEntry? { session.outline.last { $0.start <= commands.selection.location } }
@@ -30,7 +31,7 @@ struct BacklinksPane: View {
3031 }
3132 Section("Links to this file") { rows(toFile) }
3233 }
33 .themedListBackground(theme.color("sidebar-background"))
34 .themedListBackground(theme.color("sidebar-background", in: colorScheme))
3435 .task(id: Key(path: session.path, heading: heading?.start, version: session.editVersion)) { refresh() }
3536 }
3637
Sources/Orgstar/BoardView.swift +2 −1
@@ -24,6 +24,7 @@ struct BoardView: View {
2424 @AppStorage("agendaSubfolders") private var includeSubfolders = false
2525 @Environment(\.openWindow) private var openWindow
2626 @Environment(\.orgTheme) private var theme
27 @Environment(\.colorScheme) private var colorScheme
2728
2829 init(workspace: WorkspaceModel, session: DocumentSession, commands: AppCommands) {
2930 self.workspace = workspace
@@ -137,7 +138,7 @@ struct BoardView: View {
137138 }
138139 .padding(12)
139140 }
140 .background(theme.color("agenda-background") ?? .clear)
141 .background(theme.color("agenda-background", in: colorScheme) ?? .clear)
141142 }
142143
143144 private func column(_ keyword: String) -> some View {
Sources/Orgstar/BufferTabs.swift +2 −1
@@ -33,6 +33,7 @@ struct BufferTabs: View {
3333 let pane: EditorPane
3434 let close: (String) -> Void
3535 @Environment(\.orgTheme) private var theme
36 @Environment(\.colorScheme) private var colorScheme
3637
3738 var body: some View {
3839 ScrollView(.horizontal, showsIndicators: false) {
@@ -43,7 +44,7 @@ struct BufferTabs: View {
4344 }
4445 }
4546 .frame(height: 28)
46 .background { Rectangle().fill(theme.color("modeline-background").map(AnyShapeStyle.init) ?? AnyShapeStyle(.bar)) }
47 .background { Rectangle().fill(theme.color("modeline-background", in: colorScheme).map(AnyShapeStyle.init) ?? AnyShapeStyle(.bar)) }
4748 .overlay(alignment: .bottom) { Divider() }
4849 }
4950
Sources/Orgstar/Keys.swift +2 −1
@@ -14,6 +14,7 @@ struct KeyHint: Hashable {
1414struct EchoArea: View {
1515 let commands: AppCommands
1616 @Environment(\.orgTheme) private var theme
17 @Environment(\.colorScheme) private var colorScheme
1718 @State private var showingHints = false
1819 @State private var answer = ""
1920 @FocusState private var answerFocused: Bool
@@ -107,7 +108,7 @@ struct EchoArea: View {
107108 }
108109 }
109110 .foregroundStyle(theme.color("modeline-foreground") ?? .primary)
110 .background { if let bg = theme.color("modeline-background") { bg } else { Rectangle().fill(.bar) } }
111 .background { if let bg = theme.color("modeline-background", in: colorScheme) { bg } else { Rectangle().fill(.bar) } }
111112 .task(id: commands.pendingKeys) {
112113 showingHints = false
113114 guard commands.pendingKeys != nil else { return }
Sources/Orgstar/ModeLine.swift +2 −1
@@ -13,6 +13,7 @@ struct ModeLine: View {
1313 /// Runs an app command (clock out, go to the clocked entry).
1414 let perform: (String) -> Void
1515 @Environment(\.orgTheme) private var theme
16 @Environment(\.colorScheme) private var colorScheme
1617 @State private var words: Int?
1718 @State private var characters = 0
1819 @State private var crlf = false
@@ -99,7 +100,7 @@ struct ModeLine: View {
99100 .foregroundStyle(theme.color("modeline-foreground") ?? .secondary)
100101 .padding(.horizontal, 10)
101102 .frame(height: 22)
102 .background { if let bg = theme.color("modeline-background") { bg } else { Rectangle().fill(.bar) } }
103 .background { if let bg = theme.color("modeline-background", in: colorScheme) { bg } else { Rectangle().fill(.bar) } }
103104 .overlay(alignment: .top) { Divider() }
104105 .task(id: session.path) {
105106 // HEAD changes outside the app, so look again every few seconds.
Sources/Orgstar/Sidebar.swift +4 −2
@@ -14,6 +14,7 @@ struct Sidebar: View {
1414 @State private var removing: String?
1515 /// A file operation waiting for a name or a confirmation.
1616 @Environment(\.orgTheme) private var theme
17 @Environment(\.colorScheme) private var colorScheme
1718 @State var pending: FileOperation?
1819 @State var name = ""
1920 @State var failure: String?
@@ -50,7 +51,7 @@ struct Sidebar: View {
5051 }
5152 }
5253 .listStyle(.sidebar)
53 .themedListBackground(theme.color("sidebar-background"))
54 .themedListBackground(theme.color("sidebar-background", in: colorScheme))
5455 .safeAreaInset(edge: .bottom, spacing: 0) {
5556 HStack(spacing: 4) {
5657 Button("Add Folder…", systemImage: "plus", action: addFolder)
@@ -120,6 +121,7 @@ struct Sidebar: View {
120121struct OutlineColumn: View {
121122 let session: DocumentSession
122123 @Environment(\.orgTheme) private var theme
124 @Environment(\.colorScheme) private var colorScheme
123125
124126 var body: some View {
125127 List(Array(session.outline.enumerated()), id: \.element.start) { _, entry in
@@ -133,7 +135,7 @@ struct OutlineColumn: View {
133135 }
134136 .buttonStyle(.plain)
135137 }
136 .themedListBackground(theme.color("sidebar-background"))
138 .themedListBackground(theme.color("sidebar-background", in: colorScheme))
137139 .overlay {
138140 if session.path != nil, !session.isOrg {
139141 ContentUnavailableView("No outline", systemImage: "doc.plaintext", description: Text("Only org files have an outline."))
Sources/Orgstar/ThemeColors.swift +6
@@ -21,6 +21,12 @@ extension ThemeSpec {
2121 })
2222 }
2323
24 /// `key` in `scheme` only, nil where the theme leaves it to the system there, for
25 /// backgrounds that fall back to a material rather than a color.
26 func color(_ key: String, in scheme: ColorScheme) -> Color? {
27 color(key, dark: scheme == .dark).map { Color(.sRGB, red: $0.red, green: $0.green, blue: $0.blue, opacity: $0.alpha) }
28 }
29
2430 /// A color that follows the appearance from a helper taking `dark:` (`todoColor`,
2531 /// `statusColor`, …), or `fallback` where it gives none.
2632 func dynamic(_ fallback: NSColor = .labelColor, _ pick: @escaping @Sendable (_ dark: Bool) -> RGBA?) -> Color {
Sources/OrgstarWidgets/AgendaTimeline.swift +2 −1
@@ -51,8 +51,9 @@ extension AgendaSnapshot.Hex {
5151}
5252
5353extension AgendaSnapshot {
54 /// Nil where the theme leaves `key` to the system in `scheme`.
5455 func color(_ key: String, _ scheme: ColorScheme) -> Color? {
55 colors[key]?.color(scheme)
56 colors[key].flatMap { AgendaSnapshot.Hex.parse(scheme == .dark ? $0.dark : $0.light) }
5657 }
5758
5859 /// A day for the gallery and previews.
Tests/OrgAppTests/AgendaSnapshotTests.swift +7
@@ -78,6 +78,13 @@ struct AgendaSnapshotTests {
7878 #expect(snapshot.colors["agenda-background"] == nil)
7979 }
8080
81 @Test func aColorTheSystemKeepsInOneAppearanceStaysUnsetThere() throws {
82 let theme = ThemeSpec.base(light: nil, dark: "nord").0
83 let snapshot = AgendaSnapshot(groups: [], today: Self.today, theme: theme, generated: Date())
84 let background = try #require(snapshot.colors["agenda-background"])
85 #expect(background.light == "" && background.dark == "#2e3440")
86 }
87
8188 @Test func encodesAndDecodes() throws {
8289 let snapshot = Self.snapshot()
8390 let data = try AgendaSnapshot.encoder.encode(snapshot)
Tests/OrgAppTests/UserConfigTests.swift +16
@@ -294,4 +294,20 @@ struct ThemeReadingTests {
294294 #expect(try !UserConfig.copyTheme(light: light, dark: dark, to: folder))
295295 #expect(try String(contentsOf: file, encoding: .utf8) == "mine")
296296 }
297
298 @Test @MainActor func aThemePickedInTheAppAppliesAtOnce() throws {
299 let name = "orgstar-pick-\(UUID().uuidString)"
300 let defaults = UserDefaults(suiteName: name)!
301 defer { defaults.removePersistentDomain(forName: name) }
302 let folder = FileManager.default.temporaryDirectory.appendingPathComponent(name)
303 defer { try? FileManager.default.removeItem(at: folder) }
304 try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
305 try "[theme]\n".write(to: folder.appendingPathComponent("config.toml"), atomically: true, encoding: .utf8)
306 let sync = ConfigSync(url: folder.appendingPathComponent("config.toml"), defaults: defaults)
307 sync.start(watch: false)
308 defaults.set("nord", forKey: "themeDark")
309 sync.writeBack()
310 #expect(try String(contentsOf: folder.appendingPathComponent("config.toml"), encoding: .utf8).contains("dark-theme = \"nord\""))
311 #expect(sync.theme.dark["background"] == ThemeSpec.palette("nord", .dark)?.colors["background"])
312 }
297313}
Tests/OrgPresentationTests/PaletteTests.swift +8
@@ -101,4 +101,12 @@ struct PaletteTests {
101101 #expect(AppIcons.dockFile("unicorn", dark: false) == "unicorn-light")
102102 #expect(AppIcons.dockFile("unicorn", dark: true) == "unicorn-dark")
103103 }
104
105 @Test func aDarkOnlyChoiceLeavesTheLightSideToTheSystem() {
106 let spec = ThemeSpec.base(light: nil, dark: "nord").0
107 for key in ThemeSpec.systemDefaults {
108 #expect(spec.color(key, dark: false) == nil, "\(key)")
109 #expect(spec.color(key, dark: true) != nil, "\(key)")
110 }
111 }
104112}
ios/Orgstar/Assets.xcassets/AppIcon-Outline.appiconset/AppIcon-dark.png

Binary file not shown.

ios/Orgstar/Assets.xcassets/AppIcon-Paper.appiconset/AppIcon-dark.png

Binary file not shown.

ios/Orgstar/Assets.xcassets/IconPreview-outline.imageset/dark.png

Binary file not shown.

ios/Orgstar/Assets.xcassets/IconPreview-paper.imageset/dark.png

Binary file not shown.

packaging/IconPreviews/default-dark.png

Binary file not shown.

packaging/IconPreviews/forest-dark.png

Binary file not shown.

packaging/IconPreviews/midnight-dark.png

Binary file not shown.

packaging/IconPreviews/mono-dark.png

Binary file not shown.

packaging/IconPreviews/org-dark.png

Binary file not shown.

packaging/IconPreviews/outline-dark.png

Binary file not shown.

packaging/IconPreviews/paper-dark.png

Binary file not shown.

packaging/IconPreviews/rainbow-dark.png

Binary file not shown.

packaging/IconPreviews/sunset-dark.png

Binary file not shown.

packaging/IconPreviews/terminal-dark.png

Binary file not shown.

packaging/IconPreviews/unicorn-dark.png

Binary file not shown.

packaging/IconPreviews/unicorn-night-dark.png

Binary file not shown.

packaging/IconPreviews/unicorn-pastel-dark.png

Binary file not shown.

scripts/make-icon.swift +13 −4
@@ -35,7 +35,9 @@ let variants: [Variant] = [
3535 Variant(id: "unicorn-pastel", top: rgb(0xffc6dd), bottom: rgb(0xc7b8ff), glyph: rgb(0xffc74d), bars: .white, style: .unicorn),
3636]
3737
38enum Look { case light, dark, tinted }
38/// `darkTile`: the dark look on a near-black tile, for the Mac's Dock, which draws nothing
39/// behind an icon set with `NSApp.applicationIconImage`.
40enum Look { case light, dark, darkTile, tinted }
3941
4042/// The macOS icon grid: an 824-point rounded square in a 1024 canvas; `fullBleed` fills the
4143/// canvas, as iOS wants. Dark and tinted leave the background clear (dark) or black (tinted)
@@ -67,10 +69,17 @@ func draw(_ v: Variant, _ size: CGFloat, look: Look = .light, fullBleed: Bool =
6769 NSGraphicsContext.restoreGraphicsState()
6870 case .light: NSGradient(colors: [v.top, v.bottom])!.draw(in: shape, angle: -60)
6971 case .dark: break
72 case .darkTile: NSColor(srgbRed: 0.11, green: 0.11, blue: 0.12, alpha: 1).setFill(); shape.fill()
7073 case .tinted: NSColor.black.setFill(); shape.fill()
7174 }
72 let glyph = look == .tinted ? NSColor(white: 0.95, alpha: 1) : v.glyph
73 let bars = look == .tinted ? NSColor(white: 0.75, alpha: 1) : v.bars
75 // On a dark background a dark glyph (Paper, Outline) is drawn light.
76 func lifted(_ color: NSColor, _ light: CGFloat) -> NSColor {
77 guard look == .dark || look == .darkTile, let c = color.usingColorSpace(.sRGB),
78 0.2126 * c.redComponent + 0.7152 * c.greenComponent + 0.0722 * c.blueComponent < 0.4 else { return color }
79 return NSColor(white: light, alpha: 1)
80 }
81 let glyph = look == .tinted ? NSColor(white: 0.95, alpha: 1) : lifted(v.glyph, 0.95)
82 let bars = look == .tinted ? NSColor(white: 0.75, alpha: 1) : lifted(v.bars, 0.8)
7483 switch v.style {
7584 case .filled: drawOutline(s, glyph: glyph, bars: bars, filled: true)
7685 case .outline: drawOutline(s, glyph: glyph, bars: bars, filled: false)
@@ -193,7 +202,7 @@ for v in variants {
193202
194203 // The Mac's Dock icons and picker previews.
195204 try write(png(draw(v, 512)), "packaging/IconPreviews/\(v.id)-light.png")
196 try write(png(draw(v, 512, look: .dark)), "packaging/IconPreviews/\(v.id)-dark.png")
205 try write(png(draw(v, 512, look: .darkTile)), "packaging/IconPreviews/\(v.id)-dark.png")
197206}
198207
199208// The Mac's bundle icon: the default variant at the Mac's sizes. actool drops dark and