diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-16 21:48:41 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-16 21:48:41 +0900 |
commit | 33a97a0e8c18c099b23cd50a832242985837edca (patch) | |
tree | 73a15a1a39b41e0c42ea79a2d521d63865f83f06 /src/content/index.js | |
parent | 7ced514f83a69f557c19c1eb24ad792b3f2ace89 (diff) | |
parent | cf3a1eaf16d7dd5c71de57901415fb147793aa56 (diff) |
Merge pull request #61 from ueokande/multi-frame-following
Multi frame following
Diffstat (limited to 'src/content/index.js')
-rw-r--r-- | src/content/index.js | 61 |
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(); |