aboutsummaryrefslogtreecommitdiff
path: root/src/background/components/indicator.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-05-06 21:42:43 +0900
committerGitHub <noreply@github.com>2018-05-06 21:42:43 +0900
commit104a9666ff627b11ce7cf3a5bf096b1bc3437bc1 (patch)
tree4d995736429753d8c9d2892ef6195e6517777fc9 /src/background/components/indicator.js
parent828ac8cd84ddae9565be67f56e452a416b305c7a (diff)
parentcf30ef0cd503b3b9dee882202d64ba9db9922ee3 (diff)
Merge pull request #386 from ueokande/addon-enabled-indicator
Addon enabled indicator
Diffstat (limited to 'src/background/components/indicator.js')
-rw-r--r--src/background/components/indicator.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/background/components/indicator.js b/src/background/components/indicator.js
new file mode 100644
index 0000000..cceb119
--- /dev/null
+++ b/src/background/components/indicator.js
@@ -0,0 +1,45 @@
+import * as indicators from '../shared/indicators';
+import messages from 'shared/messages';
+
+export default class IndicatorComponent {
+ constructor(store) {
+ this.store = store;
+
+ messages.onMessage(this.onMessage.bind(this));
+
+ browser.browserAction.onClicked.addListener(this.onClicked);
+ browser.tabs.onActivated.addListener((info) => {
+ return browser.tabs.query({ currentWindow: true }).then(() => {
+ return this.onTabActivated(info);
+ });
+ });
+ }
+
+ onTabActivated(info) {
+ return browser.tabs.sendMessage(info.tabId, {
+ type: messages.ADDON_ENABLED_QUERY,
+ }).then((resp) => {
+ return this.updateIndicator(resp.enabled);
+ });
+ }
+
+ onClicked(tab) {
+ browser.tabs.sendMessage(tab.id, {
+ type: messages.ADDON_TOGGLE_ENABLED,
+ });
+ }
+
+ onMessage(message) {
+ switch (message.type) {
+ case messages.ADDON_ENABLED_RESPONSE:
+ return this.updateIndicator(message.enabled);
+ }
+ }
+
+ updateIndicator(enabled) {
+ if (enabled) {
+ return indicators.enable();
+ }
+ return indicators.disable();
+ }
+}