diff options
Diffstat (limited to 'src/background/index.js')
-rw-r--r-- | src/background/index.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/background/index.js b/src/background/index.js new file mode 100644 index 0000000..604ea92 --- /dev/null +++ b/src/background/index.js @@ -0,0 +1,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); + } +}); |