Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
1.4 kB · 29 lines
Swift
123456789101112131415161718192021222324252627282930// DockIcon.swift — give the bare SPM executable a real dock identity:// the JukeWizard mascot in a squircle, light/dark renders (bin/gen-icons.sh)// swapped live when the system theme changes. Same as wave/clip-wizard.import AppKit
enum DockIcon { static func install(prefix: String) { apply(prefix: prefix) DistributedNotificationCenter.default().addObserver( forName: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil, queue: .main ) { _ in apply(prefix: prefix) } }
private static func apply(prefix: String) { let dark = NSApp.effectiveAppearance .bestMatch(from: [.aqua, .darkAqua]) == .darkAqua let variant = dark ? "dark" : "light" let bundle = Bundle.module let img = bundle.url(forResource: "\(prefix)-icon-\(variant)", withExtension: "png", subdirectory: "Assets") .flatMap { NSImage(contentsOf: $0) } ?? bundle.url(forResource: "\(prefix)-icon-\(variant)", withExtension: "png") .flatMap { NSImage(contentsOf: $0) } ?? bundle.url(forResource: "\(prefix)-mascot", withExtension: "png", subdirectory: "Assets") .flatMap { NSImage(contentsOf: $0) } if let img { NSApp.applicationIconImage = img } }}