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"
}
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 {

18
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
}
}
}

Loading…
Cancel
Save