Skip to content

Commit 67e301a

Browse files
committed
feat(pomodoro): add and improve notifications #32
1 parent c52b1f5 commit 67e301a

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

app-src/scripts/main/global-services/notifier-s.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Service in the superProductivity.
77
*/
88

9-
(function () {
9+
(function() {
1010
'use strict';
1111

1212
angular
@@ -21,18 +21,24 @@
2121
Notification.requestPermission();
2222
}
2323

24-
return function (notification) {
24+
return function(notification) {
2525
if (IS_ELECTRON) {
2626
// send to electron
2727
window.ipcRenderer.send(IPC_NOTIFIER_EV, notification);
2828
} else if (Notification && Notification.permission === 'granted') {
29-
new Notification(notification.title, {
29+
const notificationInstance = new Notification(notification.title, {
3030
icon: notification.icon || 'img/icon_128x128-with-pad.png',
3131
body: notification.message
3232
});
33+
34+
notificationInstance.onclick = () => {
35+
notificationInstance.close();
36+
};
37+
38+
setTimeout(() => {
39+
notificationInstance.close();
40+
}, notification.time || 10000);
3341
}
3442
};
35-
3643
}
37-
3844
})();

app-src/scripts/pomodoro-button/pomodoro-button-s.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class PomodoroButton {
2020
/* @ngInject */
21-
constructor($rootScope, $interval, $q, Dialogs, Tasks, SimpleToast, LS_DEFAULTS, EV, IS_ELECTRON) {
21+
constructor($rootScope, $interval, $q, Dialogs, Tasks, SimpleToast, LS_DEFAULTS, EV, IS_ELECTRON, Notifier) {
2222
this.LS_DEFAULTS = LS_DEFAULTS;
2323
this.IS_ELECTRON = IS_ELECTRON;
2424
this.EV = EV;
@@ -28,6 +28,7 @@
2828
this.Dialogs = Dialogs;
2929
this.SimpleToast = SimpleToast;
3030
this.Tasks = Tasks;
31+
this.Notifier = Notifier;
3132

3233
this.initListeners();
3334

@@ -137,6 +138,10 @@
137138
this.playSessionDoneSound();
138139
this.data.isOnBreak = !this.data.isOnBreak;
139140
if (this.data.isOnBreak) {
141+
this.Notifier({
142+
title: 'Pomodoro break #' + this.data.currentCycle + ' started.',
143+
});
144+
140145
this.dialog = this.Dialogs('POMODORO_BREAK', {
141146
pomodoroData: this.data,
142147
pomodoroConfig: this.config
@@ -153,7 +158,12 @@
153158
}
154159
} else {
155160
this.data.currentCycle++;
156-
this.selectTask();
161+
this.selectTask()
162+
.then(() => {
163+
this.Notifier({
164+
title: 'Pomodoro session #' + this.data.currentCycle + ' started.',
165+
});
166+
});
157167
}
158168

159169
this.setSessionTimerTime();

0 commit comments

Comments
 (0)