-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathservice_worker.js
More file actions
76 lines (68 loc) · 2.48 KB
/
service_worker.js
File metadata and controls
76 lines (68 loc) · 2.48 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 extensionId = chrome.runtime.id,
localStorage = await chrome.storage.local.get(['autostartEntries', 'showNotification', 'autoClose', 'autoCheckUpdate']);
// show error if our custom extension ID didn't apply correctly
if (extensionId !== 'algkcnfjnajfhgimadimbjhmpaeohhln') {
setTimeout(() => {
chrome.windows.create({
url: '/html/id_mismatch.html',
type: 'popup',
height: 200,
width: 840
});
}, 500);
return;
}
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;
}
});