-
Notifications
You must be signed in to change notification settings - Fork 5
/
service_worker.js
61 lines (55 loc) · 2.12 KB
/
service_worker.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
58
59
60
61
chrome.runtime.onStartup.addListener(async () => {
const localStorage = await chrome.storage.local.get(['autostartEntries', 'showNotification', 'autoClose', 'autoCheckUpdate']);
// check for extension update
if (localStorage.autoCheckUpdate) {
chrome.windows.create({
url: '/html/check_update.html?autoclose=1',
type: 'popup',
state: 'minimized'
});
}
// open html/autoStart.html (used to execute command via terminalPrivate API) at login
chrome.windows.create({
url: '/html/autostart.html',
type: 'popup',
state: 'minimized'
});
});
chrome.runtime.onInstalled.addListener(async i => {
const localStorage = await chrome.storage.local.get(['autostartEntries', 'showNotification', 'autoClose', 'autoCheckUpdate']);
if (localStorage.autoCheckUpdate === undefined) {
// ask user for enabling auto update check
await new Promise(resolve => {
chrome.windows.create({
url: '/html/check_update.html?askUpdateCheck=1',
type: 'popup',
height: 250,
width: 450
}, window => {
// wait for user selection
const listener = windowId => {
if (windowId === window.id) {
chrome.windows.onRemoved.removeListener(listener);
resolve();
}
};
chrome.windows.onRemoved.addListener(listener);
});
});
}
switch (i.reason) {
case 'update':
if (i.previousVersion.localeCompare("5.0.0", undefined, { numeric: true, sensitivity: 'base' }) >= 0) {
chrome.storage.local.set({ showNotification: true, autoClose: true });
} else {
chrome.storage.local.set({ autostartEntries: [], showNotification: true, autoClose: true });
chrome.windows.create({ url: '/html/list_entries.html', type: 'popup', height: 600, width: 700 });
}
break;
case 'install':
// prompt user to enter a command after install
chrome.storage.local.set({ autostartEntries: [], showNotification: true, autoClose: true });
chrome.windows.create({ url: '/html/list_entries.html', type: 'popup', height: 600, width: 700 });
break;
}
});