From 129aae38df1a17a5850898d5832bb8112ead3cbb Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 6 May 2018 22:30:04 +0900 Subject: Indicator shows the add-on enabled --- src/content/components/common/index.js | 14 ++++++++++++++ src/content/components/top-content/index.js | 7 +++++++ 2 files changed, 21 insertions(+) (limited to 'src/content/components') diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js index 565632c..c5d1df7 100644 --- a/src/content/components/common/index.js +++ b/src/content/components/common/index.js @@ -14,10 +14,12 @@ export default class Common { input.onKey(key => keymapper.key(key)); this.store = store; + this.prevEnabled = this.store.getState().addon.enabled; this.reloadSettings(); messages.onMessage(this.onMessage.bind(this)); + store.subscribe(() => this.update()); } onMessage(message) { @@ -27,6 +29,18 @@ export default class Common { } } + update() { + let enabled = this.store.getState().addon.enabled; + if (enabled !== this.prevEnabled) { + this.prevEnabled = enabled; + + browser.runtime.sendMessage({ + type: messages.ADDON_ENABLED_RESPONSE, + enabled, + }); + } + } + reloadSettings() { browser.runtime.sendMessage({ type: messages.SETTINGS_QUERY, diff --git a/src/content/components/top-content/index.js b/src/content/components/top-content/index.js index cf21ec4..cb9e160 100644 --- a/src/content/components/top-content/index.js +++ b/src/content/components/top-content/index.js @@ -48,11 +48,18 @@ export default class TopContent { } 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, + }); } } } -- cgit v1.2.3