Skip to content

Commit

Permalink
Implement blink-on-timer-expiration for statusItem.button
Browse files Browse the repository at this point in the history
  • Loading branch information
kristopherjohnson committed Oct 22, 2019
1 parent 854cb4d commit 61788f4
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions MenubarCountdown/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

stopwatch.reset()

let statusBar = NSStatusBar.system
statusItem = statusBar.statusItem(withLength: NSStatusItem.variableLength)

statusItem.menu = menu
statusItem.button?.toolTip = NSLocalizedString("Menubar Countdown",
comment: "Status Item Tooltip")
showStatusItemIcon()
initializeStatusItem()

if UserDefaults.standard.bool(forKey: AppUserDefaults.showStartDialogOnLaunchKey) {
showStartTimerDialog(self)
Expand Down Expand Up @@ -126,6 +120,22 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

/**
Create `statusItem` and set its initial state.
*/
func initializeStatusItem() {
let statusBar = NSStatusBar.system
statusItem = statusBar.statusItem(withLength: NSStatusItem.variableLength)

statusItem.menu = menu
statusItem.button?.wantsLayer = true
statusItem.button?.toolTip = NSLocalizedString("Menubar Countdown",
comment: "Status Item Tooltip")
statusItem.button?.font = NSFont.monospacedDigitSystemFont(ofSize: 0,
weight: .regular)
showStatusItemIcon()
}

/**
Sets the text of the menu bar status item.
*/
Expand Down Expand Up @@ -162,6 +172,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
statusItem.button?.title = "⌛️"
}

func startBlinking() {
statusItem.button?.layer?.addBlinkAnimation()
}

func stopBlinking() {
statusItem.button?.layer?.removeBlinkAnimation()
}

// MARK: Timer expiration

/**
Expand All @@ -180,7 +198,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let defaults = UserDefaults.standard

if defaults.bool(forKey: AppUserDefaults.blinkOnExpirationKey) {
//statusItemView.isTitleBlinking = true
startBlinking()
}

if defaults.bool(forKey: AppUserDefaults.playAlertSoundOnExpirationKey) {
Expand Down Expand Up @@ -328,7 +346,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
canPause = false
canResume = false

//statusItemView.isTitleBlinking = false
stopBlinking()
showStatusItemIcon()
}

Expand Down

0 comments on commit 61788f4

Please sign in to comment.