From b002d70070a1b691b635220bc694c48df36faca5 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 6 May 2019 22:17:01 +0900 Subject: src/content --- src/background/repositories/BrowserSettingRepository.ts | 16 ++++++++++++++++ src/background/usecases/MarkUseCase.ts | 17 ++++++++--------- src/background/usecases/VersionUseCase.ts | 2 +- src/background/usecases/filters.ts | 6 ++++-- 4 files changed, 29 insertions(+), 12 deletions(-) (limited to 'src/background') diff --git a/src/background/repositories/BrowserSettingRepository.ts b/src/background/repositories/BrowserSettingRepository.ts index 48c72a5..33b35dd 100644 --- a/src/background/repositories/BrowserSettingRepository.ts +++ b/src/background/repositories/BrowserSettingRepository.ts @@ -1,5 +1,21 @@ import * as urls from '../../shared/urls'; +declare namespace browser.browserSettings.homepageOverride { + + type BrowserSettings = { + value: string; + levelOfControl: LevelOfControlType; + }; + + type LevelOfControlType = + 'not_controllable' | + 'controlled_by_other_extensions' | + 'controllable_by_this_extension' | + 'controlled_by_this_extension'; + + function get(param: object): Promise; +} + export default class BrowserSettingRepository { async getHomepageUrls(): Promise { let { value } = await browser.browserSettings.homepageOverride.get({}); diff --git a/src/background/usecases/MarkUseCase.ts b/src/background/usecases/MarkUseCase.ts index 8b544aa..e376c55 100644 --- a/src/background/usecases/MarkUseCase.ts +++ b/src/background/usecases/MarkUseCase.ts @@ -21,7 +21,7 @@ export default class MarkUseCase { async setGlobal(key: string, x: number, y: number): Promise { let tab = await this.tabPresenter.getCurrent(); - let mark = { tabId: tab.id, url: tab.url, x, y }; + let mark = { tabId: tab.id as number, url: tab.url as string, x, y }; return this.markRepository.setMark(key, mark); } @@ -33,15 +33,14 @@ export default class MarkUseCase { return this.consoleClient.showError( current.id as number, 'Mark is not set'); } - - return this.contentMessageClient.scrollTo( - mark.tabId, mark.x, mark.y - ).then(() => { + try { + await this.contentMessageClient.scrollTo(mark.tabId, mark.x, mark.y); return this.tabPresenter.select(mark.tabId); - }).catch(async() => { + } catch (e) { let tab = await this.tabPresenter.create(mark.url); - let mark2 = { tabId: tab.id, url: mark.url, x: mark.x, y: mark.y }; - return this.markRepository.setMark(key, mark2); - }); + return this.markRepository.setMark(key, { + tabId: tab.id as number, url: mark.url, x: mark.x, y: mark.y, + }); + } } } diff --git a/src/background/usecases/VersionUseCase.ts b/src/background/usecases/VersionUseCase.ts index 3a3cc2e..8154eba 100644 --- a/src/background/usecases/VersionUseCase.ts +++ b/src/background/usecases/VersionUseCase.ts @@ -1,4 +1,3 @@ -import manifest from '../../../manifest.json'; import TabPresenter from '../presenters/TabPresenter'; import NotifyPresenter from '../presenters/NotifyPresenter'; @@ -13,6 +12,7 @@ export default class VersionUseCase { } notify(): Promise { + let manifest = browser.runtime.getManifest(); let title = `Vim Vixen ${manifest.version} has been installed`; let message = 'Click here to see release notes'; let url = this.releaseNoteUrl(manifest.version); diff --git a/src/background/usecases/filters.ts b/src/background/usecases/filters.ts index 44eb56f..84a42fb 100644 --- a/src/background/usecases/filters.ts +++ b/src/background/usecases/filters.ts @@ -40,7 +40,8 @@ const filterByPathname = (items: Item[], min: number): Item[] => { let pathname = url.origin + url.pathname; if (!hash[pathname]) { hash[pathname] = item; - } else if (hash[pathname].url.length > item.url.length) { + } else if ((hash[pathname].url as string).length > + (item.url as string).length) { hash[pathname] = item; } } @@ -57,7 +58,8 @@ const filterByOrigin = (items: Item[], min: number): Item[] => { let origin = new URL(item.url as string).origin; if (!hash[origin]) { hash[origin] = item; - } else if (hash[origin].url.length > item.url.length) { + } else if ((hash[origin].url as string).length > + (item.url as string).length) { hash[origin] = item; } } -- cgit v1.2.3