Commit f97aeb320e
Verified · cmc
Layout: unified · split
Sources/OrgApp/AgendaSnapshot.swift +7 −1
| @@ -145,7 +145,13 @@ public struct AgendaSnapshot: Codable, Equatable, Sendable { | ||
| 145 | 145 | } |
| 146 | 146 | var colors: [String: Hex] = [:] |
| 147 | 147 | 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 | } | |
| 149 | 155 | } |
| 150 | 156 | self.colors = colors |
| 151 | 157 | self.generated = generated |
Sources/OrgApp/ConfigSync.swift +2
| @@ -144,6 +144,8 @@ public final class ConfigSync { | ||
| 144 | 144 | guard current != original else { return } |
| 145 | 145 | text = current |
| 146 | 146 | 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() | |
| 147 | 149 | } |
| 148 | 150 | } |
| 149 | 151 | #endif |
Sources/Orgstar/BacklinksPane.swift +2 −1
| @@ -13,6 +13,7 @@ struct BacklinksPane: View { | ||
| 13 | 13 | @State private var toHeading: [HeadingLocation] = [] |
| 14 | 14 | @State private var toFile: [HeadingLocation] = [] |
| 15 | 15 | @Environment(\.orgTheme) private var theme |
| 16 | @Environment(\.colorScheme) private var colorScheme | |
| 16 | 17 | |
| 17 | 18 | /// The heading at the caret. |
| 18 | 19 | private var heading: OutlineEntry? { session.outline.last { $0.start <= commands.selection.location } } |
| @@ -30,7 +31,7 @@ struct BacklinksPane: View { | ||
| 30 | 31 | } |
| 31 | 32 | Section("Links to this file") { rows(toFile) } |
| 32 | 33 | } |
| 33 | .themedListBackground(theme.color("sidebar-background")) | |
| 34 | .themedListBackground(theme.color("sidebar-background", in: colorScheme)) | |
| 34 | 35 | .task(id: Key(path: session.path, heading: heading?.start, version: session.editVersion)) { refresh() } |
| 35 | 36 | } |
| 36 | 37 | |
Sources/Orgstar/BoardView.swift +2 −1
| @@ -24,6 +24,7 @@ struct BoardView: View { | ||
| 24 | 24 | @AppStorage("agendaSubfolders") private var includeSubfolders = false |
| 25 | 25 | @Environment(\.openWindow) private var openWindow |
| 26 | 26 | @Environment(\.orgTheme) private var theme |
| 27 | @Environment(\.colorScheme) private var colorScheme | |
| 27 | 28 | |
| 28 | 29 | init(workspace: WorkspaceModel, session: DocumentSession, commands: AppCommands) { |
| 29 | 30 | self.workspace = workspace |
| @@ -137,7 +138,7 @@ struct BoardView: View { | ||
| 137 | 138 | } |
| 138 | 139 | .padding(12) |
| 139 | 140 | } |
| 140 | .background(theme.color("agenda-background") ?? .clear) | |
| 141 | .background(theme.color("agenda-background", in: colorScheme) ?? .clear) | |
| 141 | 142 | } |
| 142 | 143 | |
| 143 | 144 | private func column(_ keyword: String) -> some View { |
Sources/Orgstar/BufferTabs.swift +2 −1
| @@ -33,6 +33,7 @@ struct BufferTabs: View { | ||
| 33 | 33 | let pane: EditorPane |
| 34 | 34 | let close: (String) -> Void |
| 35 | 35 | @Environment(\.orgTheme) private var theme |
| 36 | @Environment(\.colorScheme) private var colorScheme | |
| 36 | 37 | |
| 37 | 38 | var body: some View { |
| 38 | 39 | ScrollView(.horizontal, showsIndicators: false) { |
| @@ -43,7 +44,7 @@ struct BufferTabs: View { | ||
| 43 | 44 | } |
| 44 | 45 | } |
| 45 | 46 | .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)) } | |
| 47 | 48 | .overlay(alignment: .bottom) { Divider() } |
| 48 | 49 | } |
| 49 | 50 | |
Sources/Orgstar/Keys.swift +2 −1
| @@ -14,6 +14,7 @@ struct KeyHint: Hashable { | ||
| 14 | 14 | struct EchoArea: View { |
| 15 | 15 | let commands: AppCommands |
| 16 | 16 | @Environment(\.orgTheme) private var theme |
| 17 | @Environment(\.colorScheme) private var colorScheme | |
| 17 | 18 | @State private var showingHints = false |
| 18 | 19 | @State private var answer = "" |
| 19 | 20 | @FocusState private var answerFocused: Bool |
| @@ -107,7 +108,7 @@ struct EchoArea: View { | ||
| 107 | 108 | } |
| 108 | 109 | } |
| 109 | 110 | .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) } } | |
| 111 | 112 | .task(id: commands.pendingKeys) { |
| 112 | 113 | showingHints = false |
| 113 | 114 | guard commands.pendingKeys != nil else { return } |
Sources/Orgstar/ModeLine.swift +2 −1
| @@ -13,6 +13,7 @@ struct ModeLine: View { | ||
| 13 | 13 | /// Runs an app command (clock out, go to the clocked entry). |
| 14 | 14 | let perform: (String) -> Void |
| 15 | 15 | @Environment(\.orgTheme) private var theme |
| 16 | @Environment(\.colorScheme) private var colorScheme | |
| 16 | 17 | @State private var words: Int? |
| 17 | 18 | @State private var characters = 0 |
| 18 | 19 | @State private var crlf = false |
| @@ -99,7 +100,7 @@ struct ModeLine: View { | ||
| 99 | 100 | .foregroundStyle(theme.color("modeline-foreground") ?? .secondary) |
| 100 | 101 | .padding(.horizontal, 10) |
| 101 | 102 | .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) } } | |
| 103 | 104 | .overlay(alignment: .top) { Divider() } |
| 104 | 105 | .task(id: session.path) { |
| 105 | 106 | // HEAD changes outside the app, so look again every few seconds. |
Sources/Orgstar/Sidebar.swift +4 −2
| @@ -14,6 +14,7 @@ struct Sidebar: View { | ||
| 14 | 14 | @State private var removing: String? |
| 15 | 15 | /// A file operation waiting for a name or a confirmation. |
| 16 | 16 | @Environment(\.orgTheme) private var theme |
| 17 | @Environment(\.colorScheme) private var colorScheme | |
| 17 | 18 | @State var pending: FileOperation? |
| 18 | 19 | @State var name = "" |
| 19 | 20 | @State var failure: String? |
| @@ -50,7 +51,7 @@ struct Sidebar: View { | ||
| 50 | 51 | } |
| 51 | 52 | } |
| 52 | 53 | .listStyle(.sidebar) |
| 53 | .themedListBackground(theme.color("sidebar-background")) | |
| 54 | .themedListBackground(theme.color("sidebar-background", in: colorScheme)) | |
| 54 | 55 | .safeAreaInset(edge: .bottom, spacing: 0) { |
| 55 | 56 | HStack(spacing: 4) { |
| 56 | 57 | Button("Add Folder…", systemImage: "plus", action: addFolder) |
| @@ -120,6 +121,7 @@ struct Sidebar: View { | ||
| 120 | 121 | struct OutlineColumn: View { |
| 121 | 122 | let session: DocumentSession |
| 122 | 123 | @Environment(\.orgTheme) private var theme |
| 124 | @Environment(\.colorScheme) private var colorScheme | |
| 123 | 125 | |
| 124 | 126 | var body: some View { |
| 125 | 127 | List(Array(session.outline.enumerated()), id: \.element.start) { _, entry in |
| @@ -133,7 +135,7 @@ struct OutlineColumn: View { | ||
| 133 | 135 | } |
| 134 | 136 | .buttonStyle(.plain) |
| 135 | 137 | } |
| 136 | .themedListBackground(theme.color("sidebar-background")) | |
| 138 | .themedListBackground(theme.color("sidebar-background", in: colorScheme)) | |
| 137 | 139 | .overlay { |
| 138 | 140 | if session.path != nil, !session.isOrg { |
| 139 | 141 | 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 { | ||
| 21 | 21 | }) |
| 22 | 22 | } |
| 23 | 23 | |
| 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 | ||
| 24 | 30 | /// A color that follows the appearance from a helper taking `dark:` (`todoColor`, |
| 25 | 31 | /// `statusColor`, …), or `fallback` where it gives none. |
| 26 | 32 | 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 { | ||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | extension AgendaSnapshot { |
| 54 | /// Nil where the theme leaves `key` to the system in `scheme`. | |
| 54 | 55 | 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) } | |
| 56 | 57 | } |
| 57 | 58 | |
| 58 | 59 | /// A day for the gallery and previews. |
Tests/OrgAppTests/AgendaSnapshotTests.swift +7
| @@ -78,6 +78,13 @@ struct AgendaSnapshotTests { | ||
| 78 | 78 | #expect(snapshot.colors["agenda-background"] == nil) |
| 79 | 79 | } |
| 80 | 80 | |
| 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 | ||
| 81 | 88 | @Test func encodesAndDecodes() throws { |
| 82 | 89 | let snapshot = Self.snapshot() |
| 83 | 90 | let data = try AgendaSnapshot.encoder.encode(snapshot) |
Tests/OrgAppTests/UserConfigTests.swift +16
| @@ -294,4 +294,20 @@ struct ThemeReadingTests { | ||
| 294 | 294 | #expect(try !UserConfig.copyTheme(light: light, dark: dark, to: folder)) |
| 295 | 295 | #expect(try String(contentsOf: file, encoding: .utf8) == "mine") |
| 296 | 296 | } |
| 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 | } | |
| 297 | 313 | } |
Tests/OrgPresentationTests/PaletteTests.swift +8
| @@ -101,4 +101,12 @@ struct PaletteTests { | ||
| 101 | 101 | #expect(AppIcons.dockFile("unicorn", dark: false) == "unicorn-light") |
| 102 | 102 | #expect(AppIcons.dockFile("unicorn", dark: true) == "unicorn-dark") |
| 103 | 103 | } |
| 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 | } | |
| 104 | 112 | } |
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] = [ | ||
| 35 | 35 | Variant(id: "unicorn-pastel", top: rgb(0xffc6dd), bottom: rgb(0xc7b8ff), glyph: rgb(0xffc74d), bars: .white, style: .unicorn), |
| 36 | 36 | ] |
| 37 | 37 | |
| 38 | enum 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`. | |
| 40 | enum Look { case light, dark, darkTile, tinted } | |
| 39 | 41 | |
| 40 | 42 | /// The macOS icon grid: an 824-point rounded square in a 1024 canvas; `fullBleed` fills the |
| 41 | 43 | /// 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 = | ||
| 67 | 69 | NSGraphicsContext.restoreGraphicsState() |
| 68 | 70 | case .light: NSGradient(colors: [v.top, v.bottom])!.draw(in: shape, angle: -60) |
| 69 | 71 | case .dark: break |
| 72 | case .darkTile: NSColor(srgbRed: 0.11, green: 0.11, blue: 0.12, alpha: 1).setFill(); shape.fill() | |
| 70 | 73 | case .tinted: NSColor.black.setFill(); shape.fill() |
| 71 | 74 | } |
| 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) | |
| 74 | 83 | switch v.style { |
| 75 | 84 | case .filled: drawOutline(s, glyph: glyph, bars: bars, filled: true) |
| 76 | 85 | case .outline: drawOutline(s, glyph: glyph, bars: bars, filled: false) |
| @@ -193,7 +202,7 @@ for v in variants { | ||
| 193 | 202 | |
| 194 | 203 | // The Mac's Dock icons and picker previews. |
| 195 | 204 | 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") | |
| 197 | 206 | } |
| 198 | 207 | |
| 199 | 208 | // The Mac's bundle icon: the default variant at the Mac's sizes. actool drops dark and |