diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-08-13 17:30:18 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-08-13 17:30:18 +0900 |
commit | e45985088e0bbd041a567bab6b7665d2906528e4 (patch) | |
tree | 5e99b3f10e6b553b0f3b0d5afa811b6133bb9798 /src/background/index.js | |
parent | d169661e030e53b6a1635f86205f9fc42d2b7ef2 (diff) | |
parent | 41069cf527ed159d6c5ff89cc77867537025c9f5 (diff) |
Merge branch 'basic-features'
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); + } +}); |