-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
79 lines (78 loc) · 2.39 KB
/
background.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"use strict";
const db = getDatabaseConnection();
let port = startNativeApp();
browser.runtime.onMessage.addListener((n, sender, sendResponse) => {
let ret;
if (typeof n === 'string') {
n = { 'cmd': n };
}
if (n.cmd === 'notify') {
ret = browser.notifications.create(n.id === undefined ? "" : n.id, {
"type": "basic",
"title": n.title,
"message": n.message,
});
} else if (n.cmd.startsWith('tab/')) {
if ('tab' in sender && sender.tab.id !== browser.tabs.TAB_ID_NONE) {
let action;
if (n.cmd === 'tab/activate')
action = { active: true };
else if (n.cmd === 'tab/mute')
action = { muted: true };
else if (n.cmd === 'tab/unmute')
action = { muted: false };
else if (n.cmd === 'tab/pin')
action = { pinned: true };
else if (n.cmd === 'tab/unpin')
action = { pinned: false };
else if (n.cmd === 'tab/url')
action = { url: n.url };
else if (n.cmd === 'tab/reload')
ret = browser.tabs.reload();
else if (n.cmd === 'tab/force-reload')
ret = browser.tabs.reload({bypassCache: true});
else if (n.cmd === 'tab/close')
ret = browser.tabs.remove(sender.tab.id);
else if (n.cmd === 'tab/open') {
let create = { 'url': n.url };
if ('active' in n)
create.active = n.active;
if ('pinned' in n)
create.pinned = n.pinned;
if ('window' in n)
;
else
n.window = 'tab';
if (n.window === 'tab')
create.windowId = sender.tab.windowId;
else if (n.window !== 'current')
console.warn('Ignore unknown window option for new tab', n.window, create);
ret = browser.tabs.create(create);
} else {
console.warn("got an unknown tab action from tab", sender.tab.id, n);
return;
}
if (ret === undefined)
ret = browser.tabs.update(sender.tab.id, action);
} else {
console.warn("got tab action, but not from a valid sender", n, sender);
return;
}
} else if (n.cmd === 'reloadfiles')
ret = port.postMessage({cmd: 'list', path: DOTPAGEMOD_PATH});
else if (n.cmd === 'openeditor')
ret = port.postMessage({cmd: 'openeditor', path: n.param});
else if (n.cmd === 'restartapp') {
port.disconnect();
port = startNativeApp();
ret = port.postMessage({cmd: 'list', path: DOTPAGEMOD_PATH});
} else if (n.cmd === 'clear-database')
db.then(handleDatabaseClearing);
else
return;
if (ret === undefined)
sendResponse();
else
ret.then(() => sendResponse());
});
getAndReloadConfigDirectory();