Types on src/background
This commit is contained in:
parent
0cffb09e24
commit
678020a3a2
48 changed files with 446 additions and 431 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
import LinkUseCase from '../usecases/LinkUseCase';
|
||||
|
||||
export default class LinkController {
|
||||
private linkUseCase: LinkUseCase;
|
||||
|
||||
constructor() {
|
||||
this.linkUseCase = new LinkUseCase();
|
||||
}
|
||||
|
||||
openToTab(url, tabId) {
|
||||
this.linkUseCase.openToTab(url, tabId);
|
||||
openToTab(url: string, tabId: number): Promise<void> {
|
||||
return this.linkUseCase.openToTab(url, tabId);
|
||||
}
|
||||
|
||||
openNewTab(url, openerId, background) {
|
||||
this.linkUseCase.openNewTab(url, openerId, background);
|
||||
openNewTab(
|
||||
url: string, openerId: number, background: boolean,
|
||||
): Promise<void> {
|
||||
return this.linkUseCase.openNewTab(url, openerId, background);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
import MarkUseCase from '../usecases/MarkUseCase';
|
||||
|
||||
export default class MarkController {
|
||||
private markUseCase: MarkUseCase;
|
||||
|
||||
constructor() {
|
||||
this.markUseCase = new MarkUseCase();
|
||||
}
|
||||
|
||||
setGlobal(key, x, y) {
|
||||
this.markUseCase.setGlobal(key, x, y);
|
||||
setGlobal(key: string, x: number, y: number): Promise<any> {
|
||||
return this.markUseCase.setGlobal(key, x, y);
|
||||
}
|
||||
|
||||
jumpGlobal(key) {
|
||||
this.markUseCase.jumpGlobal(key);
|
||||
jumpGlobal(key: string): Promise<any> {
|
||||
return this.markUseCase.jumpGlobal(key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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: any): 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,16 +2,20 @@ import SettingUseCase from '../usecases/SettingUseCase';
|
|||
import ContentMessageClient from '../infrastructures/ContentMessageClient';
|
||||
|
||||
export default class SettingController {
|
||||
private settingUseCase: SettingUseCase;
|
||||
|
||||
private contentMessageClient: ContentMessageClient;
|
||||
|
||||
constructor() {
|
||||
this.settingUseCase = new SettingUseCase();
|
||||
this.contentMessageClient = new ContentMessageClient();
|
||||
}
|
||||
|
||||
getSetting() {
|
||||
getSetting(): any {
|
||||
return this.settingUseCase.get();
|
||||
}
|
||||
|
||||
async reload() {
|
||||
async reload(): Promise<any> {
|
||||
await this.settingUseCase.reload();
|
||||
this.contentMessageClient.broadcastSettingsChanged();
|
||||
}
|
||||
|
|
|
@ -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(): void {
|
||||
return this.versionUseCase.notify();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
Reference in a new issue