aboutsummaryrefslogtreecommitdiff
path: root/src/content/components/common/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/components/common/index.ts')
-rw-r--r--src/content/components/common/index.ts36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/content/components/common/index.ts b/src/content/components/common/index.ts
index be77812..899953d 100644
--- a/src/content/components/common/index.ts
+++ b/src/content/components/common/index.ts
@@ -2,22 +2,18 @@ import InputComponent from './input';
import FollowComponent from './follow';
import MarkComponent from './mark';
import KeymapperComponent from './keymapper';
-import * as settingActions from '../../actions/setting';
import * as messages from '../../../shared/messages';
import MessageListener from '../../MessageListener';
import * as blacklists from '../../../shared/blacklists';
import * as keys from '../../../shared/utils/keys';
-import * as actions from '../../actions';
import AddonEnabledUseCase from '../../usecases/AddonEnabledUseCase';
+import SettingUseCase from '../../usecases/SettingUseCase';
let addonEnabledUseCase = new AddonEnabledUseCase();
+let settingUseCase = new SettingUseCase();
export default class Common {
- private win: Window;
-
- private store: any;
-
constructor(win: Window, store: any) {
const input = new InputComponent(win.document.body);
const follow = new FollowComponent(win);
@@ -28,9 +24,6 @@ export default class Common {
input.onKey((key: keys.Key) => mark.key(key));
input.onKey((key: keys.Key) => keymapper.key(key));
- this.win = win;
- this.store = store;
-
this.reloadSettings();
new MessageListener().onBackgroundMessage(this.onMessage.bind(this));
@@ -41,23 +34,22 @@ export default class Common {
case messages.SETTINGS_CHANGED:
return this.reloadSettings();
case messages.ADDON_TOGGLE_ENABLED:
- addonEnabledUseCase.toggle();
+ return addonEnabledUseCase.toggle();
}
+ return undefined;
}
- reloadSettings() {
+ async reloadSettings() {
try {
- this.store.dispatch(settingActions.load())
- .then((action: actions.SettingAction) => {
- let enabled = !blacklists.includes(
- action.settings.blacklist, this.win.location.href
- );
- if (enabled) {
- addonEnabledUseCase.enable();
- } else {
- addonEnabledUseCase.disable();
- }
- });
+ let current = await settingUseCase.reload();
+ let disabled = blacklists.includes(
+ current.blacklist, window.location.href,
+ );
+ if (disabled) {
+ addonEnabledUseCase.disable();
+ } else {
+ addonEnabledUseCase.enable();
+ }
} catch (e) {
// Sometime sendMessage fails when background script is not ready.
console.warn(e);