aboutsummaryrefslogtreecommitdiff
path: root/src/content/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/index.js')
-rw-r--r--src/content/index.js61
1 files changed, 18 insertions, 43 deletions
diff --git a/src/content/index.js b/src/content/index.js
index 64d86bb..e01172d 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -1,54 +1,29 @@
import './console-frame.scss';
-import * as consoleFrames from './console-frames';
-import * as inputActions from './actions/input';
import { createStore } from 'shared/store';
-import ContentInputComponent from 'content/components/content-input';
-import KeymapperComponent from 'content/components/keymapper';
-import FollowComponent from 'content/components/follow';
import reducers from 'content/reducers';
-import messages from 'shared/messages';
+import TopContentComponent from './components/top-content';
+import FrameContentComponent from './components/frame-content';
const store = createStore(reducers);
-const followComponent = new FollowComponent(window.document.body, store);
-const contentInputComponent =
- new ContentInputComponent(window.document.body, store);
-const keymapperComponent = new KeymapperComponent(store);
-contentInputComponent.onKey((key, ctrl) => {
- return followComponent.key(key, ctrl);
-});
-contentInputComponent.onKey((key, ctrl) => {
- return keymapperComponent.key(key, ctrl);
-});
+
+let rootComponent = window.self === window.top
+ ? new TopContentComponent(window, store)
+ : new FrameContentComponent(window, store);
+
store.subscribe(() => {
- try {
- followComponent.update();
- contentInputComponent.update();
- } catch (e) {
- console.error(e);
- }
+ rootComponent.update();
});
-consoleFrames.initialize(window.document);
-
-const reloadSettings = () => {
- return browser.runtime.sendMessage({
- type: messages.SETTINGS_QUERY,
- }).then((settings) => {
- store.dispatch(inputActions.setKeymaps(settings.keymaps));
- });
-};
+browser.runtime.onMessage.addListener(msg => rootComponent.onMessage(msg));
+rootComponent.update();
-browser.runtime.onMessage.addListener((action) => {
- switch (action.type) {
- case messages.CONSOLE_HIDE_COMMAND:
- window.focus();
- consoleFrames.blur(window.document);
- return Promise.resolve();
- case messages.SETTINGS_CHANGED:
- return reloadSettings();
- default:
- return Promise.resolve();
+window.addEventListener('message', (event) => {
+ let message = null;
+ try {
+ message = JSON.parse(event.data);
+ } catch (e) {
+ // ignore unexpected message
+ return;
}
+ rootComponent.onMessage(message, event.source);
});
-
-reloadSettings();