aboutsummaryrefslogtreecommitdiff
path: root/src/background
diff options
context:
space:
mode:
Diffstat (limited to 'src/background')
-rw-r--r--src/background/index.js41
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());
};