parent
b130fd5268
commit
42d902982a
7 changed files with 77 additions and 2 deletions
@ -0,0 +1,11 @@ |
||||
import AddonEnabledInteractor from '../usecases/addon-enabled'; |
||||
|
||||
export default class AddonEnabledController { |
||||
constructor() { |
||||
this.addonEnabledInteractor = new AddonEnabledInteractor(); |
||||
} |
||||
|
||||
indicate(enabled) { |
||||
this.addonEnabledInteractor.indicate(enabled); |
||||
} |
||||
} |
@ -0,0 +1,12 @@ |
||||
export default class IndicatorPresenter { |
||||
indicate(enabled) { |
||||
let path = enabled |
||||
? 'resources/enabled_32x32.png' |
||||
: 'resources/disabled_32x32.png'; |
||||
return browser.browserAction.setIcon({ path }); |
||||
} |
||||
|
||||
onClick(listener) { |
||||
browser.browserAction.onClicked.addListener(listener); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
Reference in new issue