From d01db82c0dca352de2d7644c383d388fc3ec0366 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Thu, 2 May 2019 14:08:51 +0900 Subject: Types src/content --- src/background/controllers/OperationController.ts | 4 ++-- src/background/controllers/VersionController.ts | 2 +- src/background/domains/Setting.ts | 20 ++++++++++++++------ src/background/infrastructures/ConsoleClient.ts | 2 +- .../infrastructures/ContentMessageClient.ts | 2 +- .../infrastructures/ContentMessageListener.ts | 6 ++++-- src/background/presenters/NotifyPresenter.ts | 6 +++--- src/background/usecases/VersionUseCase.ts | 2 +- 8 files changed, 27 insertions(+), 17 deletions(-) (limited to 'src/background') diff --git a/src/background/controllers/OperationController.ts b/src/background/controllers/OperationController.ts index 4e9c106..fa09512 100644 --- a/src/background/controllers/OperationController.ts +++ 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'; @@ -25,7 +25,7 @@ export default class OperationController { } // eslint-disable-next-line complexity, max-lines-per-function - exec(operation: any): Promise { + exec(operation: operations.Operation): Promise { switch (operation.type) { case operations.TAB_CLOSE: return this.tabUseCase.close(false); diff --git a/src/background/controllers/VersionController.ts b/src/background/controllers/VersionController.ts index f402ed0..2e2a197 100644 --- a/src/background/controllers/VersionController.ts +++ b/src/background/controllers/VersionController.ts @@ -7,7 +7,7 @@ export default class VersionController { this.versionUseCase = new VersionUseCase(); } - notify(): void { + notify(): Promise { return this.versionUseCase.notify(); } } diff --git a/src/background/domains/Setting.ts b/src/background/domains/Setting.ts index 106ec0f..b2b1ff2 100644 --- a/src/background/domains/Setting.ts +++ b/src/background/domains/Setting.ts @@ -1,22 +1,30 @@ import DefaultSettings from '../../shared/settings/default'; import * as settingsValues from '../../shared/settings/values'; +type SettingValue = { + source: string, + json: string, + form: any +} + export default class Setting { - constructor({ source, json, form }) { + private obj: SettingValue; + + constructor({ source, json, form }: SettingValue) { this.obj = { source, json, form }; } - get source() { + get source(): string { return this.obj.source; } - get json() { + get json(): string { return this.obj.json; } - get form() { + get form(): any { return this.obj.form; } @@ -33,11 +41,11 @@ export default class Setting { return { ...settingsValues.valueFromJson(DefaultSettings.json), ...value }; } - serialize() { + serialize(): SettingValue { return this.obj; } - static deserialize(obj) { + static deserialize(obj: SettingValue): Setting { return new Setting({ source: obj.source, json: obj.json, form: obj.form }); } diff --git a/src/background/infrastructures/ConsoleClient.ts b/src/background/infrastructures/ConsoleClient.ts index 7ad5d24..c162634 100644 --- a/src/background/infrastructures/ConsoleClient.ts +++ b/src/background/infrastructures/ConsoleClient.ts @@ -1,4 +1,4 @@ -import messages from '../../shared/messages'; +import * as messages from '../../shared/messages'; export default class ConsoleClient { showCommand(tabId: number, command: string): Promise { diff --git a/src/background/infrastructures/ContentMessageClient.ts b/src/background/infrastructures/ContentMessageClient.ts index 20057c7..d4bc476 100644 --- a/src/background/infrastructures/ContentMessageClient.ts +++ b/src/background/infrastructures/ContentMessageClient.ts @@ -1,4 +1,4 @@ -import messages from '../../shared/messages'; +import * as messages from '../../shared/messages'; export default class ContentMessageClient { async broadcastSettingsChanged(): Promise { diff --git a/src/background/infrastructures/ContentMessageListener.ts b/src/background/infrastructures/ContentMessageListener.ts index 81d3232..1cc2696 100644 --- a/src/background/infrastructures/ContentMessageListener.ts +++ b/src/background/infrastructures/ContentMessageListener.ts @@ -1,4 +1,4 @@ -import messages from '../../shared/messages'; +import * as messages from '../../shared/messages'; import CompletionGroup from '../domains/CompletionGroup'; import CommandController from '../controllers/CommandController'; import SettingController from '../controllers/SettingController'; @@ -68,7 +68,9 @@ export default class ContentMessageListener { browser.runtime.onConnect.addListener(this.onConnected.bind(this)); } - onMessage(message: any, senderTab: browser.tabs.Tab): Promise | any { + onMessage( + message: messages.Message, senderTab: browser.tabs.Tab, + ): Promise | any { switch (message.type) { case messages.CONSOLE_QUERY_COMPLETIONS: return this.onConsoleQueryCompletions(message.text); diff --git a/src/background/presenters/NotifyPresenter.ts b/src/background/presenters/NotifyPresenter.ts index c83c205..23932f7 100644 --- a/src/background/presenters/NotifyPresenter.ts +++ b/src/background/presenters/NotifyPresenter.ts @@ -1,11 +1,11 @@ const NOTIFICATION_ID = 'vimvixen-update'; export default class NotifyPresenter { - notify( + async notify( title: string, message: string, onclick: () => void, - ): Promise { + ): Promise { const listener = (id: string) => { if (id !== NOTIFICATION_ID) { return; @@ -17,7 +17,7 @@ export default class NotifyPresenter { }; browser.notifications.onClicked.addListener(listener); - return browser.notifications.create(NOTIFICATION_ID, { + await browser.notifications.create(NOTIFICATION_ID, { 'type': 'basic', 'iconUrl': browser.extension.getURL('resources/icon_48x48.png'), title, diff --git a/src/background/usecases/VersionUseCase.ts b/src/background/usecases/VersionUseCase.ts index 207f9e2..3a3cc2e 100644 --- a/src/background/usecases/VersionUseCase.ts +++ b/src/background/usecases/VersionUseCase.ts @@ -12,7 +12,7 @@ export default class VersionUseCase { this.notifyPresenter = new NotifyPresenter(); } - notify(): Promise { + notify(): Promise { let title = `Vim Vixen ${manifest.version} has been installed`; let message = 'Click here to see release notes'; let url = this.releaseNoteUrl(manifest.version); -- cgit v1.2.3