Browse Source

Capturing self.

pull/101/head
Abhishek 3 years ago
parent
commit
fd532e22bb
  1. 43
      Clocker/Preferences/General/PreferencesViewController.swift
  2. 18
      Clocker/Preferences/Menu Bar/StatusItemHandler.swift

43
Clocker/Preferences/General/PreferencesViewController.swift

@ -18,6 +18,49 @@ struct PreferencesConstants {
static let hotKeyPathIdentifier = "values.globalPing" 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 { class PreferencesViewController: ParentViewController {
private var isActivityInProgress = false { private var isActivityInProgress = false {
didSet { didSet {

18
Clocker/Preferences/Menu Bar/StatusItemHandler.swift

@ -339,6 +339,7 @@ class StatusItemHandler: NSObject {
statusItem.button?.title = CLEmptyString statusItem.button?.title = CLEmptyString
statusItem.button?.image = NSImage(named: .menubarIcon) statusItem.button?.image = NSImage(named: .menubarIcon)
statusItem.button?.imagePosition = .imageOnly statusItem.button?.imagePosition = .imageOnly
statusItem.toolTip = "Clocker"
} }
private func setupForStandardText() { private func setupForStandardText() {
@ -412,13 +413,16 @@ class StatusItemHandler: NSObject {
time.invalidate() time.invalidate()
} }
timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: false) { _ in timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: false) { [weak self] _ in
if self.statusBarVisibilityStatus() == false { guard let localSelf = self else { return }
self.constructCompactView(true) if localSelf.statusBarVisibilityStatus() == false {
self.hasSystemHiddenClocker = true localSelf.constructCompactView(true)
} else if self.hasSystemHiddenClocker { localSelf.hasSystemHiddenClocker = true
self.constructCompactView() localSelf.statusItem.target = self
self.hasSystemHiddenClocker = false localSelf.statusItem.button?.action = #selector(localSelf.menubarIconClicked(_:))
} else if localSelf.hasSystemHiddenClocker {
localSelf.constructCompactView()
localSelf.hasSystemHiddenClocker = false
} }
} }
} }

Loading…
Cancel
Save