fix: menubar icon not showing on macos 10.13 (closes #507)
This commit is contained in:
1 parent
76dbdf03fe
commit
2fa0b8ac52
12 files changed
+33
-30
No files matched your search
@@ -97,18 +97,6 @@ extension NSControl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension NSImage {
|
|
||||||
// copy and resize an image using high quality interpolation
|
|
||||||
func resizedCopy(_ width: CGFloat, _ height: CGFloat) -> NSImage {
|
|
||||||
let img = NSImage(size: CGSize(width: width, height: height))
|
|
||||||
img.lockFocus()
|
|
||||||
NSGraphicsContext.current?.imageInterpolation = .high
|
|
||||||
draw(in: NSMakeRect(0, 0, width, height), from: NSMakeRect(0, 0, size.width, size.height), operation: .copy, fraction: 1)
|
|
||||||
img.unlockFocus()
|
|
||||||
return img
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// only assign if different; useful for performance
|
// only assign if different; useful for performance
|
||||||
func assignIfDifferent<T: Equatable>(_ a: UnsafeMutablePointer<T>, _ b: T) {
|
func assignIfDifferent<T: Equatable>(_ a: UnsafeMutablePointer<T>, _ b: T) {
|
||||||
if a.pointee != b {
|
if a.pointee != b {
|
||||||
@@ -149,9 +137,25 @@ extension NSViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension NSImage {
|
extension NSImage {
|
||||||
static func initTemplate(_ name: String) -> NSImage {
|
// NSImage(named) caches/reuses NSImage objects; we force separate instances of images by using copy()
|
||||||
let image = NSImage(named: name)!
|
static func initCopy(_ name: String) -> NSImage {
|
||||||
|
return NSImage(named: name)!.copy() as! NSImage
|
||||||
|
}
|
||||||
|
|
||||||
|
static func initTemplateCopy(_ name: String) -> NSImage {
|
||||||
|
let image = initCopy(name)
|
||||||
image.isTemplate = true
|
image.isTemplate = true
|
||||||
return image
|
return image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// copy and resize an image using high quality interpolation
|
||||||
|
static func initResizedCopy(_ name: String, _ width: CGFloat, _ height: CGFloat) -> NSImage {
|
||||||
|
let original = initCopy(name)
|
||||||
|
let img = NSImage(size: CGSize(width: width, height: height))
|
||||||
|
img.lockFocus()
|
||||||
|
NSGraphicsContext.current?.imageInterpolation = .high
|
||||||
|
original.draw(in: NSMakeRect(0, 0, width, height), from: NSMakeRect(0, 0, original.size.width, original.size.height), operation: .copy, fraction: 1)
|
||||||
|
img.unlockFocus()
|
||||||
|
return img
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ class FeedbackWindow: NSWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func setupView() {
|
private func setupView() {
|
||||||
let appIcon = NSImageView(image: NSImage(named: "app-icon")!.resizedCopy(80, 80))
|
let appIcon = NSImageView(image: NSImage.initResizedCopy("app-icon", 80, 80))
|
||||||
appIcon.imageScaling = .scaleNone
|
appIcon.imageScaling = .scaleNone
|
||||||
let appText = StackView([
|
let appText = StackView([
|
||||||
BoldLabel(NSLocalizedString("Share improvement ideas, or report bugs", comment: "")),
|
BoldLabel(NSLocalizedString("Share improvement ideas, or report bugs", comment: "")),
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ class Menubar {
|
|||||||
static var statusItem: NSStatusItem!
|
static var statusItem: NSStatusItem!
|
||||||
|
|
||||||
static func initialize() {
|
static func initialize() {
|
||||||
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
|
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
|
||||||
statusItem.button!.imageScaling = .scaleProportionallyUpOrDown
|
|
||||||
statusItem.menu = NSMenu()
|
statusItem.menu = NSMenu()
|
||||||
statusItem.menu!.addItem(
|
statusItem.menu!.addItem(
|
||||||
withTitle: NSLocalizedString("Show", comment: "Menubar option"),
|
withTitle: NSLocalizedString("Show", comment: "Menubar option"),
|
||||||
@@ -43,9 +42,9 @@ class Menubar {
|
|||||||
let i = imageIndexFromPreference()
|
let i = imageIndexFromPreference()
|
||||||
let image = NSImage(named: "menubar-icon-" + i)!
|
let image = NSImage(named: "menubar-icon-" + i)!
|
||||||
image.isTemplate = i == "3" ? false : true
|
image.isTemplate = i == "3" ? false : true
|
||||||
statusItem.button!.appearance = i == "3" ? NSAppearance(named: .aqua) : nil
|
|
||||||
statusItem.button!.image = image
|
statusItem.button!.image = image
|
||||||
statusItem.isVisible = true
|
statusItem.isVisible = true
|
||||||
|
statusItem.button!.imageScaling = .scaleProportionallyUpOrDown
|
||||||
}
|
}
|
||||||
|
|
||||||
static private func imageIndexFromPreference() -> String {
|
static private func imageIndexFromPreference() -> String {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class PermissionView: StackView {
|
|||||||
var isPermissionGranted = false
|
var isPermissionGranted = false
|
||||||
|
|
||||||
convenience init(_ iconName: String, _ title: String, _ justification: String, _ buttonText: String, _ buttonUrl: String, _ checkFunction: @escaping () -> Bool) {
|
convenience init(_ iconName: String, _ title: String, _ justification: String, _ buttonText: String, _ buttonUrl: String, _ checkFunction: @escaping () -> Bool) {
|
||||||
let icon = NSImageView(image: NSImage(named: iconName)!)
|
let icon = NSImageView(image: NSImage.initCopy(iconName))
|
||||||
icon.translatesAutoresizingMaskIntoConstraints = false
|
icon.translatesAutoresizingMaskIntoConstraints = false
|
||||||
icon.fit()
|
icon.fit()
|
||||||
let title = BoldLabel(title)
|
let title = BoldLabel(title)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class PermissionsWindow: NSWindow, NSWindowDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func setupView() {
|
private func setupView() {
|
||||||
let appIcon = NSImageView(image: NSImage(named: "app-icon")!.resizedCopy(80, 80))
|
let appIcon = NSImageView(image: NSImage.initResizedCopy("app-icon", 80, 80))
|
||||||
appIcon.imageScaling = .scaleNone
|
appIcon.imageScaling = .scaleNone
|
||||||
let appText = TitleLabel(NSLocalizedString("AltTab needs some permissions", comment: ""))
|
let appText = TitleLabel(NSLocalizedString("AltTab needs some permissions", comment: ""))
|
||||||
appText.preferredMaxLayoutWidth = 380
|
appText.preferredMaxLayoutWidth = 380
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import Preferences
|
|||||||
class AboutTab: NSViewController, PreferencePane {
|
class AboutTab: NSViewController, PreferencePane {
|
||||||
let preferencePaneIdentifier = PreferencePane.Identifier("About")
|
let preferencePaneIdentifier = PreferencePane.Identifier("About")
|
||||||
let preferencePaneTitle = NSLocalizedString("About", comment: "")
|
let preferencePaneTitle = NSLocalizedString("About", comment: "")
|
||||||
let toolbarItemIcon = NSImage.initTemplate("about")
|
let toolbarItemIcon = NSImage.initTemplateCopy("about")
|
||||||
|
|
||||||
override func loadView() {
|
override func loadView() {
|
||||||
let appIcon = NSImageView(image: NSImage(named: "app-icon")!.resizedCopy(256, 256))
|
let appIcon = NSImageView(image: NSImage.initResizedCopy("app-icon", 256, 256))
|
||||||
appIcon.imageScaling = .scaleNone
|
appIcon.imageScaling = .scaleNone
|
||||||
let appText = StackView([
|
let appText = StackView([
|
||||||
BoldLabel(App.name),
|
BoldLabel(App.name),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class AcknowledgmentsTab: NSViewController, PreferencePane {
|
|||||||
static let maxTabHeight = CGFloat(450)
|
static let maxTabHeight = CGFloat(450)
|
||||||
let preferencePaneIdentifier = PreferencePane.Identifier("Acknowledgments")
|
let preferencePaneIdentifier = PreferencePane.Identifier("Acknowledgments")
|
||||||
let preferencePaneTitle = NSLocalizedString("Acknowledgments", comment: "")
|
let preferencePaneTitle = NSLocalizedString("Acknowledgments", comment: "")
|
||||||
let toolbarItemIcon = NSImage.initTemplate("acknowledgments")
|
let toolbarItemIcon = NSImage.initTemplateCopy("acknowledgments")
|
||||||
|
|
||||||
override func loadView() {
|
override func loadView() {
|
||||||
let textViews: [TextField] = ["Contributors", "Acknowledgments"].map {
|
let textViews: [TextField] = ["Contributors", "Acknowledgments"].map {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import Preferences
|
|||||||
class AppearanceTab: NSViewController, PreferencePane {
|
class AppearanceTab: NSViewController, PreferencePane {
|
||||||
let preferencePaneIdentifier = PreferencePane.Identifier("Appearance")
|
let preferencePaneIdentifier = PreferencePane.Identifier("Appearance")
|
||||||
let preferencePaneTitle = NSLocalizedString("Appearance", comment: "")
|
let preferencePaneTitle = NSLocalizedString("Appearance", comment: "")
|
||||||
let toolbarItemIcon = NSImage.initTemplate("appearance")
|
let toolbarItemIcon = NSImage.initTemplateCopy("appearance")
|
||||||
|
|
||||||
override func loadView() {
|
override func loadView() {
|
||||||
let grid = GridView([
|
let grid = GridView([
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import Preferences
|
|||||||
class BlacklistsTab: NSViewController, PreferencePane {
|
class BlacklistsTab: NSViewController, PreferencePane {
|
||||||
let preferencePaneIdentifier = PreferencePane.Identifier("Blacklists")
|
let preferencePaneIdentifier = PreferencePane.Identifier("Blacklists")
|
||||||
let preferencePaneTitle = NSLocalizedString("Blacklists", comment: "")
|
let preferencePaneTitle = NSLocalizedString("Blacklists", comment: "")
|
||||||
let toolbarItemIcon = NSImage.initTemplate("blacklists")
|
let toolbarItemIcon = NSImage.initTemplateCopy("blacklists")
|
||||||
|
|
||||||
override func loadView() {
|
override func loadView() {
|
||||||
let dontShowBlacklistLabel = NSTextField(labelWithString: NSLocalizedString("Don’t show windows from these apps", comment: ""))
|
let dontShowBlacklistLabel = NSTextField(labelWithString: NSLocalizedString("Don’t show windows from these apps", comment: ""))
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import Preferences
|
|||||||
class ControlsTab: NSViewController, PreferencePane {
|
class ControlsTab: NSViewController, PreferencePane {
|
||||||
let preferencePaneIdentifier = PreferencePane.Identifier("Controls")
|
let preferencePaneIdentifier = PreferencePane.Identifier("Controls")
|
||||||
let preferencePaneTitle = NSLocalizedString("Controls", comment: "")
|
let preferencePaneTitle = NSLocalizedString("Controls", comment: "")
|
||||||
let toolbarItemIcon = NSImage.initTemplate("controls")
|
let toolbarItemIcon = NSImage.initTemplateCopy("controls")
|
||||||
|
|
||||||
static var nextWindowShortcut: [NSControl]!
|
static var nextWindowShortcut: [NSControl]!
|
||||||
static var shortcuts = [String: Shortcut]()
|
static var shortcuts = [String: Shortcut]()
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ import Preferences
|
|||||||
class GeneralTab: NSViewController, PreferencePane {
|
class GeneralTab: NSViewController, PreferencePane {
|
||||||
let preferencePaneIdentifier = PreferencePane.Identifier("General")
|
let preferencePaneIdentifier = PreferencePane.Identifier("General")
|
||||||
let preferencePaneTitle = NSLocalizedString("General", comment: "")
|
let preferencePaneTitle = NSLocalizedString("General", comment: "")
|
||||||
let toolbarItemIcon = NSImage.initTemplate("general")
|
let toolbarItemIcon = NSImage.initTemplateCopy("general")
|
||||||
|
|
||||||
override func loadView() {
|
override func loadView() {
|
||||||
let startAtLogin = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Start at login:", comment: ""), "startAtLogin", extraAction: startAtLoginCallback)
|
let startAtLogin = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Start at login:", comment: ""), "startAtLogin", extraAction: startAtLoginCallback)
|
||||||
let menubarIcon = LabelAndControl.makeLabelWithDropdown(NSLocalizedString("Menubar icon:", comment: ""), "menubarIcon", MenubarIconPreference.allCases, extraAction: Menubar.menubarIconCallback)
|
let menubarIcon = LabelAndControl.makeLabelWithDropdown(NSLocalizedString("Menubar icon:", comment: ""), "menubarIcon", MenubarIconPreference.allCases, extraAction: Menubar.menubarIconCallback)
|
||||||
let menubarIconDropdown = menubarIcon[1] as! NSPopUpButton
|
let menubarIconDropdown = menubarIcon[1] as! NSPopUpButton
|
||||||
for i in 0...2 {
|
for i in 0...2 {
|
||||||
let image = NSImage(named: "menubar-icon-" + String(i + 1))!
|
let image = NSImage.initCopy("menubar-icon-" + String(i + 1))
|
||||||
image.isTemplate = i == 2 ? false : true
|
image.isTemplate = false
|
||||||
menubarIconDropdown.item(at: i)!.image = image
|
menubarIconDropdown.item(at: i)!.image = image
|
||||||
}
|
}
|
||||||
menubarIconDropdown.item(at: 3)!.image = NSImage(size: NSSize(width: 1, height: menubarIconDropdown.item(at: 0)!.image!.size.height))
|
menubarIconDropdown.item(at: 3)!.image = NSImage(size: NSSize(width: 1, height: menubarIconDropdown.item(at: 0)!.image!.size.height))
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import Preferences
|
|||||||
class PoliciesTab: NSViewController, PreferencePane {
|
class PoliciesTab: NSViewController, PreferencePane {
|
||||||
let preferencePaneIdentifier = PreferencePane.Identifier("Policies")
|
let preferencePaneIdentifier = PreferencePane.Identifier("Policies")
|
||||||
let preferencePaneTitle = NSLocalizedString("Policies", comment: "")
|
let preferencePaneTitle = NSLocalizedString("Policies", comment: "")
|
||||||
let toolbarItemIcon = NSImage.initTemplate("policies")
|
let toolbarItemIcon = NSImage.initTemplateCopy("policies")
|
||||||
|
|
||||||
static var updateButtons: [NSButton]!
|
static var updateButtons: [NSButton]!
|
||||||
static var crashButtons: [NSButton]!
|
static var crashButtons: [NSButton]!
|
||||||
|
|||||||
Reference in new issue
Block a user