diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-01 17:04:26 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-01 17:17:47 +0900 |
commit | 825bb6347623d998c671d3d42268230d1a783d76 (patch) | |
tree | bc62a31c9cccf91abcfff83645beb3028a75a3d6 /src/background | |
parent | 1f3dc0ba5a3bc0f02a98e3e11fca6038b9fd8b87 (diff) |
BackgroundComponent
Diffstat (limited to 'src/background')
-rw-r--r-- | src/background/index.js | 41 |
1 files changed, 5 insertions, 36 deletions
diff --git a/src/background/index.js b/src/background/index.js index 040a2d5..bf89a33 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -1,10 +1,9 @@ import * as keys from './keys'; import * as inputActions from '../actions/input'; import * as operationActions from '../actions/operation'; -import * as commandActions from '../actions/command'; import * as consoleActions from '../actions/console'; import * as settingsActions from '../actions/setting'; -import * as tabActions from '../actions/tab'; +import BackgroundComponent from '../components/background'; import reducers from '../reducers'; import messages from '../content/messages'; import * as store from '../store'; @@ -18,6 +17,10 @@ const backgroundStore = store.createStore(reducers, (e, sender) => { backgroundStore.dispatch(consoleActions.showError(e.message), sender); } }); +const backgroundComponent = new BackgroundComponent(backgroundStore); +backgroundStore.subscribe((sender) => { + backgroundComponent.update(sender); +}); backgroundStore.subscribe((sender) => { let currentInput = backgroundStore.getState().input; if (JSON.stringify(prevInput) === JSON.stringify(currentInput)) { @@ -66,40 +69,6 @@ const keyQueueChanged = (state, sender) => { backgroundStore.dispatch(inputActions.clearKeys(), sender); }; -const handleMessage = (message, sender) => { - switch (message.type) { - case messages.KEYDOWN: - return backgroundStore.dispatch( - inputActions.keyPress(message.code, message.ctrl), sender); - case messages.OPEN_URL: - if (message.newTab) { - return backgroundStore.dispatch( - tabActions.openNewTab(message.url), sender); - } - return backgroundStore.dispatch( - tabActions.openToTab(message.url, sender.tab), sender); - case messages.CONSOLE_BLURRED: - return backgroundStore.dispatch( - consoleActions.hide(), sender); - case messages.CONSOLE_ENTERED: - return backgroundStore.dispatch( - commandActions.exec(message.text, settings), sender); - case messages.CONSOLE_CHANGEED: - return backgroundStore.dispatch( - commandActions.complete(message.text, settings), sender); - case messages.SETTINGS_RELOAD: - backgroundStore.dispatch(settingsActions.load()); - } -}; - -browser.runtime.onMessage.addListener((message, sender) => { - try { - handleMessage(message, sender); - } catch (e) { - backgroundStore.dispatch(consoleActions.showError(e.message), sender); - } -}); - const initializeSettings = () => { backgroundStore.dispatch(settingsActions.load()); }; |