Types src/content

This commit is contained in:
Shin'ya Ueoka 2019-05-02 14:08:51 +09:00
parent 992b3ac65d
commit d01db82c0d
62 changed files with 1411 additions and 468 deletions

View file

@ -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<any> {
exec(operation: operations.Operation): Promise<any> {
switch (operation.type) {
case operations.TAB_CLOSE:
return this.tabUseCase.close(false);

View file

@ -7,7 +7,7 @@ export default class VersionController {
this.versionUseCase = new VersionUseCase();
}
notify(): void {
notify(): Promise<void> {
return this.versionUseCase.notify();
}
}

View file

@ -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 });
}

View file

@ -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<any> {

View file

@ -1,4 +1,4 @@
import messages from '../../shared/messages';
import * as messages from '../../shared/messages';
export default class ContentMessageClient {
async broadcastSettingsChanged(): Promise<void> {

View file

@ -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> | any {
onMessage(
message: messages.Message, senderTab: browser.tabs.Tab,
): Promise<any> | any {
switch (message.type) {
case messages.CONSOLE_QUERY_COMPLETIONS:
return this.onConsoleQueryCompletions(message.text);

View file

@ -1,11 +1,11 @@
const NOTIFICATION_ID = 'vimvixen-update';
export default class NotifyPresenter {
notify(
async notify(
title: string,
message: string,
onclick: () => void,
): Promise<string> {
): Promise<void> {
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,

View file

@ -12,7 +12,7 @@ export default class VersionUseCase {
this.notifyPresenter = new NotifyPresenter();
}
notify(): Promise<string> {
notify(): Promise<void> {
let title = `Vim Vixen ${manifest.version} has been installed`;
let message = 'Click here to see release notes';
let url = this.releaseNoteUrl(manifest.version);