Sources/Orgstar/DockIcon.swift

d88176172f98786bd9a86c2f6ee051fd19fe426d
orgstar/Sources/Orgstar/DockIcon.swift

28 lines · 1013 bytes

 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}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form