From 7f3561f6954b1273ecb4ec939833126c3445b20a Mon Sep 17 00:00:00 2001 From: Drew Frank Date: Wed, 5 Dec 2012 19:52:32 -0800 Subject: [PATCH 1/2] Prevent restarting break phase and add option to end break early. --- _locales/en/messages.json | 6 +++++- background.js | 24 ++++++++++++++++++------ options.html | 4 ++++ options.js | 4 ++++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 046461f..d64c191 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -71,9 +71,13 @@ "description": "On the options page, label for the checkbox that enables/disables ringing sound at the end of a timer" }, "options_click_restarts": { - "message": "Clicking on a running timer restarts it", + "message": "Clicking on a running work timer restarts it", "description": "On the options page, label for the checkbox that enables/disables the feature that clicking on a running timer restarts it" }, + "options_click_skips": { + "message": "Clicking on a running break timer starts a new work period", + "description": "On the options page, label for the checkbox that enables/disables the feature that clicking on a running break timer starts a work period" + }, "options_click_restarts_note": { "message": "By the strictness philosophy, the only way to cancel a running timer is to disable the extension.", "description": "On the options page, note below the label for the click-restarts checkbox explaining that this will not allow users to *cancel* a running timer" diff --git a/background.js b/background.js index 311a031..6abf196 100644 --- a/background.js +++ b/background.js @@ -144,10 +144,15 @@ function Pomodoro(options) { this.currentTimer.start(); } + this.stop = function () { + if (this.currentTimer) { + this.currentTimer.stop(); + } + } + this.restart = function () { - if(this.currentTimer) { - this.currentTimer.restart(); - } + this.stop(); + this.start(); } } @@ -162,6 +167,10 @@ Pomodoro.Timer = function Timer(pomodoro, options) { options.onStart(timer); options.onTick(timer); } + + this.stop = function () { + clearInterval(tickInterval); + } this.restart = function() { this.timeRemaining = options.duration; @@ -348,9 +357,12 @@ var notification, mainPomodoro = new Pomodoro({ chrome.browserAction.onClicked.addListener(function (tab) { if(mainPomodoro.running) { - if(PREFS.clickRestarts) { - mainPomodoro.restart(); - } + if(PREFS.clickRestarts && mainPomodoro.mostRecentMode == 'work') { + mainPomodoro.currentTimer.restart(); + } + if(PREFS.clickSkips && mainPomodoro.mostRecentMode == 'break') { + mainPomodoro.restart(); + } } else { mainPomodoro.start(); } diff --git a/options.html b/options.html index d97ca87..d8c4730 100644 --- a/options.html +++ b/options.html @@ -142,6 +142,10 @@

+
+ + +
diff --git a/options.js b/options.js index 32dada8..08232ae 100644 --- a/options.js +++ b/options.js @@ -26,6 +26,7 @@ var form = document.getElementById('options-form'), showNotificationsEl = document.getElementById('show-notifications'), shouldRingEl = document.getElementById('should-ring'), clickRestartsEl = document.getElementById('click-restarts'), + clickSkipsEl = document.getElementById('click-skips'), saveSuccessfulEl = document.getElementById('save-successful'), timeFormatErrorEl = document.getElementById('time-format-error'), background = chrome.extension.getBackgroundPage(), @@ -63,6 +64,7 @@ form.onsubmit = function () { showNotifications: showNotificationsEl.checked, shouldRing: shouldRingEl.checked, clickRestarts: clickRestartsEl.checked, + clickSkips: clickSkipsEl.checked, whitelist: whitelistEl.selectedIndex == 1 }) saveSuccessfulEl.className = 'show'; @@ -73,6 +75,7 @@ siteListEl.onfocus = formAltered; showNotificationsEl.onchange = formAltered; shouldRingEl.onchange = formAltered; clickRestartsEl.onchange = formAltered; +clickSkipsEl.onchange = formAltered; whitelistEl.onchange = formAltered; function formAltered() { @@ -84,6 +87,7 @@ siteListEl.value = background.PREFS.siteList.join("\n"); showNotificationsEl.checked = background.PREFS.showNotifications; shouldRingEl.checked = background.PREFS.shouldRing; clickRestartsEl.checked = background.PREFS.clickRestarts; +clickSkipsEl.checked = background.PREFS.clickSkips; whitelistEl.selectedIndex = background.PREFS.whitelist ? 1 : 0; var duration, minutes, seconds; From e26362b46879dfce103707f29cc5d54b3a06ffc6 Mon Sep 17 00:00:00 2001 From: Drew Frank Date: Wed, 5 Dec 2012 19:55:37 -0800 Subject: [PATCH 2/2] Add option to automatically start work phase when break phase ends. --- _locales/en/messages.json | 4 ++++ background.js | 7 +++++-- options.html | 4 ++++ options.js | 4 ++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index d64c191..3ac6848 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -78,6 +78,10 @@ "message": "Clicking on a running break timer starts a new work period", "description": "On the options page, label for the checkbox that enables/disables the feature that clicking on a running break timer starts a work period" }, + "options_auto_continue": { + "message": "Automatically start a new work period when the break timer finishes", + "description": "On the options page, label for the checkbox that enables/disables the feature that the work timer starts automatically at the end of a break" + }, "options_click_restarts_note": { "message": "By the strictness philosophy, the only way to cancel a running timer is to disable the extension.", "description": "On the options page, note below the label for the click-restarts checkbox explaining that this will not allow users to *cancel* a running timer" diff --git a/background.js b/background.js index 6abf196..949e03b 100644 --- a/background.js +++ b/background.js @@ -127,6 +127,9 @@ function Pomodoro(options) { this.onTimerEnd = function (timer) { this.running = false; + if (PREFS.autoContinue && this.mostRecentMode == 'break') { + this.start(); + } } this.start = function () { @@ -189,9 +192,9 @@ Pomodoro.Timer = function Timer(pomodoro, options) { timer.timeRemaining--; options.onTick(timer); if(timer.timeRemaining <= 0) { - clearInterval(tickInterval); - pomodoro.onTimerEnd(timer); + timer.stop(); options.onEnd(timer); + pomodoro.onTimerEnd(timer); } } } diff --git a/options.html b/options.html index d8c4730..a92105e 100644 --- a/options.html +++ b/options.html @@ -146,6 +146,10 @@

+
+ + +
diff --git a/options.js b/options.js index 08232ae..6748f1f 100644 --- a/options.js +++ b/options.js @@ -27,6 +27,7 @@ var form = document.getElementById('options-form'), shouldRingEl = document.getElementById('should-ring'), clickRestartsEl = document.getElementById('click-restarts'), clickSkipsEl = document.getElementById('click-skips'), + autoContinueEl = document.getElementById('auto-continue'), saveSuccessfulEl = document.getElementById('save-successful'), timeFormatErrorEl = document.getElementById('time-format-error'), background = chrome.extension.getBackgroundPage(), @@ -65,6 +66,7 @@ form.onsubmit = function () { shouldRing: shouldRingEl.checked, clickRestarts: clickRestartsEl.checked, clickSkips: clickSkipsEl.checked, + autoContinue: autoContinueEl.checked, whitelist: whitelistEl.selectedIndex == 1 }) saveSuccessfulEl.className = 'show'; @@ -76,6 +78,7 @@ showNotificationsEl.onchange = formAltered; shouldRingEl.onchange = formAltered; clickRestartsEl.onchange = formAltered; clickSkipsEl.onchange = formAltered; +autoContinueEl.onchange = formAltered; whitelistEl.onchange = formAltered; function formAltered() { @@ -88,6 +91,7 @@ showNotificationsEl.checked = background.PREFS.showNotifications; shouldRingEl.checked = background.PREFS.shouldRing; clickRestartsEl.checked = background.PREFS.clickRestarts; clickSkipsEl.checked = background.PREFS.clickSkips; +autoContinueEl.checked = background.PREFS.autoContinue; whitelistEl.selectedIndex = background.PREFS.whitelist ? 1 : 0; var duration, minutes, seconds;