diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index 107a6ae..e3a7137 100644 --- a/Clocker/Preferences/General/PreferencesViewController.swift +++ b/Clocker/Preferences/General/PreferencesViewController.swift @@ -18,6 +18,49 @@ struct PreferencesConstants { static let hotKeyPathIdentifier = "values.globalPing" } +class TableHeaderViewCell: NSTableHeaderCell { + var backgroundColour: NSColor = NSColor.black { + didSet { + backgroundColor = backgroundColour + } + } + + override init(textCell: String) { + super.init(textCell: textCell) + let attributedParagraphStyle = NSMutableParagraphStyle() + attributedParagraphStyle.alignment = .left + attributedStringValue = NSAttributedString(string: textCell, + attributes: [.foregroundColor: Themer.shared().mainTextColor(), + .font: NSFont(name: "Avenir", size: 14)!, + .paragraphStyle: attributedParagraphStyle]) + backgroundColor = Themer.shared().textBackgroundColor() + } + + required init(coder _: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func draw(withFrame cellFrame: NSRect, in controlView: NSView) { + super.draw(withFrame: cellFrame, in: controlView) + if !controlView.isHidden { + backgroundColor?.setFill() + cellFrame.fill() + drawInterior(withFrame: cellFrame, in: controlView) + } + } + + override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) { + if !controlView.isHidden { + if let avenirFont = NSFont(name: "Avenir", size: 14) { + font = avenirFont + } + textColor = NSColor.white + let rect = titleRect(forBounds: cellFrame) + attributedStringValue.draw(in: rect) + } + } +} + class PreferencesViewController: ParentViewController { private var isActivityInProgress = false { didSet { diff --git a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift index 3cfa35c..225e40f 100644 --- a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift +++ b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift @@ -339,6 +339,7 @@ class StatusItemHandler: NSObject { statusItem.button?.title = CLEmptyString statusItem.button?.image = NSImage(named: .menubarIcon) statusItem.button?.imagePosition = .imageOnly + statusItem.toolTip = "Clocker" } private func setupForStandardText() { @@ -412,13 +413,16 @@ class StatusItemHandler: NSObject { time.invalidate() } - timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: false) { _ in - if self.statusBarVisibilityStatus() == false { - self.constructCompactView(true) - self.hasSystemHiddenClocker = true - } else if self.hasSystemHiddenClocker { - self.constructCompactView() - self.hasSystemHiddenClocker = false + timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: false) { [weak self] _ in + guard let localSelf = self else { return } + if localSelf.statusBarVisibilityStatus() == false { + localSelf.constructCompactView(true) + localSelf.hasSystemHiddenClocker = true + localSelf.statusItem.target = self + localSelf.statusItem.button?.action = #selector(localSelf.menubarIconClicked(_:)) + } else if localSelf.hasSystemHiddenClocker { + localSelf.constructCompactView() + localSelf.hasSystemHiddenClocker = false } } }