aboutsummaryrefslogtreecommitdiff
path: root/src/content/controllers
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-05-19 10:50:49 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2019-05-19 10:50:49 +0900
commitc81b82ee39cc05d06597e7cd024de448894efe43 (patch)
tree269611c57413e1795250bc743e4571e469682426 /src/content/controllers
parent4be04628e19392d8da9688d538cc3374e91005d8 (diff)
Make routes
Diffstat (limited to 'src/content/controllers')
-rw-r--r--src/content/controllers/ConsoleFrameController.ts16
-rw-r--r--src/content/controllers/SettingController.ts41
2 files changed, 57 insertions, 0 deletions
diff --git a/src/content/controllers/ConsoleFrameController.ts b/src/content/controllers/ConsoleFrameController.ts
new file mode 100644
index 0000000..fafadf4
--- /dev/null
+++ b/src/content/controllers/ConsoleFrameController.ts
@@ -0,0 +1,16 @@
+import ConsoleFrameUseCase from '../usecases/ConsoleFrameUseCase';
+import * as messages from '../../shared/messages';
+
+export default class ConsoleFrameController {
+ private consoleFrameUseCase: ConsoleFrameUseCase;
+
+ constructor({
+ consoleFrameUseCase = new ConsoleFrameUseCase(),
+ } = {}) {
+ this.consoleFrameUseCase = consoleFrameUseCase;
+ }
+
+ unfocus(_message: messages.Message) {
+ this.consoleFrameUseCase.unfocus();
+ }
+}
diff --git a/src/content/controllers/SettingController.ts b/src/content/controllers/SettingController.ts
new file mode 100644
index 0000000..f0e770b
--- /dev/null
+++ b/src/content/controllers/SettingController.ts
@@ -0,0 +1,41 @@
+import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase';
+import SettingUseCase from '../usecases/SettingUseCase';
+import * as blacklists from '../../shared/blacklists';
+
+import * as messages from '../../shared/messages';
+
+export default class SettingController {
+ private addonEnabledUseCase: AddonEnabledUseCase;
+
+ private settingUseCase: SettingUseCase;
+
+ constructor({
+ addonEnabledUseCase = new AddonEnabledUseCase(),
+ settingUseCase = new SettingUseCase(),
+ } = {}) {
+ this.addonEnabledUseCase = addonEnabledUseCase;
+ this.settingUseCase = settingUseCase;
+ }
+
+ async initSettings(): Promise<void> {
+ try {
+ let current = await this.settingUseCase.reload();
+ let disabled = blacklists.includes(
+ current.blacklist, window.location.href,
+ );
+ if (disabled) {
+ this.addonEnabledUseCase.disable();
+ } else {
+ this.addonEnabledUseCase.enable();
+ }
+ } catch (e) {
+ // Sometime sendMessage fails when background script is not ready.
+ console.warn(e);
+ setTimeout(() => this.initSettings(), 500);
+ }
+ }
+
+ async reloadSettings(_message: messages.Message): Promise<void> {
+ await this.settingUseCase.reload();
+ }
+}