Toggle add-on enabled by clicking indicator

jh-changes
Shin'ya Ueoka 7 years ago
parent 129aae38df
commit 6d057a974b
  1. 7
      src/background/components/indicator.js
  2. 5
      src/content/components/common/index.js
  3. 1
      src/shared/messages.js

@ -7,6 +7,7 @@ export default class IndicatorComponent {
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);
@ -22,6 +23,12 @@ export default class IndicatorComponent {
});
}
onClicked(tab) {
browser.tabs.sendMessage(tab.id, {
type: messages.ADDON_TOGGLE_ENABLED,
});
}
onMessage(message) {
switch (message.type) {
case messages.ADDON_ENABLED_RESPONSE:

@ -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) {
@ -25,7 +26,9 @@ export default class Common {
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());
}
}

@ -50,6 +50,7 @@ export default {
ADDON_ENABLED_QUERY: 'addon.enabled.query',
ADDON_ENABLED_RESPONSE: 'addon.enabled.response',
ADDON_TOGGLE_ENABLED: 'addon.toggle.enabled',
OPEN_URL: 'open.url',