diff options
Diffstat (limited to 'src/background/usecases')
-rw-r--r-- | src/background/usecases/addon-enabled.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/background/usecases/addon-enabled.js b/src/background/usecases/addon-enabled.js new file mode 100644 index 0000000..37eb1c2 --- /dev/null +++ b/src/background/usecases/addon-enabled.js @@ -0,0 +1,29 @@ +import IndicatorPresenter from '../presenters/indicator'; +import TabPresenter from '../presenters/tab'; +import ContentMessageClient from '../infrastructures/content-message-client'; + +export default class AddonEnabledInteractor { + constructor() { + this.indicatorPresentor = new IndicatorPresenter(); + + this.indicatorPresentor.onClick(tab => this.onIndicatorClick(tab.id)); + + this.tabPresenter = new TabPresenter(); + this.tabPresenter.onSelected(info => this.onTabSelected(info.tabId)); + + this.contentMessageClient = new ContentMessageClient(); + } + + indicate(enabled) { + this.indicatorPresentor.indicate(enabled); + } + + onIndicatorClick(tabId) { + return this.contentMessageClient.toggleAddonEnabled(tabId); + } + + async onTabSelected(tabId) { + let enabled = await this.contentMessageClient.getAddonEnabled(tabId); + return this.indicatorPresentor.indicate(enabled); + } +} |