aboutsummaryrefslogtreecommitdiff
path: root/src/content/components/common/index.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-07-13 22:36:56 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-07-13 22:36:56 +0900
commit944dea59199fa03f77e0e7c0d3c02acf8ccb458f (patch)
tree5f44471cdb32376a8c93e6f6eba738180f08c96f /src/content/components/common/index.js
parent77b4e807e2a8b3e7ddb5f042719a34962a31b1c4 (diff)
parent28bfa3ac8124d3453cd539db26da4f4703e783df (diff)
Merge remote-tracking branch 'origin/master' into greenkeeper/css-loader-1.0.0
Diffstat (limited to 'src/content/components/common/index.js')
-rw-r--r--src/content/components/common/index.js29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js
index 6437011..a1e71a1 100644
--- a/src/content/components/common/index.js
+++ b/src/content/components/common/index.js
@@ -4,6 +4,7 @@ import FollowComponent from './follow';
import * as settingActions from 'content/actions/setting';
import messages from 'shared/messages';
import * as addonActions from '../../actions/addon';
+import * as blacklists from 'shared/blacklists';
export default class Common {
constructor(win, store) {
@@ -14,42 +15,34 @@ export default class Common {
input.onKey(key => follow.key(key));
input.onKey(key => keymapper.key(key));
+ this.win = win;
this.store = store;
this.prevEnabled = undefined;
+ this.prevBlacklist = undefined;
this.reloadSettings();
messages.onMessage(this.onMessage.bind(this));
- store.subscribe(() => this.update());
}
onMessage(message) {
+ let { enabled } = this.store.getState().addon;
switch (message.type) {
case messages.SETTINGS_CHANGED:
return this.reloadSettings();
case messages.ADDON_TOGGLE_ENABLED:
- return this.store.dispatch(addonActions.toggleEnabled());
+ this.store.dispatch(addonActions.setEnabled(!enabled));
}
}
- update() {
- let enabled = this.store.getState().addon.enabled;
- if (enabled !== this.prevEnabled) {
- this.prevEnabled = enabled;
-
- browser.runtime.sendMessage({
- type: messages.ADDON_ENABLED_RESPONSE,
- enabled,
- });
- }
- }
-
- async reloadSettings() {
+ reloadSettings() {
try {
- let settings = await browser.runtime.sendMessage({
- type: messages.SETTINGS_QUERY,
+ this.store.dispatch(settingActions.load()).then(({ value: settings }) => {
+ let enabled = !blacklists.includes(
+ settings.blacklist, this.win.location.href
+ );
+ this.store.dispatch(addonActions.setEnabled(enabled));
});
- this.store.dispatch(settingActions.set(settings));
} catch (e) {
// Sometime sendMessage fails when background script is not ready.
console.warn(e);