-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventPage.js
57 lines (48 loc) · 1.3 KB
/
eventPage.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// test at init
chrome.runtime.onInstalled.addListener(() => {
log("[OnInstalled] ");
// need to indicate that extension need config
});
chrome.runtime.onStartup.addListener(() => {
log("[onStartup]");
});
chrome.runtime.onSuspend.addListener(() => {
log("[onSuspend]");
});
chrome.alarms.onAlarm.addListener(alarm => {
log("[onAlarm] with alarm: ", alarm);
switch (alarm.name) {
case ALARM_ICON_INDICATOR:
updateIconIndicator();
break;
default:
log("[onAlarm] default alarm triggered for alarm: ", alarm);
break;
}
});
// extension calls
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log("[onMessage] action:", request.action);
switch (request.action) {
case "pingAPI":
pingAPI(sendResponse, sendResponse);
break;
case "refreshData":
getFilteredLabels(sendResponse);
break;
}
// we need to return true, to indicate sendResponse will be handle asynchronously
return true;
});
// periodic calls
chrome.alarms.create(ALARM_ICON_INDICATOR, {
delayInMinutes: 0,
periodInMinutes: 5
});
// notifications
chrome.notifications.onClosed.addListener((id, byUser) => {
console.log("lets clear it", id, byUser);
});
chrome.notifications.onClicked.addListener(id => {
console.log("click!", id);
});