Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,17 @@
"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_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 <em>cancel</em> 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"
Expand Down
31 changes: 23 additions & 8 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -144,10 +147,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();
}
}

Expand All @@ -162,6 +170,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;
Expand All @@ -180,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);
}
}
}
Expand Down Expand Up @@ -348,9 +360,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();
}
Expand Down
8 changes: 8 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ <h1 data-i18n="options_title"></h1>
<p class="note" data-i18n="options_click_restarts_note"></p>
</label>
</div>
<div>
<input id="click-skips" type="checkbox" />
<label for="click-skips" data-i18n="options_click_skips"></label>
</div>
<div>
<input id="auto-continue" type="checkbox" />
<label for="auto-continue" data-i18n="options_auto_continue"></label>
</div>
<button type="submit" id="save-button" data-i18n="options_save_changes"></button>
<span id="save-successful" data-i18n="options_save_successful"></span>
</form>
Expand Down
8 changes: 8 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ 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'),
autoContinueEl = document.getElementById('auto-continue'),
saveSuccessfulEl = document.getElementById('save-successful'),
timeFormatErrorEl = document.getElementById('time-format-error'),
background = chrome.extension.getBackgroundPage(),
Expand Down Expand Up @@ -63,6 +65,8 @@ form.onsubmit = function () {
showNotifications: showNotificationsEl.checked,
shouldRing: shouldRingEl.checked,
clickRestarts: clickRestartsEl.checked,
clickSkips: clickSkipsEl.checked,
autoContinue: autoContinueEl.checked,
whitelist: whitelistEl.selectedIndex == 1
})
saveSuccessfulEl.className = 'show';
Expand All @@ -73,6 +77,8 @@ siteListEl.onfocus = formAltered;
showNotificationsEl.onchange = formAltered;
shouldRingEl.onchange = formAltered;
clickRestartsEl.onchange = formAltered;
clickSkipsEl.onchange = formAltered;
autoContinueEl.onchange = formAltered;
whitelistEl.onchange = formAltered;

function formAltered() {
Expand All @@ -84,6 +90,8 @@ 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;
autoContinueEl.checked = background.PREFS.autoContinue;
whitelistEl.selectedIndex = background.PREFS.whitelist ? 1 : 0;

var duration, minutes, seconds;
Expand Down