From 79ceb21b0c2b0364b95a5aca30c09bde7b9a4454 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Sun, 7 Apr 2024 18:45:07 -0400 Subject: [PATCH] Make things look good on older OSes for status item's button. --- Clocker/Overall App/VersionUpdateHandler.swift | 12 ++++++------ Clocker/Preferences/Menu Bar/StatusItemHandler.swift | 11 +++++++++++ Clocker/Preferences/Menu Bar/StatusItemView.swift | 7 ++++++- .../Menu Bar/UpcomingEventStatusItemView.swift | 7 ++++++- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Clocker/Overall App/VersionUpdateHandler.swift b/Clocker/Overall App/VersionUpdateHandler.swift index 8b6b90a..654aede 100644 --- a/Clocker/Overall App/VersionUpdateHandler.swift +++ b/Clocker/Overall App/VersionUpdateHandler.swift @@ -229,7 +229,7 @@ class VersionUpdateHandler: NSObject { } dataTask = NetworkManager.task(with: itunesServiceURL) { [weak self] response, error in - guard let self, let data = response else {return } + guard let self = self, let data = response else {return } if (error != nil || response == nil) { Logger.info("Response is nil or error is non-nil") @@ -258,7 +258,7 @@ class VersionUpdateHandler: NSObject { } newerVersionAvailable = latestVersion?.compareVersion(self.applicationVersion) == .orderedDescending - if (verboseLogging) { + if (self.verboseLogging) { if (newerVersionAvailable) { Logger.info("iVersion found a new version \(latestVersion ?? "N/A") of the app on iTunes. Current version is \(self.applicationVersion ?? "nil")") } else { @@ -266,7 +266,7 @@ class VersionUpdateHandler: NSObject { } } } else { - if (verboseLogging) { + if (self.verboseLogging) { Logger.info("iVersion found that the application bundle ID \(self.applicationBundleID) does not match the bundle ID of the app found on iTunes \(bundleID) with the specified App Store ID") } } @@ -276,13 +276,13 @@ class VersionUpdateHandler: NSObject { //TODO: Set download error Logger.info("Versions downloaded \(versions ?? [:])") - performSelector(onMainThread: #selector(setRemoteVersionsDict(_:)), + self.performSelector(onMainThread: #selector(VersionUpdateHandler.setRemoteVersionsDict(_:)), with: versions, waitUntilDone: true) - performSelector(onMainThread: #selector(setLastChecked(_:)), + self.performSelector(onMainThread: #selector(VersionUpdateHandler.setLastChecked(_:)), with: Date(), waitUntilDone: true) - performSelector(onMainThread: #selector(Self.downloadVersionsData), + self.performSelector(onMainThread: #selector(Self.downloadVersionsData), with: nil, waitUntilDone: true) } diff --git a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift index f403d6d..7d97c2c 100644 --- a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift +++ b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift @@ -154,6 +154,17 @@ class StatusItemHandler: NSObject { statusContainerView?.wantsLayer = true statusItem.button?.addSubview(statusContainerView!) statusItem.button?.frame = statusContainerView!.bounds + + // For OS < 11, we need to fix the sizing (width) on the button's window + // Otherwise, we won't be able to see the menu bar option at all. + if let window = statusItem.button?.window { + let currentFrame = window.frame + let newFrame = NSRect(x: currentFrame.origin.x, + y: currentFrame.origin.y, + width: statusItem.button?.bounds.size.width ?? 0, + height: currentFrame.size.height) + window.setFrame(newFrame, display: true) + } statusItem.button?.subviews.first?.window?.backgroundColor = NSColor.clear } diff --git a/Clocker/Preferences/Menu Bar/StatusItemView.swift b/Clocker/Preferences/Menu Bar/StatusItemView.swift index 2723a62..87fc168 100644 --- a/Clocker/Preferences/Menu Bar/StatusItemView.swift +++ b/Clocker/Preferences/Menu Bar/StatusItemView.swift @@ -107,11 +107,16 @@ class StatusItemView: NSView { } timeView.disableWrapping() + + var topAnchorConstant: CGFloat = 7.0 + if #available(macOS 11.0, *) { + topAnchorConstant = 0.0 + } NSLayoutConstraint.activate([ locationView.leadingAnchor.constraint(equalTo: leadingAnchor), locationView.trailingAnchor.constraint(equalTo: trailingAnchor), - locationView.topAnchor.constraint(equalTo: topAnchor, constant: 0), + locationView.topAnchor.constraint(equalTo: topAnchor, constant: topAnchorConstant), locationView.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 0.35), ]) diff --git a/Clocker/Preferences/Menu Bar/UpcomingEventStatusItemView.swift b/Clocker/Preferences/Menu Bar/UpcomingEventStatusItemView.swift index 1858145..f4495d5 100644 --- a/Clocker/Preferences/Menu Bar/UpcomingEventStatusItemView.swift +++ b/Clocker/Preferences/Menu Bar/UpcomingEventStatusItemView.swift @@ -49,11 +49,16 @@ class UpcomingEventStatusItemView: NSView { } etaField.disableWrapping() + + var topAnchorConstant: CGFloat = 7 + if #available(macOS 11.0, *) { + topAnchorConstant = 0 + } NSLayoutConstraint.activate([ nextEventField.leadingAnchor.constraint(equalTo: leadingAnchor), nextEventField.trailingAnchor.constraint(equalTo: trailingAnchor), - nextEventField.topAnchor.constraint(equalTo: topAnchor, constant: 0), + nextEventField.topAnchor.constraint(equalTo: topAnchor, constant: topAnchorConstant), nextEventField.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 0.35), ])