Skip to content

Commit

Permalink
Add a break confirmation and break progress to notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
flakas committed Oct 4, 2016
1 parent cc3c5f6 commit c4d8a11
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 112 deletions.
42 changes: 37 additions & 5 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ if (typeof localStorage.statistics === "undefined") {
} else {
statistics = $.parseJSON(localStorage["statistics"]);
}
var notification, breakTime, workTime, rule, enableSound, iCloseNotification = 0, timer, badgeTimer, nextBreak;
var notification, breakTime, workTime, rule, enableSound, iCloseNotification = 0, timer, nextBreak, breakTimeLeft;
resetTimes();
$(document).ready(function () {
chrome.notifications.onButtonClicked.addListener(handleNotificationInteraction);
waitForNext();
updateBadge();
});
Expand All @@ -101,14 +102,28 @@ function displayNotification() {
notification = chrome.notifications.create('bh-notification', {
type: 'basic',
title: 'Break Helper',
message: "You've been working for quite a while, please take a break",
iconUrl: 'icon48.png',
}, function (notificationId) {
doBreak();
message: "You've been working for quite a while, please take a break.",
iconUrl: 'icon128.png',
buttons: [
{ title: "Take a break" },
{ title: "Skip this break" }
],
requireInteraction: true,
});
log("Displaying notification");
}

function handleNotificationInteraction(notificationId, buttonIndex) {
if (notificationId === 'bh-notification') {
if (buttonIndex === 0) {
doBreak();
} else if (buttonIndex === 1) {
skipBreak();
closeNotification();
}
}
}

function closeNotification() {
"use strict";
iCloseNotification = 1;
Expand Down Expand Up @@ -147,10 +162,27 @@ function skipFor4Hours() {
}

function doBreak() {
breakTimeLeft = breakTime;
timer = setTimeout(waitAndClose, 1000 * breakTime);
updateBreakNotificationTimer();
log("Doing a break");
}

function updateBreakNotificationTimer() {
if (breakTimeLeft <= 0) return;
breakTimeLeft -= 1;
var progress = breakTimeLeft / breakTime * 100;
chrome.notifications.update('bh-notification', {
type: 'progress',
title: 'Break Helper',
message: "You're on a break.",
iconUrl: 'icon128.png',
buttons: [],
progress: progress
});
setTimeout(updateBreakNotificationTimer, 1000);
};

function waitAndClose() {
closeNotification();
var currentTime = new Date();
Expand Down
85 changes: 0 additions & 85 deletions js/notification.js

This file was deleted.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Break Helper",
"version": "1.4.4",
"version": "1.5",
"description": "Reminds you to take a break, because breaks are good for your health and productivity",
"icons": {
"16": "icon16.png",
Expand Down
21 changes: 0 additions & 21 deletions notification.html

This file was deleted.

0 comments on commit c4d8a11

Please sign in to comment.