diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-05-06 21:42:43 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-06 21:42:43 +0900 |
commit | 104a9666ff627b11ce7cf3a5bf096b1bc3437bc1 (patch) | |
tree | 4d995736429753d8c9d2892ef6195e6517777fc9 /src/content/components/common/index.js | |
parent | 828ac8cd84ddae9565be67f56e452a416b305c7a (diff) | |
parent | cf30ef0cd503b3b9dee882202d64ba9db9922ee3 (diff) |
Merge pull request #386 from ueokande/addon-enabled-indicator
Addon enabled indicator
Diffstat (limited to 'src/content/components/common/index.js')
-rw-r--r-- | src/content/components/common/index.js | 19 |
1 files changed, 18 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, + }); } } |