|
@@ -15,6 +15,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
|
|
|
private weak var launcherWindowReference: NSWindow?
|
|
private weak var launcherWindowReference: NSWindow?
|
|
|
private var launcherWindowResignObserver: NSObjectProtocol?
|
|
private var launcherWindowResignObserver: NSObjectProtocol?
|
|
|
private var refocusLauncherObserver: NSObjectProtocol?
|
|
private var refocusLauncherObserver: NSObjectProtocol?
|
|
|
|
|
+ private var appearanceChangedObserver: NSObjectProtocol?
|
|
|
|
|
+ private var effectiveAppearanceObservation: NSKeyValueObservation?
|
|
|
private var startupPaywallWindow: NSWindow?
|
|
private var startupPaywallWindow: NSWindow?
|
|
|
private var hasPresentedStartupPaywall = false
|
|
private var hasPresentedStartupPaywall = false
|
|
|
private var premiumUnlockObservation: NSKeyValueObservation?
|
|
private var premiumUnlockObservation: NSKeyValueObservation?
|
|
@@ -197,13 +199,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
|
|
|
statusItem = item
|
|
statusItem = item
|
|
|
|
|
|
|
|
guard let button = item.button else { return }
|
|
guard let button = item.button else { return }
|
|
|
- if let menuBarIcon = NSImage(named: "menu_bar_icon") {
|
|
|
|
|
- button.image = menuBarIcon
|
|
|
|
|
- button.image?.isTemplate = false
|
|
|
|
|
- } else {
|
|
|
|
|
- button.image = NSImage(systemSymbolName: "square.grid.2x2.fill", accessibilityDescription: "My Apps")
|
|
|
|
|
- button.image?.isTemplate = true
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ updateStatusBarIconForCurrentAppearance()
|
|
|
|
|
+ observeAppearanceChanges()
|
|
|
button.imageScaling = .scaleProportionallyDown
|
|
button.imageScaling = .scaleProportionallyDown
|
|
|
button.imagePosition = .imageOnly
|
|
button.imagePosition = .imageOnly
|
|
|
button.action = #selector(statusBarButtonClicked(_:))
|
|
button.action = #selector(statusBarButtonClicked(_:))
|
|
@@ -211,6 +208,43 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
|
|
|
button.sendAction(on: [.leftMouseUp, .rightMouseUp])
|
|
button.sendAction(on: [.leftMouseUp, .rightMouseUp])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private func updateStatusBarIconForCurrentAppearance() {
|
|
|
|
|
+ guard let button = statusItem?.button else { return }
|
|
|
|
|
+
|
|
|
|
|
+ // Use a template image so macOS tints it appropriately (white on dark menu bar,
|
|
|
|
|
+ // black on light menu bar), matching other status bar icons.
|
|
|
|
|
+ if let menuBarIcon = NSImage(named: "menu_bar_dark_icon") ?? NSImage(named: "menu_bar_icon") {
|
|
|
|
|
+ menuBarIcon.isTemplate = true
|
|
|
|
|
+ button.image = menuBarIcon
|
|
|
|
|
+ button.image?.isTemplate = true
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ button.image = NSImage(systemSymbolName: "square.grid.2x2.fill", accessibilityDescription: "My Apps")
|
|
|
|
|
+ button.image?.isTemplate = true
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private func observeAppearanceChanges() {
|
|
|
|
|
+ if let appearanceChangedObserver {
|
|
|
|
|
+ DistributedNotificationCenter.default().removeObserver(appearanceChangedObserver)
|
|
|
|
|
+ self.appearanceChangedObserver = nil
|
|
|
|
|
+ }
|
|
|
|
|
+ effectiveAppearanceObservation?.invalidate()
|
|
|
|
|
+ effectiveAppearanceObservation = nil
|
|
|
|
|
+
|
|
|
|
|
+ appearanceChangedObserver = DistributedNotificationCenter.default().addObserver(
|
|
|
|
|
+ forName: NSNotification.Name("AppleInterfaceThemeChangedNotification"),
|
|
|
|
|
+ object: nil,
|
|
|
|
|
+ queue: .main
|
|
|
|
|
+ ) { [weak self] _ in
|
|
|
|
|
+ self?.updateStatusBarIconForCurrentAppearance()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ effectiveAppearanceObservation = NSApp.observe(\.effectiveAppearance, options: [.new]) { [weak self] _, _ in
|
|
|
|
|
+ self?.updateStatusBarIconForCurrentAppearance()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@objc
|
|
@objc
|
|
|
private func statusBarButtonClicked(_ sender: Any?) {
|
|
private func statusBarButtonClicked(_ sender: Any?) {
|
|
|
guard let event = NSApp.currentEvent else {
|
|
guard let event = NSApp.currentEvent else {
|
|
@@ -399,6 +433,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
|
|
|
NotificationCenter.default.removeObserver(observer)
|
|
NotificationCenter.default.removeObserver(observer)
|
|
|
refocusLauncherObserver = nil
|
|
refocusLauncherObserver = nil
|
|
|
}
|
|
}
|
|
|
|
|
+ if let observer = appearanceChangedObserver {
|
|
|
|
|
+ DistributedNotificationCenter.default().removeObserver(observer)
|
|
|
|
|
+ appearanceChangedObserver = nil
|
|
|
|
|
+ }
|
|
|
|
|
+ effectiveAppearanceObservation?.invalidate()
|
|
|
|
|
+ effectiveAppearanceObservation = nil
|
|
|
premiumStateMonitorTask?.cancel()
|
|
premiumStateMonitorTask?.cancel()
|
|
|
premiumStateMonitorTask = nil
|
|
premiumStateMonitorTask = nil
|
|
|
premiumUnlockObservation?.invalidate()
|
|
premiumUnlockObservation?.invalidate()
|