blob: 604ea92f4fec3c20b5b3f51d44a943a53c85e3f0 (
plain) (
blame)
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
|
import * as actions from '../shared/actions';
import * as tabs from './tabs';
import KeyQueue from './key-queue';
const queue = new KeyQueue();
const keyDownHandle = (request) => {
return queue.push({
code: request.code,
shift: request.shift,
ctrl: request.ctrl,
alt: request.alt,
meta: request.meta
})
}
const doBackgroundAction = (sender, action) => {
switch(action[0]) {
case actions.TABS_PREV:
tabs.selectPrevTab(sender.tab.index, actions[1] || 1);
break;
case actions.TABS_NEXT:
tabs.selectNextTab(sender.tab.index, actions[1] || 1);
break;
}
}
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
let action = null;
switch (request.type) {
case 'event.keydown':
action = keyDownHandle(request);
break;
}
if (action == null) {
return;
}
if (actions.isBackgroundAction(action[0])) {
doBackgroundAction(sender, action);
} else if (actions.isContentAction(action[0])) {
sendResponse(action);
}
});
|