diff options
Diffstat (limited to 'src/content/components')
-rw-r--r-- | src/content/components/common/index.js | 19 | ||||
-rw-r--r-- | src/content/components/top-content/index.js | 9 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js index 565632c..9b7b083 100644 --- a/src/content/components/common/index.js +++ b/src/content/components/common/index.js @@ -3,6 +3,7 @@ import KeymapperComponent from './keymapper'; import FollowComponent from './follow'; import * as settingActions from 'content/actions/setting'; import messages from 'shared/messages'; +import * as addonActions from '../../actions/addon'; export default class Common { constructor(win, store) { @@ -14,16 +15,32 @@ export default class Common { input.onKey(key => keymapper.key(key)); this.store = store; + this.prevEnabled = undefined; this.reloadSettings(); messages.onMessage(this.onMessage.bind(this)); + store.subscribe(() => this.update()); } onMessage(message) { switch (message.type) { case messages.SETTINGS_CHANGED: - this.reloadSettings(); + return this.reloadSettings(); + case messages.ADDON_TOGGLE_ENABLED: + return this.store.dispatch(addonActions.toggleEnabled()); + } + } + + update() { + let enabled = this.store.getState().addon.enabled; + if (enabled !== this.prevEnabled) { + this.prevEnabled = enabled; + + browser.runtime.sendMessage({ + type: messages.ADDON_ENABLED_RESPONSE, + enabled, + }); } } diff --git a/src/content/components/top-content/index.js b/src/content/components/top-content/index.js index cf21ec4..a0d0480 100644 --- a/src/content/components/top-content/index.js +++ b/src/content/components/top-content/index.js @@ -44,15 +44,24 @@ export default class TopContent { .some(regex => regex.test(partial)); if (matched) { this.store.dispatch(addonActions.disable()); + } else { + this.store.dispatch(addonActions.enable()); } } onMessage(message) { + let addonState = this.store.getState().addon; + switch (message.type) { case messages.CONSOLE_UNFOCUS: this.win.focus(); consoleFrames.blur(window.document); return Promise.resolve(); + case messages.ADDON_ENABLED_QUERY: + return Promise.resolve({ + type: messages.ADDON_ENABLED_RESPONSE, + enabled: addonState.enabled, + }); } } } |