forked from taicki/omnibox-timer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
message_handling.js
41 lines (39 loc) · 1.25 KB
/
message_handling.js
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
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (message.action === 'clearTimeOut') {
let curi = message.dat;
// Respond to the message
console.log('Service Worker: Received clear timer');
//Rewrite the timer
updateTimer()
.then((timers) => {
try {
chrome.notifications.update("" + curi, { requireInteraction: false }, function () {
chrome.notifications.clear("" + curi, function (cleared) {
for (var i = 0; i < timers.length; i++) {
if (parseInt(timers[i].tid) == curi) {
timers[i].status = "cancelled";
}
}
updateTimer(timers);
});
});
} catch (error) {
console.error(error);
}
//Clear the timeout
clearTimeout(message.dat);
chrome.runtime.sendMessage({ action: 'refreshPage'});
});
}
if (message.action === 'clearAllTimer') {
console.log('Service Worker: Received clear ALL timer');
updateTimer()
.then((timers) => {
timers = [];
updateTimer(timers)
.then((timers) => {
chrome.runtime.sendMessage({ action: 'refreshPage'});
})
});
}
});