Skip to content

Commit

Permalink
added total work time counter
Browse files Browse the repository at this point in the history
  • Loading branch information
orlv committed Jun 6, 2016
1 parent e2a4897 commit 615a23e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
8 changes: 8 additions & 0 deletions ibreaktime/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<connections>
<outlet property="cyclesMenuItem" destination="uUd-5i-SD1" id="EnH-H5-I6x"/>
<outlet property="statusMenu" destination="WHT-Bw-joN" id="bgL-Hh-sRL"/>
<outlet property="totalTimeMenuItem" destination="cn8-53-Gjd" id="FhR-9j-ZLL"/>
<outlet property="totalWorkTimeMenuItem" destination="cn8-53-Gjd" id="v7h-P8-CeZ"/>
</connections>
</customObject>
<menu id="WHT-Bw-joN">
Expand All @@ -28,6 +30,12 @@
<action selector="cyclesClicked:" target="92C-VU-NHd" id="cHo-Kv-0UO"/>
</connections>
</menuItem>
<menuItem title="Total Work Time" id="cn8-53-Gjd">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="totalWorkTimeClicked:" target="92C-VU-NHd" id="mvH-Ik-Ito"/>
</connections>
</menuItem>
<menuItem title="Reset Timer" id="R22-0m-9vN">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
Expand Down
4 changes: 2 additions & 2 deletions ibreaktime/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.4</string>
<string>1.5</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.4</string>
<string>1.5</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.productivity</string>
<key>LSMinimumSystemVersion</key>
Expand Down
32 changes: 16 additions & 16 deletions ibreaktime/PreferencesWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -20,103 +20,103 @@
<window title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="529" y="513" width="242" height="242"/>
<rect key="contentRect" x="529" y="513" width="242" height="257"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="242" height="242"/>
<rect key="frame" x="0.0" y="0.0" width="242" height="257"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Yqu-Ok-MKg">
<rect key="frame" x="72" y="208" width="84" height="17"/>
<rect key="frame" x="72" y="223" width="84" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Work interval" id="D5U-Nx-d8p">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="eQC-P4-oTt">
<rect key="frame" x="72" y="163" width="87" height="17"/>
<rect key="frame" x="72" y="178" width="87" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Break interval" id="ccr-n3-ZGW">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uRe-Z3-ZuD">
<rect key="frame" x="20" y="200" width="40" height="22"/>
<rect key="frame" x="20" y="215" width="40" height="22"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="" drawsBackground="YES" usesSingleLineMode="YES" id="Lqr-z5-dAb">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ytv-6Q-6Aj">
<rect key="frame" x="20" y="155" width="40" height="22"/>
<rect key="frame" x="20" y="170" width="40" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="au5-4S-ncJ">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="deg-Hj-jHn">
<rect key="frame" x="20" y="110" width="40" height="22"/>
<rect key="frame" x="20" y="125" width="40" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="4BM-LK-rgG">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ro9-vu-SxQ">
<rect key="frame" x="72" y="116" width="103" height="17"/>
<rect key="frame" x="72" y="131" width="103" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Max idle interval" id="EVJ-wZ-gWz">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="egC-WU-WN4">
<rect key="frame" x="72" y="188" width="156" height="17"/>
<rect key="frame" x="72" y="203" width="156" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="1-600 min. Default: 55 min" id="gQL-Ym-1c4">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="es7-On-6wa">
<rect key="frame" x="72" y="143" width="156" height="17"/>
<rect key="frame" x="72" y="158" width="156" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="1-600 min. Default: 5 min" id="PcV-pJ-TFe">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="GH6-1r-sDe">
<rect key="frame" x="72" y="95" width="165" height="17"/>
<rect key="frame" x="72" y="110" width="165" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="1-1800 sec. Default: 20 sec" id="Ruo-qB-mxx">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9qj-sY-JSK">
<rect key="frame" x="20" y="64" width="40" height="22"/>
<rect key="frame" x="20" y="79" width="40" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="zCd-ZV-8le">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Spn-Zc-UEh">
<rect key="frame" x="72" y="70" width="152" height="17"/>
<rect key="frame" x="72" y="85" width="152" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Cycles reset idle interval" id="bhT-1N-4ai">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="79I-HZ-8LT">
<rect key="frame" x="72" y="49" width="165" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="1-12 hours. Default: 5 hours" id="auP-OP-QIi">
<rect key="frame" x="72" y="53" width="165" height="28"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="1-12 hours. Default: 5 hours
0: disable" id="auP-OP-QIi">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -137,7 +137,7 @@
<connections>
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
</connections>
<point key="canvasLocation" x="314" y="341"/>
<point key="canvasLocation" x="314" y="348.5"/>
</window>
</objects>
</document>
16 changes: 14 additions & 2 deletions ibreaktime/StatusMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class StatusMenuController: NSObject, PreferencesWindowDelegate {
@IBAction func cyclesClicked(sender: AnyObject) {
bt.cyclesCount = 0
defaults.setValue(0, forKey: "cyclesCount")
updateStatus()
// updateStatus()
}

@IBAction func aboutClicked(sender: AnyObject) {
Expand All @@ -45,11 +45,19 @@ class StatusMenuController: NSObject, PreferencesWindowDelegate {
updateStatus()
}

@IBOutlet weak var totalWorkTimeMenuItem: NSMenuItem!

@IBAction func totalWorkTimeClicked(sender: AnyObject) {
bt.totalWorkTime = 0
defaults.setValue(0, forKey: "totalWorkTime")
}

func updateStatus() {
var timeString: String

defaults.setValue(bt.cyclesCount, forKey: "cyclesCount")
defaults.setValue(bt.lastCheckTime, forKey: "lastCheckTime")
defaults.setValue(bt.totalWorkTime, forKey: "totalWorkTime")

if showSeconds {
timeString = String(format: "%d:%02d", bt.leftTime/60, bt.leftTime%60)
Expand All @@ -68,6 +76,7 @@ class StatusMenuController: NSObject, PreferencesWindowDelegate {
}

cyclesMenuItem.title = "Cycles: \(bt.cyclesCount)"
totalWorkTimeMenuItem.title = String(format: "Total Work Time: %d:%02d (~%d Cycles)", bt.totalWorkTime/60, bt.totalWorkTime%60, bt.totalWorkTime/bt.workInterval)
}

func showSecondsCheckboxClicked(showSeconds: Bool) {
Expand Down Expand Up @@ -102,7 +111,6 @@ class StatusMenuController: NSObject, PreferencesWindowDelegate {
preferencesWindow.delegate = self

aboutWindow = AboutWindow()

showSeconds = defaults.boolForKey("showSeconds")

bt = Breaktimer(defaults.integerForKey("workInterval"), defaults.integerForKey("breakInterval"), defaults.integerForKey("maxIdleInterval"))
Expand All @@ -114,6 +122,10 @@ class StatusMenuController: NSObject, PreferencesWindowDelegate {
bt.checkCyclesCounter(Int(-lastCheckTime.timeIntervalSinceNow))
}

if bt.cyclesCount > 0 {
bt.totalWorkTime = defaults.integerForKey("totalWorkTime")
}

updateStatus()
statusItem.menu = statusMenu

Expand Down
10 changes: 7 additions & 3 deletions ibreaktime/breaktimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Breaktimer : NSObject {
var timeToWork = true
var leftTime = 0
var cyclesCount = 0
var totalWorkTime = 0

func updateLeftTime(newInterval: Int, _ prevInterval: Int) {
if newInterval > prevInterval {
Expand Down Expand Up @@ -70,8 +71,8 @@ class Breaktimer : NSObject {

var cyclesResetIdleInterval: Int {
set {
// between 1 and 12 hours. defaulf: 5 hours
if newValue < 60 * 60 || newValue > 12 * 60 * 60 {
// between 1 and 12 hours. defaulf: 5 hours. 0: disable
if newValue < 0 || newValue > 12 * 60 * 60 {
_cyclesResetIdleInterval = 5 * 60 * 60
} else {
_cyclesResetIdleInterval = newValue
Expand All @@ -93,7 +94,8 @@ class Breaktimer : NSObject {

// check if we need reset cycles counter
func checkCyclesCounter(intervalFromLastTimerTick: Int) {
if (intervalFromLastTimerTick > cyclesResetIdleInterval) || (idleTimer.idleTime > cyclesResetIdleInterval) {
if cyclesResetIdleInterval > 0 &&
((intervalFromLastTimerTick > cyclesResetIdleInterval) || (idleTimer.idleTime > cyclesResetIdleInterval)) {
cyclesCount = 0
}
}
Expand All @@ -115,6 +117,7 @@ class Breaktimer : NSObject {
if timeToWork {
if !idleTimer.idle && leftTime > 0 {
leftTime -= timerInterval
totalWorkTime += timerInterval
if leftTime <= 0 {
playSound()
}
Expand All @@ -135,6 +138,7 @@ class Breaktimer : NSObject {
// wait until user takes a break
if leftTime == breakInterval {
if !idleTimer.idle {
totalWorkTime += timerInterval
return
} else {
leftTime -= idleTimer.maxIdleInterval
Expand Down

0 comments on commit 615a23e

Please sign in to comment.