aboutsummaryrefslogtreecommitdiff
path: root/src/background/controllers
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-05-07 21:16:47 +0900
committerGitHub <noreply@github.com>2019-05-07 21:16:47 +0900
commit05ef6a8ca35aaa801c11eb6b4896caa3690058af (patch)
tree2c7708ca91ac2b462cc86aa28612e3d3943496f3 /src/background/controllers
parent457d954e08923b4accd28a919c72d0b61db1bb98 (diff)
parent27d0a7f37d24a0ad68a8ccb7dee18fc1d00eea58 (diff)
Merge pull request #578 from ueokande/move-to-typescript
Move to TypeScript
Diffstat (limited to 'src/background/controllers')
-rw-r--r--src/background/controllers/AddonEnabledController.ts (renamed from src/background/controllers/AddonEnabledController.js)4
-rw-r--r--src/background/controllers/CommandController.ts (renamed from src/background/controllers/CommandController.js)14
-rw-r--r--src/background/controllers/FindController.ts (renamed from src/background/controllers/FindController.js)6
-rw-r--r--src/background/controllers/LinkController.js15
-rw-r--r--src/background/controllers/LinkController.ts19
-rw-r--r--src/background/controllers/MarkController.js15
-rw-r--r--src/background/controllers/MarkController.ts17
-rw-r--r--src/background/controllers/OperationController.ts (renamed from src/background/controllers/OperationController.js)15
-rw-r--r--src/background/controllers/SettingController.ts (renamed from src/background/controllers/SettingController.js)9
-rw-r--r--src/background/controllers/VersionController.ts (renamed from src/background/controllers/VersionController.js)6
-rw-r--r--src/background/controllers/version.js13
11 files changed, 76 insertions, 57 deletions
diff --git a/src/background/controllers/AddonEnabledController.js b/src/background/controllers/AddonEnabledController.ts
index 9a3a521..251af25 100644
--- a/src/background/controllers/AddonEnabledController.js
+++ b/src/background/controllers/AddonEnabledController.ts
@@ -1,11 +1,13 @@
import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase';
export default class AddonEnabledController {
+ private addonEnabledUseCase: AddonEnabledUseCase;
+
constructor() {
this.addonEnabledUseCase = new AddonEnabledUseCase();
}
- indicate(enabled) {
+ indicate(enabled: boolean): Promise<any> {
return this.addonEnabledUseCase.indicate(enabled);
}
}
diff --git a/src/background/controllers/CommandController.js b/src/background/controllers/CommandController.ts
index b113709..f3a6b7f 100644
--- a/src/background/controllers/CommandController.js
+++ b/src/background/controllers/CommandController.ts
@@ -1,19 +1,23 @@
import CompletionsUseCase from '../usecases/CompletionsUseCase';
import CommandUseCase from '../usecases/CommandUseCase';
-import Completions from '../domains/Completions';
+import CompletionGroup from '../domains/CompletionGroup';
-const trimStart = (str) => {
+const trimStart = (str: string): string => {
// NOTE String.trimStart is available on Firefox 61
return str.replace(/^\s+/, '');
};
export default class CommandController {
+ private completionsUseCase: CompletionsUseCase;
+
+ private commandIndicator: CommandUseCase;
+
constructor() {
this.completionsUseCase = new CompletionsUseCase();
this.commandIndicator = new CommandUseCase();
}
- getCompletions(line) {
+ getCompletions(line: string): Promise<CompletionGroup[]> {
let trimmed = trimStart(line);
let words = trimmed.split(/ +/);
let name = words[0];
@@ -45,11 +49,11 @@ export default class CommandController {
case 'set':
return this.completionsUseCase.querySet(name, keywords);
}
- return Promise.resolve(Completions.empty());
+ return Promise.resolve([]);
}
// eslint-disable-next-line complexity
- exec(line) {
+ exec(line: string): Promise<any> {
let trimmed = trimStart(line);
let words = trimmed.split(/ +/);
let name = words[0];
diff --git a/src/background/controllers/FindController.js b/src/background/controllers/FindController.ts
index caeff98..28959e2 100644
--- a/src/background/controllers/FindController.js
+++ b/src/background/controllers/FindController.ts
@@ -1,15 +1,17 @@
import FindUseCase from '../usecases/FindUseCase';
export default class FindController {
+ private findUseCase: FindUseCase;
+
constructor() {
this.findUseCase = new FindUseCase();
}
- getKeyword() {
+ getKeyword(): Promise<string> {
return this.findUseCase.getKeyword();
}
- setKeyword(keyword) {
+ setKeyword(keyword: string): Promise<any> {
return this.findUseCase.setKeyword(keyword);
}
}
diff --git a/src/background/controllers/LinkController.js b/src/background/controllers/LinkController.js
deleted file mode 100644
index 7e395b1..0000000
--- a/src/background/controllers/LinkController.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import LinkUseCase from '../usecases/LinkUseCase';
-
-export default class LinkController {
- constructor() {
- this.linkUseCase = new LinkUseCase();
- }
-
- openToTab(url, tabId) {
- this.linkUseCase.openToTab(url, tabId);
- }
-
- openNewTab(url, openerId, background) {
- this.linkUseCase.openNewTab(url, openerId, background);
- }
-}
diff --git a/src/background/controllers/LinkController.ts b/src/background/controllers/LinkController.ts
new file mode 100644
index 0000000..707b28a
--- /dev/null
+++ b/src/background/controllers/LinkController.ts
@@ -0,0 +1,19 @@
+import LinkUseCase from '../usecases/LinkUseCase';
+
+export default class LinkController {
+ private linkUseCase: LinkUseCase;
+
+ constructor() {
+ this.linkUseCase = new LinkUseCase();
+ }
+
+ openToTab(url: string, tabId: number): Promise<void> {
+ return this.linkUseCase.openToTab(url, tabId);
+ }
+
+ openNewTab(
+ url: string, openerId: number, background: boolean,
+ ): Promise<void> {
+ return this.linkUseCase.openNewTab(url, openerId, background);
+ }
+}
diff --git a/src/background/controllers/MarkController.js b/src/background/controllers/MarkController.js
deleted file mode 100644
index 0478369..0000000
--- a/src/background/controllers/MarkController.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import MarkUseCase from '../usecases/MarkUseCase';
-
-export default class MarkController {
- constructor() {
- this.markUseCase = new MarkUseCase();
- }
-
- setGlobal(key, x, y) {
- this.markUseCase.setGlobal(key, x, y);
- }
-
- jumpGlobal(key) {
- this.markUseCase.jumpGlobal(key);
- }
-}
diff --git a/src/background/controllers/MarkController.ts b/src/background/controllers/MarkController.ts
new file mode 100644
index 0000000..419a08b
--- /dev/null
+++ b/src/background/controllers/MarkController.ts
@@ -0,0 +1,17 @@
+import MarkUseCase from '../usecases/MarkUseCase';
+
+export default class MarkController {
+ private markUseCase: MarkUseCase;
+
+ constructor() {
+ this.markUseCase = new MarkUseCase();
+ }
+
+ setGlobal(key: string, x: number, y: number): Promise<any> {
+ return this.markUseCase.setGlobal(key, x, y);
+ }
+
+ jumpGlobal(key: string): Promise<any> {
+ return this.markUseCase.jumpGlobal(key);
+ }
+}
diff --git a/src/background/controllers/OperationController.js b/src/background/controllers/OperationController.ts
index 416aa9c..fa09512 100644
--- a/src/background/controllers/OperationController.js
+++ b/src/background/controllers/OperationController.ts
@@ -1,4 +1,4 @@
-import operations from '../../shared/operations';
+import * as operations from '../../shared/operations';
import FindUseCase from '../usecases/FindUseCase';
import ConsoleUseCase from '../usecases/ConsoleUseCase';
import TabUseCase from '../usecases/TabUseCase';
@@ -6,6 +6,16 @@ import TabSelectUseCase from '../usecases/TabSelectUseCase';
import ZoomUseCase from '../usecases/ZoomUseCase';
export default class OperationController {
+ private findUseCase: FindUseCase;
+
+ private consoleUseCase: ConsoleUseCase;
+
+ private tabUseCase: TabUseCase;
+
+ private tabSelectUseCase: TabSelectUseCase;
+
+ private zoomUseCase: ZoomUseCase;
+
constructor() {
this.findUseCase = new FindUseCase();
this.consoleUseCase = new ConsoleUseCase();
@@ -15,7 +25,7 @@ export default class OperationController {
}
// eslint-disable-next-line complexity, max-lines-per-function
- exec(operation) {
+ exec(operation: operations.Operation): Promise<any> {
switch (operation.type) {
case operations.TAB_CLOSE:
return this.tabUseCase.close(false);
@@ -72,6 +82,7 @@ export default class OperationController {
case operations.CANCEL:
return this.consoleUseCase.hideConsole();
}
+ throw new Error('unknown operation: ' + operation.type);
}
}
diff --git a/src/background/controllers/SettingController.js b/src/background/controllers/SettingController.ts
index e895d72..dfd2817 100644
--- a/src/background/controllers/SettingController.js
+++ b/src/background/controllers/SettingController.ts
@@ -1,17 +1,22 @@
import SettingUseCase from '../usecases/SettingUseCase';
import ContentMessageClient from '../infrastructures/ContentMessageClient';
+import Settings from '../../shared/Settings';
export default class SettingController {
+ private settingUseCase: SettingUseCase;
+
+ private contentMessageClient: ContentMessageClient;
+
constructor() {
this.settingUseCase = new SettingUseCase();
this.contentMessageClient = new ContentMessageClient();
}
- getSetting() {
+ getSetting(): Promise<Settings> {
return this.settingUseCase.get();
}
- async reload() {
+ async reload(): Promise<any> {
await this.settingUseCase.reload();
this.contentMessageClient.broadcastSettingsChanged();
}
diff --git a/src/background/controllers/VersionController.js b/src/background/controllers/VersionController.ts
index c596f9b..2e2a197 100644
--- a/src/background/controllers/VersionController.js
+++ b/src/background/controllers/VersionController.ts
@@ -1,11 +1,13 @@
import VersionUseCase from '../usecases/VersionUseCase';
export default class VersionController {
+ private versionUseCase: VersionUseCase;
+
constructor() {
this.versionUseCase = new VersionUseCase();
}
- notify() {
- this.versionUseCase.notify();
+ notify(): Promise<void> {
+ return this.versionUseCase.notify();
}
}
diff --git a/src/background/controllers/version.js b/src/background/controllers/version.js
deleted file mode 100644
index ec0f634..0000000
--- a/src/background/controllers/version.js
+++ /dev/null
@@ -1,13 +0,0 @@
-import VersionInteractor from '../usecases/version';
-
-export default class VersionController {
- constructor() {
- this.versionInteractor = new VersionInteractor();
- }
-
- notifyIfUpdated() {
- browser.runtime.onInstalled.addListener(() => {
- return this.versionInteractor.notify();
- });
- }
-}