diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-06 22:17:01 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-06 22:17:18 +0900 |
commit | b002d70070a1b691b635220bc694c48df36faca5 (patch) | |
tree | fd69cc7a74e30c33f33376acf7e36ce585c819d9 /src/background | |
parent | a0882bbceb7ed71d56bf8557620449fbc3f19749 (diff) |
src/content
Diffstat (limited to 'src/background')
-rw-r--r-- | src/background/repositories/BrowserSettingRepository.ts | 16 | ||||
-rw-r--r-- | src/background/usecases/MarkUseCase.ts | 17 | ||||
-rw-r--r-- | src/background/usecases/VersionUseCase.ts | 2 | ||||
-rw-r--r-- | src/background/usecases/filters.ts | 6 |
4 files changed, 29 insertions, 12 deletions
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<BrowserSettings>; +} + export default class BrowserSettingRepository { async getHomepageUrls(): Promise<string[]> { 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<any> { 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<void> { + 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; } } |