Skip to content

Commit

Permalink
add feature - press r to restart with the last timer after esc is…
Browse files Browse the repository at this point in the history
… pressed or timer runs out. (#75)
  • Loading branch information
mxgc authored Apr 13, 2020
1 parent 16ebded commit 9af9b8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ Enter digits to set minutes. A decimal point specifies seconds so `2.34` is 2 mi
<kbd>backspace</kbd> or <kbd>escape</kbd> to edit.
<kbd>enter</kbd> to start or pause the timer.
<kbd>cmd</kbd>+<kbd>n</kbd> to create a new timer.
<kbd>r</kbd> to restart with the last timer.
9 changes: 9 additions & 0 deletions Timer/MVClockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MVClockView: NSControl {
private var secondsLabel: NSTextView!
private var secondsSuffixWidth: CGFloat = 0.0
private var inputSeconds: Bool = false
private var lastTimerSeconds: CGFloat?
private let docktile: NSDockTile = NSApplication.shared.dockTile
public var inDock : Bool = false{
didSet{
Expand Down Expand Up @@ -294,6 +295,13 @@ class MVClockView: NSControl {
} else if (key == Keycode.returnKey || key == Keycode.space || key == Keycode.keypadEnter) {
// "Enter" or "Space" or "Keypad Enter"
self.handleClick();
} else if (key == Keycode.r && self.timer == nil && self.paused != true) {
// "r" for restarting with the last timer
if let seconds = self.lastTimerSeconds {
self.seconds = seconds
self.handleClick()
}

}
}

Expand Down Expand Up @@ -375,6 +383,7 @@ class MVClockView: NSControl {

private func start() {
guard self.seconds > 0 else { return }
self.lastTimerSeconds = self.seconds

self.paused = false
self.stop()
Expand Down

0 comments on commit 9af9b8c

Please sign in to comment.