aboutsummaryrefslogtreecommitdiff
path: root/src/background
diff options
context:
space:
mode:
Diffstat (limited to 'src/background')
-rw-r--r--src/background/controllers/addon-enabled.js11
-rw-r--r--src/background/index.js2
-rw-r--r--src/background/infrastructures/content-message-client.js13
-rw-r--r--src/background/infrastructures/content-message-listener.js8
-rw-r--r--src/background/presenters/indicator.js12
-rw-r--r--src/background/presenters/tab.js4
-rw-r--r--src/background/usecases/addon-enabled.js29
7 files changed, 77 insertions, 2 deletions
diff --git a/src/background/controllers/addon-enabled.js b/src/background/controllers/addon-enabled.js
new file mode 100644
index 0000000..0f5d801
--- /dev/null
+++ b/src/background/controllers/addon-enabled.js
@@ -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);
+ }
+}
diff --git a/src/background/index.js b/src/background/index.js
index e753c48..70d514f 100644
--- a/src/background/index.js
+++ b/src/background/index.js
@@ -1,7 +1,6 @@
import BackgroundComponent from 'background/components/background';
import OperationComponent from 'background/components/operation';
import TabComponent from 'background/components/tab';
-import IndicatorComponent from 'background/components/indicator';
import reducers from 'background/reducers';
import { createStore, applyMiddleware } from 'redux';
import promise from 'redux-promise';
@@ -19,7 +18,6 @@ const store = createStore(
const backgroundComponent = new BackgroundComponent(store);
const operationComponent = new OperationComponent(store);
const tabComponent = new TabComponent(store);
-const indicatorComponent = new IndicatorComponent(store);
/* eslint-enable no-unused-vars */
new SettingController().reload();
diff --git a/src/background/infrastructures/content-message-client.js b/src/background/infrastructures/content-message-client.js
index b3b37b4..d659560 100644
--- a/src/background/infrastructures/content-message-client.js
+++ b/src/background/infrastructures/content-message-client.js
@@ -9,4 +9,17 @@ export default class ContentMessageClient {
});
}
}
+
+ async getAddonEnabled(tabId) {
+ let { enabled } = await browser.tabs.sendMessage(tabId, {
+ type: messages.ADDON_ENABLED_QUERY,
+ });
+ return enabled;
+ }
+
+ toggleAddonEnabled(tabId) {
+ return browser.tabs.sendMessage(tabId, {
+ type: messages.ADDON_TOGGLE_ENABLED,
+ });
+ }
}
diff --git a/src/background/infrastructures/content-message-listener.js b/src/background/infrastructures/content-message-listener.js
index 00dba51..8a361c1 100644
--- a/src/background/infrastructures/content-message-listener.js
+++ b/src/background/infrastructures/content-message-listener.js
@@ -2,12 +2,14 @@ import messages from '../../shared/messages';
import CompletionsController from '../controllers/completions';
import SettingController from '../controllers/setting';
import FindController from '../controllers/find';
+import AddonEnabledController from '../controllers/addon-enabled';
export default class ContentMessageListener {
constructor() {
this.settingController = new SettingController();
this.completionsController = new CompletionsController();
this.findController = new FindController();
+ this.addonEnabledController = new AddonEnabledController();
}
run() {
@@ -35,6 +37,8 @@ export default class ContentMessageListener {
return this.onFindGetKeyword();
case messages.FIND_SET_KEYWORD:
return this.onFindSetKeyword(message.keyword);
+ case messages.ADDON_ENABLED_RESPONSE:
+ return this.onAddonEnabledResponse(message.enabled);
}
}
@@ -58,4 +62,8 @@ export default class ContentMessageListener {
onFindSetKeyword(keyword) {
return this.findController.setKeyword(keyword);
}
+
+ onAddonEnabledResponse(enabled) {
+ return this.addonEnabledController.indicate(enabled);
+ }
}
diff --git a/src/background/presenters/indicator.js b/src/background/presenters/indicator.js
new file mode 100644
index 0000000..5737519
--- /dev/null
+++ b/src/background/presenters/indicator.js
@@ -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);
+ }
+}
diff --git a/src/background/presenters/tab.js b/src/background/presenters/tab.js
index 8f60535..6120f6e 100644
--- a/src/background/presenters/tab.js
+++ b/src/background/presenters/tab.js
@@ -2,4 +2,8 @@ export default class TabPresenter {
create(url) {
browser.tabs.create({ url, });
}
+
+ onSelected(listener) {
+ browser.tabs.onActivated.addListener(listener);
+ }
}
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);
+ }
+}