-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
43 lines (41 loc) · 1.46 KB
/
Copy pathbackground.js
File metadata and controls
43 lines (41 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Create the basic alarm
chrome.alarms.create('Pomodorro Timer', { periodInMinutes: 1 / 60 });
// Add a listener to track the changes
chrome.alarms.onAlarm.addListener((alarm) => {
if (alarm.name === 'Pomodorro Timer') {
// Get the local variables and increment if we need to
chrome.storage.local.get(['timer', 'isRunning', 'timeOption'], (res) => {
let timer = res.timer + 1;
if (res.isRunning) {
if (res.timer === 60 * res.timeOption) {
// Change to using the tabs
// this.registration.showNotification('Pomodoro Timer', {
// body: `${res.timeOption} minutes have passed! Great Job!`,
// icon: 'chronometer.png',
// });
chrome.notifications.create({
title: 'Time has ended!',
message: 'Time has ended!',
iconUrl: 'chronometer.png',
type: 'basic',
});
timer = 0;
res.isRunning = false;
}
// Once the timer has been updated, we want to set the value
chrome.storage.local.set({
timer,
isRunning: res.isRunning,
});
}
});
}
});
// Check if the timer is on or not, if on, how much time is left
chrome.storage.local.get(['timer', 'isRunning'], (res) => {
chrome.storage.local.set({
timer: 'timer' in res ? res.timer : 0,
isRunning: 'isRunning' in res ? res.isRunning : false,
timeOption: 'timeOption' in res ? res.timeOption : 25,
});
});