28 lines
936 B
Swift
28 lines
936 B
Swift
import AppKit
|
|
|
|
@MainActor
|
|
final class AppDelegate: NSObject, NSApplicationDelegate {
|
|
private var appearanceObservation: NSKeyValueObservation?
|
|
|
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
|
appearanceObservation = NSApp.observe(
|
|
\.effectiveAppearance,
|
|
options: [.initial, .new]
|
|
) { [weak self] _, _ in
|
|
Task { @MainActor in
|
|
self?.applyIconForCurrentAppearance()
|
|
}
|
|
}
|
|
}
|
|
|
|
private func applyIconForCurrentAppearance() {
|
|
let match = NSApp.effectiveAppearance.bestMatch(from: [.darkAqua, .aqua])
|
|
let resourceName = match == .darkAqua ? "DataTestIcon-Dark" : "DataTestIcon"
|
|
guard let url = Bundle.main.url(forResource: resourceName, withExtension: "icns"),
|
|
let image = NSImage(contentsOf: url) else {
|
|
return
|
|
}
|
|
NSApp.applicationIconImage = image
|
|
}
|
|
}
|