diff options
Diffstat (limited to 'src/content/components/common')
-rw-r--r-- | src/content/components/common/index.ts | 14 | ||||
-rw-r--r-- | src/content/components/common/keymapper.ts | 8 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/content/components/common/index.ts b/src/content/components/common/index.ts index 5b097b6..be77812 100644 --- a/src/content/components/common/index.ts +++ b/src/content/components/common/index.ts @@ -5,11 +5,14 @@ import KeymapperComponent from './keymapper'; import * as settingActions from '../../actions/setting'; import * as messages from '../../../shared/messages'; import MessageListener from '../../MessageListener'; -import * as addonActions from '../../actions/addon'; import * as blacklists from '../../../shared/blacklists'; import * as keys from '../../../shared/utils/keys'; import * as actions from '../../actions'; +import AddonEnabledUseCase from '../../usecases/AddonEnabledUseCase'; + +let addonEnabledUseCase = new AddonEnabledUseCase(); + export default class Common { private win: Window; @@ -34,12 +37,11 @@ export default class Common { } onMessage(message: messages.Message) { - let { enabled } = this.store.getState().addon; switch (message.type) { case messages.SETTINGS_CHANGED: return this.reloadSettings(); case messages.ADDON_TOGGLE_ENABLED: - this.store.dispatch(addonActions.setEnabled(!enabled)); + addonEnabledUseCase.toggle(); } } @@ -50,7 +52,11 @@ export default class Common { let enabled = !blacklists.includes( action.settings.blacklist, this.win.location.href ); - this.store.dispatch(addonActions.setEnabled(enabled)); + if (enabled) { + addonEnabledUseCase.enable(); + } else { + addonEnabledUseCase.disable(); + } }); } catch (e) { // Sometime sendMessage fails when background script is not ready. diff --git a/src/content/components/common/keymapper.ts b/src/content/components/common/keymapper.ts index c94bae0..02579ec 100644 --- a/src/content/components/common/keymapper.ts +++ b/src/content/components/common/keymapper.ts @@ -3,6 +3,10 @@ import * as operationActions from '../../actions/operation'; import * as operations from '../../../shared/operations'; import * as keyUtils from '../../../shared/utils/keys'; +import AddonEnabledUseCase from '../../usecases/AddonEnabledUseCase'; + +let addonEnabledUseCase = new AddonEnabledUseCase(); + const mapStartsWith = ( mapping: keyUtils.Key[], keys: keyUtils.Key[], @@ -41,7 +45,7 @@ export default class KeymapperComponent { (mapping: keyUtils.Key[]) => { return mapStartsWith(mapping, input.keys); }); - if (!state.addon.enabled) { + if (!addonEnabledUseCase.getEnabled()) { // available keymaps are only ADDON_ENABLE and ADDON_TOGGLE_ENABLED if // the addon disabled matched = matched.filter((keys) => { @@ -59,7 +63,7 @@ export default class KeymapperComponent { } let operation = keymaps.get(matched[0]) as operations.Operation; let act = operationActions.exec( - operation, state.setting, state.addon.enabled + operation, state.setting, ); this.store.dispatch(act); this.store.dispatch(inputActions.clearKeys()); |