Indicator shows the add-on enabled
This commit is contained in:
parent
2c366ac3b1
commit
129aae38df
9 changed files with 86 additions and 3 deletions
38
src/background/components/indicator.js
Normal file
38
src/background/components/indicator.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
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.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);
|
||||
});
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ import messages from 'shared/messages';
|
|||
import BackgroundComponent from 'background/components/background';
|
||||
import OperationComponent from 'background/components/operation';
|
||||
import TabComponent from 'background/components/tab';
|
||||
import IndicatorComponent from 'background/components/indicator';
|
||||
import reducers from 'background/reducers';
|
||||
import { createStore } from 'shared/store';
|
||||
import * as versions from 'shared/versions';
|
||||
|
@ -16,12 +17,13 @@ const store = createStore(reducers, (e, sender) => {
|
|||
});
|
||||
}
|
||||
});
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
const backgroundComponent = new BackgroundComponent(store);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const operationComponent = new OperationComponent(store);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const tabComponent = new TabComponent(store);
|
||||
const indicatorComponent = new IndicatorComponent(store);
|
||||
/* eslint-enable no-unused-vars */
|
||||
|
||||
store.dispatch(settingActions.load());
|
||||
|
||||
|
|
13
src/background/shared/indicators.js
Normal file
13
src/background/shared/indicators.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
const enable = () => {
|
||||
return browser.browserAction.setIcon({
|
||||
path: 'resources/enabled_32x32.png',
|
||||
});
|
||||
};
|
||||
|
||||
const disable = () => {
|
||||
return browser.browserAction.setIcon({
|
||||
path: 'resources/disabled_32x32.png',
|
||||
});
|
||||
};
|
||||
|
||||
export { enable, disable };
|
Reference in a new issue