aboutsummaryrefslogtreecommitdiff
path: root/src/background
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-04-13 20:37:36 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2020-04-13 20:37:36 +0900
commite1dac618a8b8929f601c7ec8aca3842c5ebf9d03 (patch)
tree6a914a8243c8c02e7752a83667a54d3fa832955c /src/background
parent685f2b7b69218b06b5bb676069e35f79c5048c9b (diff)
Use plugin:prettier/recommended
Diffstat (limited to 'src/background')
-rw-r--r--src/background/Application.ts16
-rw-r--r--src/background/clients/NavigateClient.ts4
-rw-r--r--src/background/completion/BookmarkRepository.ts6
-rw-r--r--src/background/completion/HistoryRepository.ts6
-rw-r--r--src/background/completion/OpenCompletionUseCase.ts48
-rw-r--r--src/background/completion/PropertyCompletionUseCase.ts8
-rw-r--r--src/background/completion/TabCompletionUseCase.ts27
-rw-r--r--src/background/completion/TabItem.ts14
-rw-r--r--src/background/completion/TabRepository.ts16
-rw-r--r--src/background/completion/impl/BookmarkRepositoryImpl.ts29
-rw-r--r--src/background/completion/impl/HistoryRepositoryImpl.ts49
-rw-r--r--src/background/completion/impl/PrefetchAndCache.ts37
-rw-r--r--src/background/completion/impl/TabRepositoryImpl.ts27
-rw-r--r--src/background/completion/impl/filters.ts45
-rw-r--r--src/background/controllers/AddonEnabledController.ts10
-rw-r--r--src/background/controllers/CommandController.ts87
-rw-r--r--src/background/controllers/CompletionController.ts26
-rw-r--r--src/background/controllers/FindController.ts9
-rw-r--r--src/background/controllers/LinkController.ts13
-rw-r--r--src/background/controllers/MarkController.ts9
-rw-r--r--src/background/controllers/OperationController.ts191
-rw-r--r--src/background/controllers/SettingController.ts13
-rw-r--r--src/background/controllers/VersionController.ts9
-rw-r--r--src/background/di.ts31
-rw-r--r--src/background/index.ts8
-rw-r--r--src/background/infrastructures/ConsoleClient.ts7
-rw-r--r--src/background/infrastructures/ContentMessageClient.ts8
-rw-r--r--src/background/infrastructures/ContentMessageListener.ts153
-rw-r--r--src/background/infrastructures/MemoryStorage.ts6
-rw-r--r--src/background/presenters/HelpPresenter.ts4
-rw-r--r--src/background/presenters/IndicatorPresenter.ts9
-rw-r--r--src/background/presenters/Notifier.ts17
-rw-r--r--src/background/presenters/TabPresenter.ts35
-rw-r--r--src/background/presenters/WindowPresenter.ts2
-rw-r--r--src/background/repositories/BookmarkRepository.ts9
-rw-r--r--src/background/repositories/BrowserSettingRepository.ts15
-rw-r--r--src/background/repositories/CachedSettingRepository.ts39
-rw-r--r--src/background/repositories/FindRepository.ts7
-rw-r--r--src/background/repositories/MarkRepository.ts9
-rw-r--r--src/background/repositories/RepeatRepository.ts8
-rw-r--r--src/background/repositories/SettingRepository.ts12
-rw-r--r--src/background/usecases/AddonEnabledUseCase.ts12
-rw-r--r--src/background/usecases/CommandUseCase.ts54
-rw-r--r--src/background/usecases/ConsoleUseCase.ts34
-rw-r--r--src/background/usecases/FindUseCase.ts15
-rw-r--r--src/background/usecases/LinkUseCase.ts15
-rw-r--r--src/background/usecases/MarkUseCase.ts26
-rw-r--r--src/background/usecases/NavigateUseCase.ts21
-rw-r--r--src/background/usecases/RepeatUseCase.ts55
-rw-r--r--src/background/usecases/SettingUseCase.ts29
-rw-r--r--src/background/usecases/TabSelectUseCase.ts15
-rw-r--r--src/background/usecases/TabUseCase.ts29
-rw-r--r--src/background/usecases/VersionUseCase.ts15
-rw-r--r--src/background/usecases/ZoomUseCase.ts31
-rw-r--r--src/background/usecases/parsers.ts35
55 files changed, 757 insertions, 707 deletions
diff --git a/src/background/Application.ts b/src/background/Application.ts
index c2c48b5..69fe4a4 100644
--- a/src/background/Application.ts
+++ b/src/background/Application.ts
@@ -1,7 +1,7 @@
-import { injectable, inject } from 'tsyringe';
-import ContentMessageListener from './infrastructures/ContentMessageListener';
-import SettingController from './controllers/SettingController';
-import VersionController from './controllers/VersionController';
+import { injectable, inject } from "tsyringe";
+import ContentMessageListener from "./infrastructures/ContentMessageListener";
+import SettingController from "./controllers/SettingController";
+import VersionController from "./controllers/VersionController";
import SettingRepository from "./repositories/SettingRepository";
@injectable()
@@ -10,15 +10,15 @@ export default class Application {
private contentMessageListener: ContentMessageListener,
private settingController: SettingController,
private versionController: VersionController,
- @inject("SyncSettingRepository") private syncSettingRepository: SettingRepository,
- ) {
- }
+ @inject("SyncSettingRepository")
+ private syncSettingRepository: SettingRepository
+ ) {}
run() {
this.settingController.reload();
browser.runtime.onInstalled.addListener((details) => {
- if (details.reason !== 'install' && details.reason !== 'update') {
+ if (details.reason !== "install" && details.reason !== "update") {
return;
}
this.versionController.notify();
diff --git a/src/background/clients/NavigateClient.ts b/src/background/clients/NavigateClient.ts
index bdd94ec..40ceb45 100644
--- a/src/background/clients/NavigateClient.ts
+++ b/src/background/clients/NavigateClient.ts
@@ -1,5 +1,5 @@
-import { injectable } from 'tsyringe';
-import * as messages from '../../shared/messages';
+import { injectable } from "tsyringe";
+import * as messages from "../../shared/messages";
@injectable()
export default class NavigateClient {
diff --git a/src/background/completion/BookmarkRepository.ts b/src/background/completion/BookmarkRepository.ts
index 14105c8..4dec12e 100644
--- a/src/background/completion/BookmarkRepository.ts
+++ b/src/background/completion/BookmarkRepository.ts
@@ -1,7 +1,7 @@
export type BookmarkItem = {
- title: string
- url: string
-}
+ title: string;
+ url: string;
+};
export default interface BookmarkRepository {
queryBookmarks(query: string): Promise<BookmarkItem[]>;
diff --git a/src/background/completion/HistoryRepository.ts b/src/background/completion/HistoryRepository.ts
index 5eb3a2b..446d110 100644
--- a/src/background/completion/HistoryRepository.ts
+++ b/src/background/completion/HistoryRepository.ts
@@ -1,7 +1,7 @@
export type HistoryItem = {
- title: string
- url: string
-}
+ title: string;
+ url: string;
+};
export default interface HistoryRepository {
queryHistories(keywords: string): Promise<HistoryItem[]>;
diff --git a/src/background/completion/OpenCompletionUseCase.ts b/src/background/completion/OpenCompletionUseCase.ts
index 1b63e7c..e678c2f 100644
--- a/src/background/completion/OpenCompletionUseCase.ts
+++ b/src/background/completion/OpenCompletionUseCase.ts
@@ -5,38 +5,39 @@ import BookmarkRepository from "./BookmarkRepository";
import HistoryRepository from "./HistoryRepository";
export type BookmarkItem = {
- title: string
- url: string
-}
+ title: string;
+ url: string;
+};
export type HistoryItem = {
- title: string
- url: string
-}
+ title: string;
+ url: string;
+};
@injectable()
export default class OpenCompletionUseCase {
constructor(
- @inject('BookmarkRepository') private bookmarkRepository: BookmarkRepository,
- @inject('HistoryRepository') private historyRepository: HistoryRepository,
- @inject("CachedSettingRepository") private cachedSettingRepository: CachedSettingRepository,
- ) {
- }
+ @inject("BookmarkRepository")
+ private bookmarkRepository: BookmarkRepository,
+ @inject("HistoryRepository") private historyRepository: HistoryRepository,
+ @inject("CachedSettingRepository")
+ private cachedSettingRepository: CachedSettingRepository
+ ) {}
async getCompletionTypes(): Promise<CompletionType[]> {
const settings = await this.cachedSettingRepository.get();
const types: CompletionType[] = [];
for (const c of settings.properties.complete) {
switch (c) {
- case 's':
- types.push(CompletionType.SearchEngines);
- break;
- case 'h':
- types.push(CompletionType.History);
- break;
- case 'b':
- types.push(CompletionType.Bookmarks);
- break;
+ case "s":
+ types.push(CompletionType.SearchEngines);
+ break;
+ case "h":
+ types.push(CompletionType.History);
+ break;
+ case "b":
+ types.push(CompletionType.Bookmarks);
+ break;
}
// ignore invalid characters in the complete property
}
@@ -45,8 +46,9 @@ export default class OpenCompletionUseCase {
async requestSearchEngines(query: string): Promise<string[]> {
const settings = await this.cachedSettingRepository.get();
- return Object.keys(settings.search.engines)
- .filter(key => key.startsWith(query))
+ return Object.keys(settings.search.engines).filter((key) =>
+ key.startsWith(query)
+ );
}
requestBookmarks(query: string): Promise<BookmarkItem[]> {
@@ -56,4 +58,4 @@ export default class OpenCompletionUseCase {
requestHistory(query: string): Promise<HistoryItem[]> {
return this.historyRepository.queryHistories(query);
}
-} \ No newline at end of file
+}
diff --git a/src/background/completion/PropertyCompletionUseCase.ts b/src/background/completion/PropertyCompletionUseCase.ts
index 049cfb8..7b72259 100644
--- a/src/background/completion/PropertyCompletionUseCase.ts
+++ b/src/background/completion/PropertyCompletionUseCase.ts
@@ -3,14 +3,14 @@ import Properties from "../../shared/settings/Properties";
type Property = {
name: string;
- type: 'string' | 'boolean' | 'number';
-}
+ type: "string" | "boolean" | "number";
+};
@injectable()
export default class PropertyCompletionUseCase {
async getProperties(): Promise<Property[]> {
- return Properties.defs().map(def => ({
+ return Properties.defs().map((def) => ({
name: def.name,
type: def.type,
}));
}
-} \ No newline at end of file
+}
diff --git a/src/background/completion/TabCompletionUseCase.ts b/src/background/completion/TabCompletionUseCase.ts
index dec86e9..d0d3bb7 100644
--- a/src/background/completion/TabCompletionUseCase.ts
+++ b/src/background/completion/TabCompletionUseCase.ts
@@ -7,10 +7,9 @@ import TabFlag from "../../shared/TabFlag";
@injectable()
export default class TabCompletionUseCase {
constructor(
- @inject('TabRepository') private tabRepository: TabRepository,
- @inject('TabPresenter') private tabPresenter: TabPresenter,
- ) {
- }
+ @inject("TabRepository") private tabRepository: TabRepository,
+ @inject("TabPresenter") private tabPresenter: TabPresenter
+ ) {}
async queryTabs(query: string, excludePinned: boolean): Promise<TabItem[]> {
const lastTabId = await this.tabPresenter.getLastSelectedId();
@@ -18,17 +17,17 @@ export default class TabCompletionUseCase {
const num = parseInt(query, 10);
let tabs: Tab[] = [];
if (!isNaN(num)) {
- const tab = allTabs.find(t => t.index === num - 1);
+ const tab = allTabs.find((t) => t.index === num - 1);
if (tab) {
tabs = [tab];
}
- } else if (query == '%') {
- const tab = allTabs.find(t => t.active);
+ } else if (query == "%") {
+ const tab = allTabs.find((t) => t.active);
if (tab) {
tabs = [tab];
}
- } else if (query == '#') {
- const tab = allTabs.find(t => t.id === lastTabId);
+ } else if (query == "#") {
+ const tab = allTabs.find((t) => t.id === lastTabId);
if (tab) {
tabs = [tab];
}
@@ -36,20 +35,20 @@ export default class TabCompletionUseCase {
tabs = await this.tabRepository.queryTabs(query, excludePinned);
}
- return tabs.map(tab => {
+ return tabs.map((tab) => {
let flag = TabFlag.None;
if (tab.active) {
- flag = TabFlag.CurrentTab
+ flag = TabFlag.CurrentTab;
} else if (tab.id == lastTabId) {
- flag = TabFlag.LastTab
+ flag = TabFlag.LastTab;
}
return {
index: tab.index + 1,
flag: flag,
title: tab.title,
url: tab.url,
- faviconUrl : tab.faviconUrl
- }
+ faviconUrl: tab.faviconUrl,
+ };
});
}
}
diff --git a/src/background/completion/TabItem.ts b/src/background/completion/TabItem.ts
index 630855a..eb7b657 100644
--- a/src/background/completion/TabItem.ts
+++ b/src/background/completion/TabItem.ts
@@ -1,11 +1,11 @@
import TabFlag from "../../shared/TabFlag";
type TabItem = {
- index: number
- flag: TabFlag
- title: string
- url: string
- faviconUrl?: string
-}
+ index: number;
+ flag: TabFlag;
+ title: string;
+ url: string;
+ faviconUrl?: string;
+};
-export default TabItem; \ No newline at end of file
+export default TabItem;
diff --git a/src/background/completion/TabRepository.ts b/src/background/completion/TabRepository.ts
index fe1b601..57dbf21 100644
--- a/src/background/completion/TabRepository.ts
+++ b/src/background/completion/TabRepository.ts
@@ -1,14 +1,14 @@
export type Tab = {
- id: number
- index: number
- active: boolean
- title: string
- url: string
- faviconUrl?: string
-}
+ id: number;
+ index: number;
+ active: boolean;
+ title: string;
+ url: string;
+ faviconUrl?: string;
+};
export default interface TabRepository {
queryTabs(query: string, excludePinned: boolean): Promise<Tab[]>;
- getAllTabs(excludePinned: boolean): Promise<Tab[]>
+ getAllTabs(excludePinned: boolean): Promise<Tab[]>;
}
diff --git a/src/background/completion/impl/BookmarkRepositoryImpl.ts b/src/background/completion/impl/BookmarkRepositoryImpl.ts
index 3b80b93..2bc779d 100644
--- a/src/background/completion/impl/BookmarkRepositoryImpl.ts
+++ b/src/background/completion/impl/BookmarkRepositoryImpl.ts
@@ -1,5 +1,5 @@
-import BookmarkRepository, {BookmarkItem} from "../BookmarkRepository";
-import {HistoryItem} from "../HistoryRepository";
+import BookmarkRepository, { BookmarkItem } from "../BookmarkRepository";
+import { HistoryItem } from "../HistoryRepository";
import PrefetchAndCache from "./PrefetchAndCache";
const COMPLETION_ITEM_LIMIT = 10;
@@ -8,7 +8,7 @@ export default class CachedBookmarkRepository implements BookmarkRepository {
private bookmarkCache: PrefetchAndCache<BookmarkItem>;
constructor() {
- this.bookmarkCache = new PrefetchAndCache(this.getter, this.filter, 10,);
+ this.bookmarkCache = new PrefetchAndCache(this.getter, this.filter, 10);
}
queryBookmarks(query: string): Promise<BookmarkItem[]> {
@@ -16,10 +16,10 @@ export default class CachedBookmarkRepository implements BookmarkRepository {
}
private async getter(query: string): Promise<BookmarkItem[]> {
- const items = await browser.bookmarks.search({query});
+ const items = await browser.bookmarks.search({ query });
return items
- .filter(item => item.title && item.title.length > 0)
- .filter(item => item.type === 'bookmark' && item.url)
+ .filter((item) => item.title && item.title.length > 0)
+ .filter((item) => item.type === "bookmark" && item.url)
.filter((item) => {
let url = undefined;
try {
@@ -27,20 +27,23 @@ export default class CachedBookmarkRepository implements BookmarkRepository {
} catch (e) {
return false;
}
- return url.protocol !== 'place:';
+ return url.protocol !== "place:";
})
.slice(0, COMPLETION_ITEM_LIMIT)
- .map(item => ({
+ .map((item) => ({
title: item.title!!,
url: item.url!!,
}));
}
private filter(items: HistoryItem[], query: string) {
- return items.filter(item => {
- return query.split(' ').every(keyword => {
- return item.title.toLowerCase().includes(keyword.toLowerCase()) || item.url!!.includes(keyword)
+ return items.filter((item) => {
+ return query.split(" ").every((keyword) => {
+ return (
+ item.title.toLowerCase().includes(keyword.toLowerCase()) ||
+ item.url!!.includes(keyword)
+ );
});
- })
- };
+ });
+ }
}
diff --git a/src/background/completion/impl/HistoryRepositoryImpl.ts b/src/background/completion/impl/HistoryRepositoryImpl.ts
index cd55cd0..b1992a4 100644
--- a/src/background/completion/impl/HistoryRepositoryImpl.ts
+++ b/src/background/completion/impl/HistoryRepositoryImpl.ts
@@ -1,5 +1,5 @@
import * as filters from "./filters";
-import HistoryRepository, {HistoryItem} from "../HistoryRepository";
+import HistoryRepository, { HistoryItem } from "../HistoryRepository";
import PrefetchAndCache from "./PrefetchAndCache";
const COMPLETION_ITEM_LIMIT = 10;
@@ -8,13 +8,17 @@ export default class CachedHistoryRepository implements HistoryRepository {
private historyCache: PrefetchAndCache<browser.history.HistoryItem>;
constructor() {
- this.historyCache = new PrefetchAndCache(this.getter, this.filter, 10)
+ this.historyCache = new PrefetchAndCache(this.getter, this.filter, 10);
}
async queryHistories(keywords: string): Promise<HistoryItem[]> {
const items = await this.historyCache.get(keywords);
- const filterOrKeep = <T>(source: T[], filter: (items: T[]) => T[], min: number): T[] => {
+ const filterOrKeep = <T>(
+ source: T[],
+ filter: (items: T[]) => T[],
+ min: number
+ ): T[] => {
const filtered = filter(source);
if (filtered.length < min) {
return source;
@@ -23,17 +27,23 @@ export default class CachedHistoryRepository implements HistoryRepository {
};
return [items]
- .map(items => filterOrKeep(items, filters.filterByPathname, COMPLETION_ITEM_LIMIT))
- .map(items => filterOrKeep(items, filters.filterByOrigin, COMPLETION_ITEM_LIMIT))[0]
- .sort((x, y) => Number(y.visitCount) - Number(x.visitCount))
- .slice(0, COMPLETION_ITEM_LIMIT)
- .map(item => ({
- title: item.title!!,
- url: item.url!!,
- }));
+ .map((items) =>
+ filterOrKeep(items, filters.filterByPathname, COMPLETION_ITEM_LIMIT)
+ )
+ .map((items) =>
+ filterOrKeep(items, filters.filterByOrigin, COMPLETION_ITEM_LIMIT)
+ )[0]
+ .sort((x, y) => Number(y.visitCount) - Number(x.visitCount))
+ .slice(0, COMPLETION_ITEM_LIMIT)
+ .map((item) => ({
+ title: item.title!!,
+ url: item.url!!,
+ }));
}
- private async getter (keywords: string): Promise<browser.history.HistoryItem[]> {
+ private async getter(
+ keywords: string
+ ): Promise<browser.history.HistoryItem[]> {
const items = await browser.history.search({
text: keywords,
startTime: 0,
@@ -42,14 +52,17 @@ export default class CachedHistoryRepository implements HistoryRepository {
return [items]
.map(filters.filterBlankTitle)
.map(filters.filterHttp)
- .map(filters.filterByTailingSlash)[0]
+ .map(filters.filterByTailingSlash)[0];
}
private filter(items: browser.history.HistoryItem[], query: string) {
- return items.filter(item => {
- return query.split(' ').every(keyword => {
- return item.title!!.toLowerCase().includes(keyword.toLowerCase()) || item.url!!.includes(keyword)
+ return items.filter((item) => {
+ return query.split(" ").every((keyword) => {
+ return (
+ item.title!!.toLowerCase().includes(keyword.toLowerCase()) ||
+ item.url!!.includes(keyword)
+ );
});
- })
- };
+ });
+ }
}
diff --git a/src/background/completion/impl/PrefetchAndCache.ts b/src/background/completion/impl/PrefetchAndCache.ts
index 3c074c2..d2889b0 100644
--- a/src/background/completion/impl/PrefetchAndCache.ts
+++ b/src/background/completion/impl/PrefetchAndCache.ts
@@ -5,14 +5,14 @@ const WHITESPACE = /\s/;
// `shortKey` returns a shorten key to pre-fetch completions and store in the
// cache. The shorten key is generated by the following rules:
-//
+//
// 1. If the query contains a space in the middle: i.e. the query consists of
// multiple words, the method removes the last word from the query, and
// returns joined remaining words with space.
-//
+//
// 2. If the query is a single word and it's an URL, the method returns a new
// URL excluding search query with the upper path of the original URL.
-//
+//
// 3. If the query is a single word and it's not an URL, the method returns a
// word with the half-length of the original query.
//
@@ -29,11 +29,15 @@ const WHITESPACE = /\s/;
//
export const shortKey = (query: string): string => {
if (WHITESPACE.test(query)) {
- return query.split(WHITESPACE).filter(word => word.length > 0).slice(0, -1).join(' ');
+ return query
+ .split(WHITESPACE)
+ .filter((word) => word.length > 0)
+ .slice(0, -1)
+ .join(" ");
}
let url;
try {
- url = new URL(query)
+ url = new URL(query);
} catch (e) {
return query.slice(0, query.length / 2);
}
@@ -42,12 +46,12 @@ export const shortKey = (query: string): string => {
// may be on typing or removing URLs such as "such as https://goog"
return query.slice(0, query.length / 2);
}
- if (url.pathname.endsWith('/')) {
+ if (url.pathname.endsWith("/")) {
// remove parameters and move to upper path
- return new URL('..', url).href;
+ return new URL("..", url).href;
}
// remove parameters
- return new URL('.', url).href;
+ return new URL(".", url).href;
};
export default class PrefetchAndCache<T> {
@@ -58,9 +62,8 @@ export default class PrefetchAndCache<T> {
constructor(
private getter: Getter<T>,
private filter: Filter<T>,
- private prefetchThrethold: number = 1,
- ) {
- }
+ private prefetchThrethold: number = 1
+ ) {}
async get(query: string): Promise<T[]> {
query = query.trim();
@@ -79,7 +82,7 @@ export default class PrefetchAndCache<T> {
private needToRefresh(query: string): boolean {
if (!this.shortKey) {
// no cache
- return true
+ return true;
}
if (query.length < this.shortKey.length) {
@@ -89,17 +92,17 @@ export default class PrefetchAndCache<T> {
}
if (!query.startsWith(this.shortKey)) {
- // queyr: "hello_w"
- // shorten: "hello_morning"
- return true
+ // queyr: "hello_w"
+ // shorten: "hello_morning"
+ return true;
}
- if (query.slice(this.shortKey.length).includes(' ')) {
+ if (query.slice(this.shortKey.length).includes(" ")) {
// queyr: "hello x"
// shorten: "hello"
return true;
}
- return false
+ return false;
}
}
diff --git a/src/background/completion/impl/TabRepositoryImpl.ts b/src/background/completion/impl/TabRepositoryImpl.ts
index adcaba7..d16d4c3 100644
--- a/src/background/completion/impl/TabRepositoryImpl.ts
+++ b/src/background/completion/impl/TabRepositoryImpl.ts
@@ -7,28 +7,31 @@ export default class TabRepositoryImpl implements TabRepository {
const tabs = await browser.tabs.query({ currentWindow: true });
return tabs
.filter((t) => {
- return t.url && t.url.toLowerCase().includes(query.toLowerCase()) ||
- t.title && t.title.toLowerCase().includes(query.toLowerCase());
+ return (
+ (t.url && t.url.toLowerCase().includes(query.toLowerCase())) ||
+ (t.title && t.title.toLowerCase().includes(query.toLowerCase()))
+ );
})
.filter((t) => {
return !(excludePinned && t.pinned);
})
- .filter(item => item.id && item.title && item.url)
+ .filter((item) => item.id && item.title && item.url)
.slice(0, COMPLETION_ITEM_LIMIT)
.map(TabRepositoryImpl.toEntity);
}
async getAllTabs(excludePinned: boolean): Promise<Tab[]> {
- if (excludePinned) {
- return (await browser.tabs.query({ currentWindow: true, pinned: true }))
- .map(TabRepositoryImpl.toEntity)
-
- }
- return (await browser.tabs.query({ currentWindow: true }))
- .map(TabRepositoryImpl.toEntity)
+ if (excludePinned) {
+ return (
+ await browser.tabs.query({ currentWindow: true, pinned: true })
+ ).map(TabRepositoryImpl.toEntity);
+ }
+ return (await browser.tabs.query({ currentWindow: true })).map(
+ TabRepositoryImpl.toEntity
+ );
}
- private static toEntity(tab: browser.tabs.Tab,): Tab {
+ private static toEntity(tab: browser.tabs.Tab): Tab {
return {
id: tab.id!!,
url: tab.url!!,
@@ -36,6 +39,6 @@ export default class TabRepositoryImpl implements TabRepository {
title: tab.title!!,
faviconUrl: tab.favIconUrl,
index: tab.index,
- }
+ };
}
}
diff --git a/src/background/completion/impl/filters.ts b/src/background/completion/impl/filters.ts
index 3aa56e4..523491d 100644
--- a/src/background/completion/impl/filters.ts
+++ b/src/background/completion/impl/filters.ts
@@ -1,32 +1,36 @@
type Item = browser.history.HistoryItem;
const filterHttp = (items: Item[]): Item[] => {
- const httpsHosts = items.map(x => new URL(x.url as string))
- .filter(x => x.protocol === 'https:')
- .map(x => x.host);
+ const httpsHosts = items
+ .map((x) => new URL(x.url as string))
+ .filter((x) => x.protocol === "https:")
+ .map((x) => x.host);
const hostsSet = new Set(httpsHosts);
return items.filter((item: Item) => {
const url = new URL(item.url as string);
- return url.protocol === 'https:' || !hostsSet.has(url.host);
+ return url.protocol === "https:" || !hostsSet.has(url.host);
});
};
const filterBlankTitle = (items: Item[]): Item[] => {
- return items.filter(item => item.title && item.title !== '');
+ return items.filter((item) => item.title && item.title !== "");
};
const filterByTailingSlash = (items: Item[]): Item[] => {
- const urls = items.map(item => new URL(item.url as string));
+ const urls = items.map((item) => new URL(item.url as string));
const simplePaths = urls
- .filter(url => url.hash === '' && url.search === '')
- .map(url => url.origin + url.pathname);
+ .filter((url) => url.hash === "" && url.search === "")
+ .map((url) => url.origin + url.pathname);
const pathsSet = new Set(simplePaths);
return items.filter((item) => {
const url = new URL(item.url as string);
- if (url.hash !== '' || url.search !== '' ||
- url.pathname.slice(-1) !== '/') {
+ if (
+ url.hash !== "" ||
+ url.search !== "" ||
+ url.pathname.slice(-1) !== "/"
+ ) {
return true;
}
return !pathsSet.has(url.origin + url.pathname.slice(0, -1));
@@ -34,14 +38,15 @@ const filterByTailingSlash = (items: Item[]): Item[] => {
};
const filterByPathname = (items: Item[]): Item[] => {
- const hash: {[key: string]: Item} = {};
+ const hash: { [key: string]: Item } = {};
for (const item of items) {
const url = new URL(item.url as string);
const pathname = url.origin + url.pathname;
if (!hash[pathname]) {
hash[pathname] = item;
- } else if ((hash[pathname].url as string).length >
- (item.url as string).length) {
+ } else if (
+ (hash[pathname].url as string).length > (item.url as string).length
+ ) {
hash[pathname] = item;
}
}
@@ -49,13 +54,14 @@ const filterByPathname = (items: Item[]): Item[] => {
};
const filterByOrigin = (items: Item[]): Item[] => {
- const hash: {[key: string]: Item} = {};
+ const hash: { [key: string]: Item } = {};
for (const item of items) {
const origin = new URL(item.url as string).origin;
if (!hash[origin]) {
hash[origin] = item;
- } else if ((hash[origin].url as string).length >
- (item.url as string).length) {
+ } else if (
+ (hash[origin].url as string).length > (item.url as string).length
+ ) {
hash[origin] = item;
}
}
@@ -63,6 +69,9 @@ const filterByOrigin = (items: Item[]): Item[] => {
};
export {
- filterHttp, filterBlankTitle, filterByTailingSlash,
- filterByPathname, filterByOrigin
+ filterHttp,
+ filterBlankTitle,
+ filterByTailingSlash,
+ filterByPathname,
+ filterByOrigin,
};
diff --git a/src/background/controllers/AddonEnabledController.ts b/src/background/controllers/AddonEnabledController.ts
index 903df40..170abdf 100644
--- a/src/background/controllers/AddonEnabledController.ts
+++ b/src/background/controllers/AddonEnabledController.ts
@@ -1,13 +1,9 @@
-import { injectable } from 'tsyringe';
-import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase';
+import { injectable } from "tsyringe";
+import AddonEnabledUseCase from "../usecases/AddonEnabledUseCase";
@injectable()
export default class AddonEnabledController {
-
- constructor(
- private addonEnabledUseCase: AddonEnabledUseCase,
- ) {
- }
+ constructor(private addonEnabledUseCase: AddonEnabledUseCase) {}
indicate(enabled: boolean): Promise<any> {
return this.addonEnabledUseCase.indicate(enabled);
diff --git a/src/background/controllers/CommandController.ts b/src/background/controllers/CommandController.ts
index 16aa6e8..f19303f 100644
--- a/src/background/controllers/CommandController.ts
+++ b/src/background/controllers/CommandController.ts
@@ -1,17 +1,14 @@
-import { injectable } from 'tsyringe';
-import CommandUseCase from '../usecases/CommandUseCase';
+import { injectable } from "tsyringe";
+import CommandUseCase from "../usecases/CommandUseCase";
const trimStart = (str: string): string => {
// NOTE String.trimStart is available on Firefox 61
- return str.replace(/^\s+/, '');
+ return str.replace(/^\s+/, "");
};
@injectable()
export default class CommandController {
- constructor(
- private commandIndicator: CommandUseCase,
- ) {
- }
+ constructor(private commandIndicator: CommandUseCase) {}
// eslint-disable-next-line complexity
exec(line: string): Promise<any> {
@@ -24,44 +21,44 @@ export default class CommandController {
const keywords = trimStart(trimmed.slice(name.length));
switch (words[0]) {
- case 'o':
- case 'open':
- return this.commandIndicator.open(keywords);
- case 't':
- case 'tabopen':
- return this.commandIndicator.tabopen(keywords);
- case 'w':
- case 'winopen':
- return this.commandIndicator.winopen(keywords);
- case 'b':
- case 'buffer':
- return this.commandIndicator.buffer(keywords);
- case 'bd':
- case 'bdel':
- case 'bdelete':
- return this.commandIndicator.bdelete(false, keywords);
- case 'bd!':
- case 'bdel!':
- case 'bdelete!':
- return this.commandIndicator.bdelete(true, keywords);
- case 'bdeletes':
- return this.commandIndicator.bdeletes(false, keywords);
- case 'bdeletes!':
- return this.commandIndicator.bdeletes(true, keywords);
- case 'addbookmark':
- return this.commandIndicator.addbookmark(keywords);
- case 'q':
- case 'quit':
- return this.commandIndicator.quit();
- case 'qa':
- case 'quitall':
- return this.commandIndicator.quitAll();
- case 'set':
- return this.commandIndicator.set(keywords);
- case 'h':
- case 'help':
- return this.commandIndicator.help();
+ case "o":
+ case "open":
+ return this.commandIndicator.open(keywords);
+ case "t":
+ case "tabopen":
+ return this.commandIndicator.tabopen(keywords);
+ case "w":
+ case "winopen":
+ return this.commandIndicator.winopen(keywords);
+ case "b":
+ case "buffer":
+ return this.commandIndicator.buffer(keywords);
+ case "bd":
+ case "bdel":
+ case "bdelete":
+ return this.commandIndicator.bdelete(false, keywords);
+ case "bd!":
+ case "bdel!":
+ case "bdelete!":
+ return this.commandIndicator.bdelete(true, keywords);
+ case "bdeletes":
+ return this.commandIndicator.bdeletes(false, keywords);
+ case "bdeletes!":
+ return this.commandIndicator.bdeletes(true, keywords);
+ case "addbookmark":
+ return this.commandIndicator.addbookmark(keywords);
+ case "q":
+ case "quit":
+ return this.commandIndicator.quit();
+ case "qa":
+ case "quitall":
+ return this.commandIndicator.quitAll();
+ case "set":
+ return this.commandIndicator.set(keywords);
+ case "h":
+ case "help":
+ return this.commandIndicator.help();
}
- throw new Error(words[0] + ' command is not defined');
+ throw new Error(words[0] + " command is not defined");
}
}
diff --git a/src/background/controllers/CompletionController.ts b/src/background/controllers/CompletionController.ts
index fb6137c..35538be 100644
--- a/src/background/controllers/CompletionController.ts
+++ b/src/background/controllers/CompletionController.ts
@@ -4,7 +4,7 @@ import {
ConsoleRequestBookmarksResponse,
ConsoleRequestHistoryResponse,
ConsoleRequestSearchEnginesResponse,
- ConsoleRequesttabsResponse
+ ConsoleRequesttabsResponse,
} from "../../shared/messages";
import { injectable } from "tsyringe";
import OpenCompletionUseCase from "../completion/OpenCompletionUseCase";
@@ -16,20 +16,23 @@ export default class CompletionController {
constructor(
private completionUseCase: OpenCompletionUseCase,
private tabCompletionUseCase: TabCompletionUseCase,
- private propertyCompletionUseCase: PropertyCompletionUseCase,
- ) {
- }
+ private propertyCompletionUseCase: PropertyCompletionUseCase
+ ) {}
async getCompletionTypes(): Promise<ConsoleGetCompletionTypesResponse> {
return this.completionUseCase.getCompletionTypes();
}
- async requestSearchEngines(query: string): Promise<ConsoleRequestSearchEnginesResponse> {
+ async requestSearchEngines(
+ query: string
+ ): Promise<ConsoleRequestSearchEnginesResponse> {
const items = await this.completionUseCase.requestSearchEngines(query);
- return items.map(name => ({ title: name }));
+ return items.map((name) => ({ title: name }));
}
- async requestBookmarks(query: string): Promise<ConsoleRequestBookmarksResponse> {
+ async requestBookmarks(
+ query: string
+ ): Promise<ConsoleRequestBookmarksResponse> {
return this.completionUseCase.requestBookmarks(query);
}
@@ -37,11 +40,14 @@ export default class CompletionController {
return this.completionUseCase.requestHistory(query);
}
- async queryTabs(query: string, excludePinned: boolean): Promise<ConsoleRequesttabsResponse> {
+ async queryTabs(
+ query: string,
+ excludePinned: boolean
+ ): Promise<ConsoleRequesttabsResponse> {
return this.tabCompletionUseCase.queryTabs(query, excludePinned);
}
async getProperties(): Promise<ConsoleGetPropertiesResponse> {
- return this.propertyCompletionUseCase.getProperties();
+ return this.propertyCompletionUseCase.getProperties();
}
-} \ No newline at end of file
+}
diff --git a/src/background/controllers/FindController.ts b/src/background/controllers/FindController.ts
index 1cec962..92dfeb0 100644
--- a/src/background/controllers/FindController.ts
+++ b/src/background/controllers/FindController.ts
@@ -1,12 +1,9 @@
-import { injectable } from 'tsyringe';
-import FindUseCase from '../usecases/FindUseCase';
+import { injectable } from "tsyringe";
+import FindUseCase from "../usecases/FindUseCase";
@injectable()
export default class FindController {
- constructor(
- private findUseCase: FindUseCase,
- ) {
- }
+ constructor(private findUseCase: FindUseCase) {}
getKeyword(): Promise<string> {
return this.findUseCase.getKeyword();
diff --git a/src/background/controllers/LinkController.ts b/src/background/controllers/LinkController.ts
index af6148e..a410bc7 100644
--- a/src/background/controllers/LinkController.ts
+++ b/src/background/controllers/LinkController.ts
@@ -1,19 +1,18 @@
-import { injectable } from 'tsyringe';
-import LinkUseCase from '../usecases/LinkUseCase';
+import { injectable } from "tsyringe";
+import LinkUseCase from "../usecases/LinkUseCase";
@injectable()
export default class LinkController {
- constructor(
- private linkUseCase: LinkUseCase,
- ) {
- }
+ constructor(private linkUseCase: LinkUseCase) {}
openToTab(url: string, tabId: number): Promise<void> {
return this.linkUseCase.openToTab(url, tabId);
}
openNewTab(
- url: string, openerId: number, background: boolean,
+ url: string,
+ openerId: number,
+ background: boolean
): Promise<void> {
return this.linkUseCase.openNewTab(url, openerId, background);
}
diff --git a/src/background/controllers/MarkController.ts b/src/background/controllers/MarkController.ts
index 4726fbc..0d468f2 100644
--- a/src/background/controllers/MarkController.ts
+++ b/src/background/controllers/MarkController.ts
@@ -1,12 +1,9 @@
-import { injectable } from 'tsyringe';
-import MarkUseCase from '../usecases/MarkUseCase';
+import { injectable } from "tsyringe";
+import MarkUseCase from "../usecases/MarkUseCase";
@injectable()
export default class MarkController {
- constructor(
- private markUseCase: MarkUseCase,
- ) {
- }
+ constructor(private markUseCase: MarkUseCase) {}
setGlobal(key: string, x: number, y: number): Promise<any> {
return this.markUseCase.setGlobal(key, x, y);
diff --git a/src/background/controllers/OperationController.ts b/src/background/controllers/OperationController.ts
index 181dd19..5a7047d 100644
--- a/src/background/controllers/OperationController.ts
+++ b/src/background/controllers/OperationController.ts
@@ -1,12 +1,12 @@
-import { injectable } from 'tsyringe';
-import * as operations from '../../shared/operations';
-import FindUseCase from '../usecases/FindUseCase';
-import ConsoleUseCase from '../usecases/ConsoleUseCase';
-import TabUseCase from '../usecases/TabUseCase';
-import TabSelectUseCase from '../usecases/TabSelectUseCase';
-import ZoomUseCase from '../usecases/ZoomUseCase';
-import NavigateUseCase from '../usecases/NavigateUseCase';
-import RepeatUseCase from '../usecases/RepeatUseCase';
+import { injectable } from "tsyringe";
+import * as operations from "../../shared/operations";
+import FindUseCase from "../usecases/FindUseCase";
+import ConsoleUseCase from "../usecases/ConsoleUseCase";
+import TabUseCase from "../usecases/TabUseCase";
+import TabSelectUseCase from "../usecases/TabSelectUseCase";
+import ZoomUseCase from "../usecases/ZoomUseCase";
+import NavigateUseCase from "../usecases/NavigateUseCase";
+import RepeatUseCase from "../usecases/RepeatUseCase";
@injectable()
export default class OperationController {
@@ -17,9 +17,8 @@ export default class OperationController {
private tabSelectUseCase: TabSelectUseCase,
private zoomUseCase: ZoomUseCase,
private navigateUseCase: NavigateUseCase,
- private repeatUseCase: RepeatUseCase,
- ) {
- }
+ private repeatUseCase: RepeatUseCase
+ ) {}
async exec(repeat: number, op: operations.Operation): Promise<any> {
await this.doOperation(repeat, op);
@@ -31,91 +30,96 @@ export default class OperationController {
// eslint-disable-next-line complexity, max-lines-per-function
async doOperation(
repeat: number,
- operation: operations.Operation,
+ operation: operations.Operation
): Promise<any> {
// eslint-disable-next-line complexity, max-lines-per-function
const opFunc = (() => {
switch (operation.type) {
- case operations.TAB_CLOSE:
- return () => this.tabUseCase.close(false, operation.select === 'left');
- case operations.TAB_CLOSE_RIGHT:
- return () => this.tabUseCase.closeRight();
- case operations.TAB_CLOSE_FORCE:
- return () => this.tabUseCase.close(true);
- case operations.TAB_REOPEN:
- return () => this.tabUseCase.reopen();
- case operations.TAB_PREV:
- return () => this.tabSelectUseCase.selectPrev(1);
- case operations.TAB_NEXT:
- return () => this.tabSelectUseCase.selectNext(1);
- case operations.TAB_FIRST:
- return () => this.tabSelectUseCase.selectFirst();
- case operations.TAB_LAST:
- return () => this.tabSelectUseCase.selectLast();
- case operations.TAB_PREV_SEL:
- return () => this.tabSelectUseCase.selectPrevSelected();
- case operations.TAB_RELOAD:
- return () => this.tabUseCase.reload(operation.cache);
- case operations.TAB_PIN:
- return () => this.tabUseCase.setPinned(true);
- case operations.TAB_UNPIN:
- return () => this.tabUseCase.setPinned(false);
- case operations.TAB_TOGGLE_PINNED:
- return () => this.tabUseCase.togglePinned();
- case operations.TAB_DUPLICATE:
- return () => this.tabUseCase.duplicate();
- case operations.PAGE_SOURCE:
- return () => this.tabUseCase.openPageSource();
- case operations.PAGE_HOME:
- return () => this.tabUseCase.openHome(operation.newTab);
- case operations.ZOOM_IN:
- return () => this.zoomUseCase.zoomIn();
- case operations.ZOOM_OUT:
- return () => this.zoomUseCase.zoomOut();
- case operations.ZOOM_NEUTRAL:
- return () => this.zoomUseCase.zoomNutoral();
- case operations.COMMAND_SHOW:
- return () => this.consoleUseCase.showCommand();
- case operations.COMMAND_SHOW_OPEN:
- return () => this.consoleUseCase.showOpenCommand(operation.alter);
- case operations.COMMAND_SHOW_TABOPEN:
- return () => this.consoleUseCase.showTabopenCommand(operation.alter);
- case operations.COMMAND_SHOW_WINOPEN:
- return () => this.consoleUseCase.showWinopenCommand(operation.alter);
- case operations.COMMAND_SHOW_BUFFER:
- return () => this.consoleUseCase.showBufferCommand();
- case operations.COMMAND_SHOW_ADDBOOKMARK:
- return () => this.consoleUseCase.showAddbookmarkCommand(
- operation.alter);
- case operations.FIND_START:
- return () => this.findUseCase.findStart();
- case operations.CANCEL:
- return () => this.consoleUseCase.hideConsole();
- case operations.NAVIGATE_HISTORY_PREV:
- return () => this.navigateUseCase.openHistoryPrev();
- case operations.NAVIGATE_HISTORY_NEXT:
- return () => this.navigateUseCase.openHistoryNext();
- case operations.NAVIGATE_LINK_PREV:
- return () => this.navigateUseCase.openLinkPrev();
- case operations.NAVIGATE_LINK_NEXT:
- return () => this.navigateUseCase.openLinkNext();
- case operations.NAVIGATE_PARENT:
- return () => this.navigateUseCase.openParent();
- case operations.NAVIGATE_ROOT:
- return () => this.navigateUseCase.openRoot();
- case operations.REPEAT_LAST:
- return () => {
- const last = this.repeatUseCase.getLastOperation();
- if (typeof last !== 'undefined') {
- return this.doOperation(1, last);
- }
- return Promise.resolve();
- };
- case operations.INTERNAL_OPEN_URL:
- return () => this.tabUseCase.openURL(
- operation.url, operation.newTab, operation.newWindow);
- default:
- throw new Error('unknown operation: ' + operation.type);
+ case operations.TAB_CLOSE:
+ return () =>
+ this.tabUseCase.close(false, operation.select === "left");
+ case operations.TAB_CLOSE_RIGHT:
+ return () => this.tabUseCase.closeRight();
+ case operations.TAB_CLOSE_FORCE:
+ return () => this.tabUseCase.close(true);
+ case operations.TAB_REOPEN:
+ return () => this.tabUseCase.reopen();
+ case operations.TAB_PREV:
+ return () => this.tabSelectUseCase.selectPrev(1);
+ case operations.TAB_NEXT:
+ return () => this.tabSelectUseCase.selectNext(1);
+ case operations.TAB_FIRST:
+ return () => this.tabSelectUseCase.selectFirst();
+ case operations.TAB_LAST:
+ return () => this.tabSelectUseCase.selectLast();
+ case operations.TAB_PREV_SEL:
+ return () => this.tabSelectUseCase.selectPrevSelected();
+ case operations.TAB_RELOAD:
+ return () => this.tabUseCase.reload(operation.cache);
+ case operations.TAB_PIN:
+ return () => this.tabUseCase.setPinned(true);
+ case operations.TAB_UNPIN:
+ return () => this.tabUseCase.setPinned(false);
+ case operations.TAB_TOGGLE_PINNED:
+ return () => this.tabUseCase.togglePinned();
+ case operations.TAB_DUPLICATE:
+ return () => this.tabUseCase.duplicate();
+ case operations.PAGE_SOURCE:
+ return () => this.tabUseCase.openPageSource();
+ case operations.PAGE_HOME:
+ return () => this.tabUseCase.openHome(operation.newTab);
+ case operations.ZOOM_IN:
+ return () => this.zoomUseCase.zoomIn();
+ case operations.ZOOM_OUT:
+ return () => this.zoomUseCase.zoomOut();
+ case operations.ZOOM_NEUTRAL:
+ return () => this.zoomUseCase.zoomNutoral();
+ case operations.COMMAND_SHOW:
+ return () => this.consoleUseCase.showCommand();
+ case operations.COMMAND_SHOW_OPEN:
+ return () => this.consoleUseCase.showOpenCommand(operation.alter);
+ case operations.COMMAND_SHOW_TABOPEN:
+ return () => this.consoleUseCase.showTabopenCommand(operation.alter);
+ case operations.COMMAND_SHOW_WINOPEN:
+ return () => this.consoleUseCase.showWinopenCommand(operation.alter);
+ case operations.COMMAND_SHOW_BUFFER:
+ return () => this.consoleUseCase.showBufferCommand();
+ case operations.COMMAND_SHOW_ADDBOOKMARK:
+ return () =>
+ this.consoleUseCase.showAddbookmarkCommand(operation.alter);
+ case operations.FIND_START:
+ return () => this.findUseCase.findStart();
+ case operations.CANCEL:
+ return () => this.consoleUseCase.hideConsole();
+ case operations.NAVIGATE_HISTORY_PREV:
+ return () => this.navigateUseCase.openHistoryPrev();
+ case operations.NAVIGATE_HISTORY_NEXT:
+ return () => this.navigateUseCase.openHistoryNext();
+ case operations.NAVIGATE_LINK_PREV:
+ return () => this.navigateUseCase.openLinkPrev();
+ case operations.NAVIGATE_LINK_NEXT:
+ return () => this.navigateUseCase.openLinkNext();
+ case operations.NAVIGATE_PARENT:
+ return () => this.navigateUseCase.openParent();
+ case operations.NAVIGATE_ROOT:
+ return () => this.navigateUseCase.openRoot();
+ case operations.REPEAT_LAST:
+ return () => {
+ const last = this.repeatUseCase.getLastOperation();
+ if (typeof last !== "undefined") {
+ return this.doOperation(1, last);
+ }
+ return Promise.resolve();
+ };
+ case operations.INTERNAL_OPEN_URL:
+ return () =>
+ this.tabUseCase.openURL(
+ operation.url,
+ operation.newTab,
+ operation.newWindow
+ );
+ default:
+ throw new Error("unknown operation: " + operation.type);
}
})();
@@ -125,4 +129,3 @@ export default class OperationController {
}
}
}
-
diff --git a/src/background/controllers/SettingController.ts b/src/background/controllers/SettingController.ts
index 26edc07..4248746 100644
--- a/src/background/controllers/SettingController.ts
+++ b/src/background/controllers/SettingController.ts
@@ -1,15 +1,14 @@
-import { injectable } from 'tsyringe';
-import SettingUseCase from '../usecases/SettingUseCase';
-import ContentMessageClient from '../infrastructures/ContentMessageClient';
-import Settings from '../../shared/settings/Settings';
+import { injectable } from "tsyringe";
+import SettingUseCase from "../usecases/SettingUseCase";
+import ContentMessageClient from "../infrastructures/ContentMessageClient";
+import Settings from "../../shared/settings/Settings";
@injectable()
export default class SettingController {
constructor(
private settingUseCase: SettingUseCase,
- private contentMessageClient: ContentMessageClient,
- ) {
- }
+ private contentMessageClient: ContentMessageClient
+ ) {}
getSetting(): Promise<Settings> {
return this.settingUseCase.getCached();
diff --git a/src/background/controllers/VersionController.ts b/src/background/controllers/VersionController.ts
index b00185a..92fca9e 100644
--- a/src/background/controllers/VersionController.ts
+++ b/src/background/controllers/VersionController.ts
@@ -1,12 +1,9 @@
-import { injectable } from 'tsyringe';
-import VersionUseCase from '../usecases/VersionUseCase';
+import { injectable } from "tsyringe";
+import VersionUseCase from "../usecases/VersionUseCase";
@injectable()
export default class VersionController {
- constructor(
- private versionUseCase: VersionUseCase,
- ) {
- }
+ constructor(private versionUseCase: VersionUseCase) {}
notify(): Promise<void> {
return this.versionUseCase.notify();
diff --git a/src/background/di.ts b/src/background/di.ts
index c186262..5e6ad03 100644
--- a/src/background/di.ts
+++ b/src/background/di.ts
@@ -1,19 +1,28 @@
/* eslint-disable max-len */
-import { LocalSettingRepository, SyncSettingRepository } from "./repositories/SettingRepository";
+import {
+ LocalSettingRepository,
+ SyncSettingRepository,
+} from "./repositories/SettingRepository";
import { NotifierImpl } from "./presenters/Notifier";
import { CachedSettingRepositoryImpl } from "./repositories/CachedSettingRepository";
-import { container } from 'tsyringe';
+import { container } from "tsyringe";
import HistoryRepositoryImpl from "./completion/impl/HistoryRepositoryImpl";
import BookmarkRepositoryImpl from "./completion/impl/BookmarkRepositoryImpl";
import TabRepositoryImpl from "./completion/impl/TabRepositoryImpl";
-import {TabPresenterImpl} from "./presenters/TabPresenter";
+import { TabPresenterImpl } from "./presenters/TabPresenter";
-container.register('LocalSettingRepository', { useValue: LocalSettingRepository });
-container.register('SyncSettingRepository', { useClass: SyncSettingRepository });
-container.register('CachedSettingRepository', { useClass: CachedSettingRepositoryImpl });
-container.register('Notifier', { useClass: NotifierImpl });
-container.register('HistoryRepository', { useClass: HistoryRepositoryImpl });
-container.register('BookmarkRepository', { useClass: BookmarkRepositoryImpl });
-container.register('TabRepository', { useClass: TabRepositoryImpl });
-container.register('TabPresenter', { useClass: TabPresenterImpl });
+container.register("LocalSettingRepository", {
+ useValue: LocalSettingRepository,
+});
+container.register("SyncSettingRepository", {
+ useClass: SyncSettingRepository,
+});
+container.register("CachedSettingRepository", {
+ useClass: CachedSettingRepositoryImpl,
+});
+container.register("Notifier", { useClass: NotifierImpl });
+container.register("HistoryRepository", { useClass: HistoryRepositoryImpl });
+container.register("BookmarkRepository", { useClass: BookmarkRepositoryImpl });
+container.register("TabRepository", { useClass: TabRepositoryImpl });
+container.register("TabPresenter", { useClass: TabPresenterImpl });
diff --git a/src/background/index.ts b/src/background/index.ts
index f75c53b..6fe68af 100644
--- a/src/background/index.ts
+++ b/src/background/index.ts
@@ -1,7 +1,7 @@
-import 'reflect-metadata';
-import { container } from 'tsyringe';
-import Application from './Application';
-import './di';
+import "reflect-metadata";
+import { container } from "tsyringe";
+import Application from "./Application";
+import "./di";
const app = container.resolve(Application);
app.run();
diff --git a/src/background/infrastructures/ConsoleClient.ts b/src/background/infrastructures/ConsoleClient.ts
index 1385fe7..8d0af89 100644
--- a/src/background/infrastructures/ConsoleClient.ts
+++ b/src/background/infrastructures/ConsoleClient.ts
@@ -1,5 +1,5 @@
-import { injectable } from 'tsyringe';
-import * as messages from '../../shared/messages';
+import { injectable } from "tsyringe";
+import * as messages from "../../shared/messages";
@injectable()
export default class ConsoleClient {
@@ -12,7 +12,7 @@ export default class ConsoleClient {
showFind(tabId: number): Promise<any> {
return browser.tabs.sendMessage(tabId, {
- type: messages.CONSOLE_SHOW_FIND
+ type: messages.CONSOLE_SHOW_FIND,
});
}
@@ -36,4 +36,3 @@ export default class ConsoleClient {
});
}
}
-
diff --git a/src/background/infrastructures/ContentMessageClient.ts b/src/background/infrastructures/ContentMessageClient.ts
index b6c0c23..e889392 100644
--- a/src/background/infrastructures/ContentMessageClient.ts
+++ b/src/background/infrastructures/ContentMessageClient.ts
@@ -1,12 +1,12 @@
-import { injectable } from 'tsyringe';
-import * as messages from '../../shared/messages';
+import { injectable } from "tsyringe";
+import * as messages from "../../shared/messages";
@injectable()
export default class ContentMessageClient {
async broadcastSettingsChanged(): Promise<void> {
const tabs = await browser.tabs.query({});
for (const tab of tabs) {
- if (!tab.id || tab.url && tab.url.startsWith('about:')) {
+ if (!tab.id || (tab.url && tab.url.startsWith("about:"))) {
continue;
}
browser.tabs.sendMessage(tab.id, {
@@ -19,7 +19,7 @@ export default class ContentMessageClient {
const enabled = await browser.tabs.sendMessage(tabId, {
type: messages.ADDON_ENABLED_QUERY,
});
- return enabled as any as boolean;
+ return (enabled as any) as boolean;
}
async toggleAddonEnabled(tabId: number): Promise<void> {
diff --git a/src/background/infrastructures/ContentMessageListener.ts b/src/background/infrastructures/ContentMessageListener.ts
index 2fbb9cf..6978d35 100644
--- a/src/background/infrastructures/ContentMessageListener.ts
+++ b/src/background/infrastructures/ContentMessageListener.ts
@@ -1,18 +1,18 @@
-import { injectable } from 'tsyringe';
-import * as messages from '../../shared/messages';
-import * as operations from '../../shared/operations';
-import CommandController from '../controllers/CommandController';
-import SettingController from '../controllers/SettingController';
-import FindController from '../controllers/FindController';
-import AddonEnabledController from '../controllers/AddonEnabledController';
-import LinkController from '../controllers/LinkController';
-import OperationController from '../controllers/OperationController';
-import MarkController from '../controllers/MarkController';
+import { injectable } from "tsyringe";
+import * as messages from "../../shared/messages";
+import * as operations from "../../shared/operations";
+import CommandController from "../controllers/CommandController";
+import SettingController from "../controllers/SettingController";
+import FindController from "../controllers/FindController";
+import AddonEnabledController from "../controllers/AddonEnabledController";
+import LinkController from "../controllers/LinkController";
+import OperationController from "../controllers/OperationController";
+import MarkController from "../controllers/MarkController";
import CompletionController from "../controllers/CompletionController";
@injectable()
export default class ContentMessageListener {
- private consolePorts: {[tabId: number]: browser.runtime.Port};
+ private consolePorts: { [tabId: number]: browser.runtime.Port };
constructor(
private settingController: SettingController,
@@ -22,21 +22,29 @@ export default class ContentMessageListener {
private addonEnabledController: AddonEnabledController,
private linkController: LinkController,
private operationController: OperationController,
- private markController: MarkController,
+ private markController: MarkController
) {
this.consolePorts = {};
}
run(): void {
- browser.runtime.onMessage.addListener((
- message: any, sender: browser.runtime.MessageSender,
- ) => {
- try {
- const ret = this.onMessage(message, sender.tab as browser.tabs.Tab);
- if (!(ret instanceof Promise)) {
- return {};
- }
- return ret.catch((e) => {
+ browser.runtime.onMessage.addListener(
+ (message: any, sender: browser.runtime.MessageSender) => {
+ try {
+ const ret = this.onMessage(message, sender.tab as browser.tabs.Tab);
+ if (!(ret instanceof Promise)) {
+ return {};
+ }
+ return ret.catch((e) => {
+ if (!sender.tab || !sender.tab.id) {
+ return;
+ }
+ return browser.tabs.sendMessage(sender.tab.id, {
+ type: messages.CONSOLE_SHOW_ERROR,
+ text: e.message,
+ });
+ });
+ } catch (e) {
if (!sender.tab || !sender.tab.id) {
return;
}
@@ -44,64 +52,62 @@ export default class ContentMessageListener {
type: messages.CONSOLE_SHOW_ERROR,
text: e.message,
});
- });
- } catch (e) {
- if (!sender.tab || !sender.tab.id) {
- return;
}
- return browser.tabs.sendMessage(sender.tab.id, {
- type: messages.CONSOLE_SHOW_ERROR,
- text: e.message,
- });
}
- });
+ );
browser.runtime.onConnect.addListener(this.onConnected.bind(this));
}
onMessage(
- message: messages.Message, senderTab: browser.tabs.Tab,
+ message: messages.Message,
+ senderTab: browser.tabs.Tab
): Promise<any> | any {
switch (message.type) {
- case messages.CONSOLE_GET_COMPLETION_TYPES:
- return this.completionController.getCompletionTypes();
- case messages.CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE:
- return this.completionController.requestSearchEngines(message.query);
- case messages.CONSOLE_REQUEST_BOOKMARKS:
- return this.completionController.requestBookmarks(message.query);
- case messages.CONSOLE_REQUEST_HISTORY:
- return this.completionController.requestHistory(message.query);
- case messages.CONSOLE_REQUEST_TABS:
- return this.completionController.queryTabs(message.query, message.excludePinned);
- case messages.CONSOLE_GET_PROPERTIES:
- return this.completionController.getProperties();
- case messages.CONSOLE_ENTER_COMMAND:
- return this.onConsoleEnterCommand(message.text);
- case messages.SETTINGS_QUERY:
- return this.onSettingsQuery();
- case messages.FIND_GET_KEYWORD:
- return this.onFindGetKeyword();
- case messages.FIND_SET_KEYWORD:
- return this.onFindSetKeyword(message.keyword);
- case messages.ADDON_ENABLED_RESPONSE:
- return this.onAddonEnabledResponse(message.enabled);
- case messages.OPEN_URL:
- return this.onOpenUrl(
- message.newTab,
- message.url,
- senderTab.id as number,
- message.background);
- case messages.BACKGROUND_OPERATION:
- return this.onBackgroundOperation(message.repeat, message.operation);
- case messages.MARK_SET_GLOBAL:
- return this.onMarkSetGlobal(message.key, message.x, message.y);
- case messages.MARK_JUMP_GLOBAL:
- return this.onMarkJumpGlobal(message.key);
- case messages.CONSOLE_FRAME_MESSAGE:
- return this.onConsoleFrameMessage(
- senderTab.id as number, message.message,
- );
+ case messages.CONSOLE_GET_COMPLETION_TYPES:
+ return this.completionController.getCompletionTypes();
+ case messages.CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE:
+ return this.completionController.requestSearchEngines(message.query);
+ case messages.CONSOLE_REQUEST_BOOKMARKS:
+ return this.completionController.requestBookmarks(message.query);
+ case messages.CONSOLE_REQUEST_HISTORY:
+ return this.completionController.requestHistory(message.query);
+ case messages.CONSOLE_REQUEST_TABS:
+ return this.completionController.queryTabs(
+ message.query,
+ message.excludePinned
+ );
+ case messages.CONSOLE_GET_PROPERTIES:
+ return this.completionController.getProperties();
+ case messages.CONSOLE_ENTER_COMMAND:
+ return this.onConsoleEnterCommand(message.text);
+ case messages.SETTINGS_QUERY:
+ return this.onSettingsQuery();
+ case messages.FIND_GET_KEYWORD:
+ return this.onFindGetKeyword();
+ case messages.FIND_SET_KEYWORD:
+ return this.onFindSetKeyword(message.keyword);
+ case messages.ADDON_ENABLED_RESPONSE:
+ return this.onAddonEnabledResponse(message.enabled);
+ case messages.OPEN_URL:
+ return this.onOpenUrl(
+ message.newTab,
+ message.url,
+ senderTab.id as number,
+ message.background
+ );
+ case messages.BACKGROUND_OPERATION:
+ return this.onBackgroundOperation(message.repeat, message.operation);
+ case messages.MARK_SET_GLOBAL:
+ return this.onMarkSetGlobal(message.key, message.x, message.y);
+ case messages.MARK_JUMP_GLOBAL:
+ return this.onMarkJumpGlobal(message.key);
+ case messages.CONSOLE_FRAME_MESSAGE:
+ return this.onConsoleFrameMessage(
+ senderTab.id as number,
+ message.message
+ );
}
- throw new Error('unsupported message: ' + message.type);
+ throw new Error("unsupported message: " + message.type);
}
onConsoleEnterCommand(text: string): Promise<any> {
@@ -125,7 +131,10 @@ export default class ContentMessageListener {
}
onOpenUrl(
- newTab: boolean, url: string, openerId: number, background: boolean,
+ newTab: boolean,
+ url: string,
+ openerId: number,
+ background: boolean
): Promise<any> {
if (newTab) {
return this.linkController.openNewTab(url, openerId, background);
@@ -154,7 +163,7 @@ export default class ContentMessageListener {
}
onConnected(port: browser.runtime.Port): void {
- if (port.name !== 'vimvixen-console') {
+ if (port.name !== "vimvixen-console") {
return;
}
diff --git a/src/background/infrastructures/MemoryStorage.ts b/src/background/infrastructures/MemoryStorage.ts
index af445a6..ad7bcd7 100644
--- a/src/background/infrastructures/MemoryStorage.ts
+++ b/src/background/infrastructures/MemoryStorage.ts
@@ -1,10 +1,10 @@
-const db: {[key: string]: any} = {};
+const db: { [key: string]: any } = {};
export default class MemoryStorage {
set(name: string, value: any): void {
const data = JSON.stringify(value);
- if (typeof data === 'undefined') {
- throw new Error('value is not serializable');
+ if (typeof data === "undefined") {
+ throw new Error("value is not serializable");
}
db[name] = data;
}
diff --git a/src/background/presenters/HelpPresenter.ts b/src/background/presenters/HelpPresenter.ts
index f5c3a6b..7fa0597 100644
--- a/src/background/presenters/HelpPresenter.ts
+++ b/src/background/presenters/HelpPresenter.ts
@@ -1,6 +1,6 @@
-import { injectable } from 'tsyringe';
+import { injectable } from "tsyringe";
-const url = 'https://ueokande.github.io/vim-vixen/';
+const url = "https://ueokande.github.io/vim-vixen/";
@injectable()
export default class HelpPresenter {
diff --git a/src/background/presenters/IndicatorPresenter.ts b/src/background/presenters/IndicatorPresenter.ts
index 6a33e62..5b4b673 100644
--- a/src/background/presenters/IndicatorPresenter.ts
+++ b/src/background/presenters/IndicatorPresenter.ts
@@ -1,18 +1,17 @@
-import { injectable } from 'tsyringe';
+import { injectable } from "tsyringe";
@injectable()
export default class IndicatorPresenter {
indicate(enabled: boolean): Promise<void> {
const path = enabled
- ? 'resources/enabled_32x32.png'
- : 'resources/disabled_32x32.png';
- if (typeof browser.browserAction.setIcon === 'function') {
+ ? "resources/enabled_32x32.png"
+ : "resources/disabled_32x32.png";
+ if (typeof browser.browserAction.setIcon === "function") {
return browser.browserAction.setIcon({ path });
}
// setIcon not supported on Android
return Promise.resolve();
-
}
onClick(listener: (arg: browser.tabs.Tab) => void): void {
diff --git a/src/background/presenters/Notifier.ts b/src/background/presenters/Notifier.ts
index 57d58cb..2cd3225 100644
--- a/src/background/presenters/Notifier.ts
+++ b/src/background/presenters/Notifier.ts
@@ -1,5 +1,5 @@
-const NOTIFICATION_ID_UPDATE = 'vimvixen-update';
-const NOTIFICATION_ID_INVALID_SETTINGS = 'vimvixen-update-invalid-settings';
+const NOTIFICATION_ID_UPDATE = "vimvixen-update";
+const NOTIFICATION_ID_INVALID_SETTINGS = "vimvixen-update-invalid-settings";
export default interface Notifier {
notifyUpdated(version: string, onclick: () => void): Promise<void>;
@@ -10,7 +10,7 @@ export default interface Notifier {
export class NotifierImpl implements NotifierImpl {
async notifyUpdated(version: string, onclick: () => void): Promise<void> {
const title = `Vim Vixen ${version} has been installed`;
- const message = 'Click here to see release notes';
+ const message = "Click here to see release notes";
const listener = (id: string) => {
if (id !== NOTIFICATION_ID_UPDATE) {
@@ -22,8 +22,8 @@ export class NotifierImpl implements NotifierImpl {
browser.notifications.onClicked.addListener(listener);
await browser.notifications.create(NOTIFICATION_ID_UPDATE, {
- 'type': 'basic',
- 'iconUrl': browser.extension.getURL('resources/icon_48x48.png'),
+ type: "basic",
+ iconUrl: browser.extension.getURL("resources/icon_48x48.png"),
title,
message,
});
@@ -32,7 +32,8 @@ export class NotifierImpl implements NotifierImpl {
async notifyInvalidSettings(onclick: () => void): Promise<void> {
const title = `Loaded settings is invalid`;
// eslint-disable-next-line max-len
- const message = 'The default settings is used due to the last saved settings is invalid. Check your current settings from the add-on preference';
+ const message =
+ "The default settings is used due to the last saved settings is invalid. Check your current settings from the add-on preference";
const listener = (id: string) => {
if (id !== NOTIFICATION_ID_INVALID_SETTINGS) {
@@ -44,8 +45,8 @@ export class NotifierImpl implements NotifierImpl {
browser.notifications.onClicked.addListener(listener);
await browser.notifications.create(NOTIFICATION_ID_INVALID_SETTINGS, {
- 'type': 'basic',
- 'iconUrl': browser.extension.getURL('resources/icon_48x48.png'),
+ type: "basic",
+ iconUrl: browser.extension.getURL("resources/icon_48x48.png"),
title,
message,
});
diff --git a/src/background/presenters/TabPresenter.ts b/src/background/presenters/TabPresenter.ts
index bded5a2..09cfa23 100644
--- a/src/background/presenters/TabPresenter.ts
+++ b/src/background/presenters/TabPresenter.ts
@@ -1,7 +1,7 @@
-import MemoryStorage from '../infrastructures/MemoryStorage';
+import MemoryStorage from "../infrastructures/MemoryStorage";
-const CURRENT_SELECTED_KEY = 'tabs.current.selected';
-const LAST_SELECTED_KEY = 'tabs.last.selected';
+const CURRENT_SELECTED_KEY = "tabs.current.selected";
+const LAST_SELECTED_KEY = "tabs.last.selected";
type Tab = browser.tabs.Tab;
@@ -35,7 +35,7 @@ export default interface TabPresenter {
setZoom(tabId: number, factor: number): Promise<void>;
onSelected(
- listener: (arg: { tabId: number, windowId: number}) => void,
+ listener: (arg: { tabId: number; windowId: number }) => void
): void;
}
@@ -50,7 +50,8 @@ export class TabPresenterImpl implements TabPresenter {
async getCurrent(): Promise<Tab> {
const tabs = await browser.tabs.query({
- active: true, currentWindow: true
+ active: true,
+ currentWindow: true,
});
return tabs[0];
}
@@ -62,22 +63,24 @@ export class TabPresenterImpl implements TabPresenter {
async getLastSelectedId(): Promise<number | undefined> {
const cache = new MemoryStorage();
const tabId = await cache.get(LAST_SELECTED_KEY);
- if (tabId === null || typeof tabId === 'undefined') {
+ if (tabId === null || typeof tabId === "undefined") {
return;
}
return tabId;
}
- async getByKeyword(
- keyword: string, excludePinned = false,
- ): Promise<Tab[]> {
+ async getByKeyword(keyword: string, excludePinned = false): Promise<Tab[]> {
const tabs = await browser.tabs.query({ currentWindow: true });
- return tabs.filter((t) => {
- return t.url && t.url.toLowerCase().includes(keyword.toLowerCase()) ||
- t.title && t.title.toLowerCase().includes(keyword.toLowerCase());
- }).filter((t) => {
- return !(excludePinned && t.pinned);
- });
+ return tabs
+ .filter((t) => {
+ return (
+ (t.url && t.url.toLowerCase().includes(keyword.toLowerCase())) ||
+ (t.title && t.title.toLowerCase().includes(keyword.toLowerCase()))
+ );
+ })
+ .filter((t) => {
+ return !(excludePinned && t.pinned);
+ });
}
async select(tabId: number): Promise<void> {
@@ -125,7 +128,7 @@ export class TabPresenterImpl implements TabPresenter {
}
onSelected(
- listener: (arg: { tabId: number, windowId: number}) => void,
+ listener: (arg: { tabId: number; windowId: number }) => void
): void {
browser.tabs.onActivated.addListener(listener);
}
diff --git a/src/background/presenters/WindowPresenter.ts b/src/background/presenters/WindowPresenter.ts
index 150a48b..4f37f5d 100644
--- a/src/background/presenters/WindowPresenter.ts
+++ b/src/background/presenters/WindowPresenter.ts
@@ -1,4 +1,4 @@
-import { injectable } from 'tsyringe';
+import { injectable } from "tsyringe";
@injectable()
export default class WindowPresenter {
diff --git a/src/background/repositories/BookmarkRepository.ts b/src/background/repositories/BookmarkRepository.ts
index 0d2a1fc..e6e55c9 100644
--- a/src/background/repositories/BookmarkRepository.ts
+++ b/src/background/repositories/BookmarkRepository.ts
@@ -1,17 +1,18 @@
-import { injectable } from 'tsyringe';
+import { injectable } from "tsyringe";
@injectable()
export default class BookmarkRepository {
async create(
- title: string, url: string
+ title: string,
+ url: string
): Promise<browser.bookmarks.BookmarkTreeNode> {
const item = await browser.bookmarks.create({
- type: 'bookmark',
+ type: "bookmark",
title,
url,
});
if (!item) {
- throw new Error('Could not create a bookmark');
+ throw new Error("Could not create a bookmark");
}
return item;
}
diff --git a/src/background/repositories/BrowserSettingRepository.ts b/src/background/repositories/BrowserSettingRepository.ts
index a47b64d..20013f4 100644
--- a/src/background/repositories/BrowserSettingRepository.ts
+++ b/src/background/repositories/BrowserSettingRepository.ts
@@ -1,18 +1,17 @@
-import { injectable } from 'tsyringe';
-import * as urls from '../../shared/urls';
+import { injectable } from "tsyringe";
+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';
+ | "not_controllable"
+ | "controlled_by_other_extensions"
+ | "controllable_by_this_extension"
+ | "controlled_by_this_extension";
function get(param: object): Promise<BrowserSettings>;
}
@@ -21,6 +20,6 @@ declare namespace browser.browserSettings.homepageOverride {
export default class BrowserSettingRepository {
async getHomepageUrls(): Promise<string[]> {
const { value } = await browser.browserSettings.homepageOverride.get({});
- return value.split('|').map(urls.normalizeUrl);
+ return value.split("|").map(urls.normalizeUrl);
}
}
diff --git a/src/background/repositories/CachedSettingRepository.ts b/src/background/repositories/CachedSettingRepository.ts
index 1af15d4..e3d3950 100644
--- a/src/background/repositories/CachedSettingRepository.ts
+++ b/src/background/repositories/CachedSettingRepository.ts
@@ -1,17 +1,15 @@
-import MemoryStorage from '../infrastructures/MemoryStorage';
-import Settings from '../../shared/settings/Settings';
-import Properties from '../../shared/settings/Properties';
+import MemoryStorage from "../infrastructures/MemoryStorage";
+import Settings from "../../shared/settings/Settings";
+import Properties from "../../shared/settings/Properties";
-const CACHED_SETTING_KEY = 'setting';
+const CACHED_SETTING_KEY = "setting";
export default interface CachedSettingRepository {
get(): Promise<Settings>;
update(value: Settings): Promise<void>;
- setProperty(
- name: string, value: string | number | boolean,
- ): Promise<void>;
+ setProperty(name: string, value: string | number | boolean): Promise<void>;
}
export class CachedSettingRepositoryImpl implements CachedSettingRepository {
@@ -28,35 +26,36 @@ export class CachedSettingRepositoryImpl implements CachedSettingRepository {
update(value: Settings): Promise<void> {
this.cache.set(CACHED_SETTING_KEY, value.toJSON());
- return Promise.resolve()
+ return Promise.resolve();
}
async setProperty(
- name: string, value: string | number | boolean,
+ name: string,
+ value: string | number | boolean
): Promise<void> {
const def = Properties.def(name);
if (!def) {
- throw new Error('unknown property: ' + name);
+ throw new Error("unknown property: " + name);
}
if (typeof value !== def.type) {
throw new TypeError(`property type of ${name} mismatch: ${typeof value}`);
}
let newValue = value;
- if (typeof value === 'string' && value === '') {
+ if (typeof value === "string" && value === "") {
newValue = def.defaultValue;
}
const current = await this.get();
switch (name) {
- case 'hintchars':
- current.properties.hintchars = newValue as string;
- break;
- case 'smoothscroll':
- current.properties.smoothscroll = newValue as boolean;
- break;
- case 'complete':
- current.properties.complete = newValue as string;
- break;
+ case "hintchars":
+ current.properties.hintchars = newValue as string;
+ break;
+ case "smoothscroll":
+ current.properties.smoothscroll = newValue as boolean;
+ break;
+ case "complete":
+ current.properties.complete = newValue as string;
+ break;
}
await this.update(current);
}
diff --git a/src/background/repositories/FindRepository.ts b/src/background/repositories/FindRepository.ts
index 6a087f5..be56284 100644
--- a/src/background/repositories/FindRepository.ts
+++ b/src/background/repositories/FindRepository.ts
@@ -1,7 +1,7 @@
-import { injectable } from 'tsyringe';
-import MemoryStorage from '../infrastructures/MemoryStorage';
+import { injectable } from "tsyringe";
+import MemoryStorage from "../infrastructures/MemoryStorage";
-const FIND_KEYWORD_KEY = 'find-keyword';
+const FIND_KEYWORD_KEY = "find-keyword";
@injectable()
export default class FindRepository {
@@ -20,4 +20,3 @@ export default class FindRepository {
return Promise.resolve();
}
}
-
diff --git a/src/background/repositories/MarkRepository.ts b/src/background/repositories/MarkRepository.ts
index 1f4ab0c..e2c1e94 100644
--- a/src/background/repositories/MarkRepository.ts
+++ b/src/background/repositories/MarkRepository.ts
@@ -1,8 +1,8 @@
-import { injectable } from 'tsyringe';
-import MemoryStorage from '../infrastructures/MemoryStorage';
-import GlobalMark from '../domains/GlobalMark';
+import { injectable } from "tsyringe";
+import MemoryStorage from "../infrastructures/MemoryStorage";
+import GlobalMark from "../domains/GlobalMark";
-const MARK_KEY = 'mark';
+const MARK_KEY = "mark";
@injectable()
export default class MarkRepository {
@@ -34,4 +34,3 @@ export default class MarkRepository {
return this.cache.get(MARK_KEY) || {};
}
}
-
diff --git a/src/background/repositories/RepeatRepository.ts b/src/background/repositories/RepeatRepository.ts
index c7f7a71..e3ab43d 100644
--- a/src/background/repositories/RepeatRepository.ts
+++ b/src/background/repositories/RepeatRepository.ts
@@ -1,8 +1,8 @@
-import { injectable } from 'tsyringe';
-import { Operation } from '../../shared/operations';
-import MemoryStorage from '../infrastructures/MemoryStorage';
+import { injectable } from "tsyringe";
+import { Operation } from "../../shared/operations";
+import MemoryStorage from "../infrastructures/MemoryStorage";
-const REPEAT_KEY = 'repeat';
+const REPEAT_KEY = "repeat";
@injectable()
export default class RepeatRepository {
diff --git a/src/background/repositories/SettingRepository.ts b/src/background/repositories/SettingRepository.ts
index b522045..d726cfb 100644
--- a/src/background/repositories/SettingRepository.ts
+++ b/src/background/repositories/SettingRepository.ts
@@ -1,4 +1,4 @@
-import SettingData from '../../shared/SettingData';
+import SettingData from "../../shared/SettingData";
export default interface SettingRepository {
load(): Promise<SettingData | null>;
@@ -8,7 +8,7 @@ export default interface SettingRepository {
export class LocalSettingRepository implements SettingRepository {
async load(): Promise<SettingData | null> {
- const {settings} = await browser.storage.local.get('settings');
+ const { settings } = await browser.storage.local.get("settings");
if (!settings) {
return null;
}
@@ -17,7 +17,7 @@ export class LocalSettingRepository implements SettingRepository {
onChange(callback: () => void) {
browser.storage.onChanged.addListener((changes, area) => {
- if (area !== 'local') {
+ if (area !== "local") {
return;
}
if (changes.settings) {
@@ -29,7 +29,7 @@ export class LocalSettingRepository implements SettingRepository {
export class SyncSettingRepository implements SettingRepository {
async load(): Promise<SettingData | null> {
- const {settings} = await browser.storage.sync.get('settings');
+ const { settings } = await browser.storage.sync.get("settings");
if (!settings) {
return null;
}
@@ -38,7 +38,7 @@ export class SyncSettingRepository implements SettingRepository {
onChange(callback: () => void) {
browser.storage.onChanged.addListener((changes, area) => {
- if (area !== 'sync') {
+ if (area !== "sync") {
return;
}
if (changes.settings) {
@@ -46,4 +46,4 @@ export class SyncSettingRepository implements SettingRepository {
}
});
}
-} \ No newline at end of file
+}
diff --git a/src/background/usecases/AddonEnabledUseCase.ts b/src/background/usecases/AddonEnabledUseCase.ts
index 51f02e1..f563ab0 100644
--- a/src/background/usecases/AddonEnabledUseCase.ts
+++ b/src/background/usecases/AddonEnabledUseCase.ts
@@ -1,21 +1,21 @@
-import { inject, injectable } from 'tsyringe';
-import IndicatorPresenter from '../presenters/IndicatorPresenter';
-import TabPresenter from '../presenters/TabPresenter';
-import ContentMessageClient from '../infrastructures/ContentMessageClient';
+import { inject, injectable } from "tsyringe";
+import IndicatorPresenter from "../presenters/IndicatorPresenter";
+import TabPresenter from "../presenters/TabPresenter";
+import ContentMessageClient from "../infrastructures/ContentMessageClient";
@injectable()
export default class AddonEnabledUseCase {
constructor(
private indicatorPresentor: IndicatorPresenter,
@inject("TabPresenter") private tabPresenter: TabPresenter,
- private contentMessageClient: ContentMessageClient,
+ private contentMessageClient: ContentMessageClient
) {
this.indicatorPresentor.onClick((tab) => {
if (tab.id) {
this.onIndicatorClick(tab.id);
}
});
- this.tabPresenter.onSelected(info => this.onTabSelected(info.tabId));
+ this.tabPresenter.onSelected((info) => this.onTabSelected(info.tabId));
}
indicate(enabled: boolean): Promise<void> {
diff --git a/src/background/usecases/CommandUseCase.ts b/src/background/usecases/CommandUseCase.ts
index d2d707e..811ec77 100644
--- a/src/background/usecases/CommandUseCase.ts
+++ b/src/background/usecases/CommandUseCase.ts
@@ -1,29 +1,29 @@
-import { injectable, inject } from 'tsyringe';
-import * as operations from '../../shared/operations';
-import * as parsers from './parsers';
-import * as urls from '../../shared/urls';
-import TabPresenter from '../presenters/TabPresenter';
-import WindowPresenter from '../presenters/WindowPresenter';
-import HelpPresenter from '../presenters/HelpPresenter';
-import CachedSettingRepository from '../repositories/CachedSettingRepository';
-import BookmarkRepository from '../repositories/BookmarkRepository';
-import ConsoleClient from '../infrastructures/ConsoleClient';
-import ContentMessageClient from '../infrastructures/ContentMessageClient';
-import RepeatUseCase from '../usecases/RepeatUseCase';
+import { injectable, inject } from "tsyringe";
+import * as operations from "../../shared/operations";
+import * as parsers from "./parsers";
+import * as urls from "../../shared/urls";
+import TabPresenter from "../presenters/TabPresenter";
+import WindowPresenter from "../presenters/WindowPresenter";
+import HelpPresenter from "../presenters/HelpPresenter";
+import CachedSettingRepository from "../repositories/CachedSettingRepository";
+import BookmarkRepository from "../repositories/BookmarkRepository";
+import ConsoleClient from "../infrastructures/ConsoleClient";
+import ContentMessageClient from "../infrastructures/ContentMessageClient";
+import RepeatUseCase from "../usecases/RepeatUseCase";
@injectable()
export default class CommandIndicator {
constructor(
- @inject('TabPresenter') private tabPresenter: TabPresenter,
+ @inject("TabPresenter") private tabPresenter: TabPresenter,
private windowPresenter: WindowPresenter,
private helpPresenter: HelpPresenter,
- @inject("CachedSettingRepository") private cachedSettingRepository: CachedSettingRepository,
+ @inject("CachedSettingRepository")
+ private cachedSettingRepository: CachedSettingRepository,
private bookmarkRepository: BookmarkRepository,
private consoleClient: ConsoleClient,
private contentMessageClient: ContentMessageClient,
- private repeatUseCase: RepeatUseCase,
- ) {
- }
+ private repeatUseCase: RepeatUseCase
+ ) {}
async open(keywords: string): Promise<browser.tabs.Tab> {
const url = await this.urlOrSearch(keywords);
@@ -67,14 +67,14 @@ export default class CommandIndicator {
throw new RangeError(`tab ${index + 1} does not exist`);
}
return this.tabPresenter.select(tabs[index].id as number);
- } else if (keywords.trim() === '%') {
+ } else if (keywords.trim() === "%") {
// Select current window
return;
- } else if (keywords.trim() === '#') {
+ } else if (keywords.trim() === "#") {
// Select last selected window
const lastId = await this.tabPresenter.getLastSelectedId();
- if (typeof lastId === 'undefined' || lastId === null) {
- throw new Error('No last selected tab');
+ if (typeof lastId === "undefined" || lastId === null) {
+ throw new Error("No last selected tab");
}
return this.tabPresenter.select(lastId);
}
@@ -82,7 +82,7 @@ export default class CommandIndicator {
const current = await this.tabPresenter.getCurrent();
const tabs = await this.tabPresenter.getByKeyword(keywords, false);
if (tabs.length === 0) {
- throw new RangeError('No matching buffer for ' + keywords);
+ throw new RangeError("No matching buffer for " + keywords);
}
for (const tab of tabs) {
if (tab.index > current.index) {
@@ -96,9 +96,9 @@ export default class CommandIndicator {
const excludePinned = !force;
const tabs = await this.tabPresenter.getByKeyword(keywords, excludePinned);
if (tabs.length === 0) {
- throw new Error('No matching buffer for ' + keywords);
+ throw new Error("No matching buffer for " + keywords);
} else if (tabs.length > 1) {
- throw new Error('More than one match for ' + keywords);
+ throw new Error("More than one match for " + keywords);
}
return this.tabPresenter.remove([tabs[0].id as number]);
}
@@ -106,7 +106,7 @@ export default class CommandIndicator {
async bdeletes(force: boolean, keywords: string): Promise<any> {
const excludePinned = !force;
const tabs = await this.tabPresenter.getByKeyword(keywords, excludePinned);
- const ids = tabs.map(tab => tab.id as number);
+ const ids = tabs.map((tab) => tab.id as number);
return this.tabPresenter.remove(ids);
}
@@ -117,14 +117,14 @@ export default class CommandIndicator {
async quitAll(): Promise<any> {
const tabs = await this.tabPresenter.getAll();
- const ids = tabs.map(tab => tab.id as number);
+ const ids = tabs.map((tab) => tab.id as number);
this.tabPresenter.remove(ids);
}
async addbookmark(title: string): Promise<any> {
const tab = await this.tabPresenter.getCurrent();
const item = await this.bookmarkRepository.create(title, tab.url as string);
- const message = 'Saved current page: ' + item.url;
+ const message = "Saved current page: " + item.url;
return this.consoleClient.showInfo(tab.id as number, message);
}
diff --git a/src/background/usecases/ConsoleUseCase.ts b/src/background/usecases/ConsoleUseCase.ts
index 2de5bc1..195c70f 100644
--- a/src/background/usecases/ConsoleUseCase.ts
+++ b/src/background/usecases/ConsoleUseCase.ts
@@ -1,59 +1,57 @@
-import { inject, injectable } from 'tsyringe';
-import TabPresenter from '../presenters/TabPresenter';
-import ConsoleClient from '../infrastructures/ConsoleClient';
+import { inject, injectable } from "tsyringe";
+import TabPresenter from "../presenters/TabPresenter";
+import ConsoleClient from "../infrastructures/ConsoleClient";
@injectable()
export default class ConsoleUseCase {
-
constructor(
- @inject('TabPresenter') private tabPresenter: TabPresenter,
- private consoleClient: ConsoleClient,
- ) {
- }
+ @inject("TabPresenter") private tabPresenter: TabPresenter,
+ private consoleClient: ConsoleClient
+ ) {}
async showCommand(): Promise<any> {
const tab = await this.tabPresenter.getCurrent();
- return this.consoleClient.showCommand(tab.id as number, '');
+ return this.consoleClient.showCommand(tab.id as number, "");
}
async showOpenCommand(alter: boolean): Promise<any> {
const tab = await this.tabPresenter.getCurrent();
- let command = 'open ';
+ let command = "open ";
if (alter) {
- command += tab.url || '';
+ command += tab.url || "";
}
return this.consoleClient.showCommand(tab.id as number, command);
}
async showTabopenCommand(alter: boolean): Promise<any> {
const tab = await this.tabPresenter.getCurrent();
- let command = 'tabopen ';
+ let command = "tabopen ";
if (alter) {
- command += tab.url || '';
+ command += tab.url || "";
}
return this.consoleClient.showCommand(tab.id as number, command);
}
async showWinopenCommand(alter: boolean): Promise<any> {
const tab = await this.tabPresenter.getCurrent();
- let command = 'winopen ';
+ let command = "winopen ";
if (alter) {
- command += tab.url || '';
+ command += tab.url || "";
}
return this.consoleClient.showCommand(tab.id as number, command);
}
async showBufferCommand(): Promise<any> {
const tab = await this.tabPresenter.getCurrent();
- const command = 'buffer ';
+ const command = "buffer ";
return this.consoleClient.showCommand(tab.id as number, command);
}
async showAddbookmarkCommand(alter: boolean): Promise<any> {
const tab = await this.tabPresenter.getCurrent();
- let command = 'addbookmark ';
+ let command = "addbookmark ";
if (alter) {
- command += tab.title || '';
+ command += tab.title || "";
}
return this.consoleClient.showCommand(tab.id as number, command);
}
diff --git a/src/background/usecases/FindUseCase.ts b/src/background/usecases/FindUseCase.ts
index cb41cd5..facc461 100644
--- a/src/background/usecases/FindUseCase.ts
+++ b/src/background/usecases/FindUseCase.ts
@@ -1,16 +1,15 @@
-import { inject, injectable } from 'tsyringe';
-import FindRepository from '../repositories/FindRepository';
-import TabPresenter from '../presenters/TabPresenter';
-import ConsoleClient from '../infrastructures/ConsoleClient';
+import { inject, injectable } from "tsyringe";
+import FindRepository from "../repositories/FindRepository";
+import TabPresenter from "../presenters/TabPresenter";
+import ConsoleClient from "../infrastructures/ConsoleClient";
@injectable()
export default class FindUseCase {
constructor(
- @inject('TabPresenter') private tabPresenter: TabPresenter,
+ @inject("TabPresenter") private tabPresenter: TabPresenter,
private findRepository: FindRepository,
- private consoleClient: ConsoleClient,
- ) {
- }
+ private consoleClient: ConsoleClient
+ ) {}
getKeyword(): Promise<string> {
return this.findRepository.getKeyword();
diff --git a/src/background/usecases/LinkUseCase.ts b/src/background/usecases/LinkUseCase.ts
index be076c7..d2cd464 100644
--- a/src/background/usecases/LinkUseCase.ts
+++ b/src/background/usecases/LinkUseCase.ts
@@ -1,24 +1,23 @@
-import { inject, injectable } from 'tsyringe';
-import TabPresenter from '../presenters/TabPresenter';
+import { inject, injectable } from "tsyringe";
+import TabPresenter from "../presenters/TabPresenter";
@injectable()
export default class LinkUseCase {
- constructor(
- @inject('TabPresenter') private tabPresenter: TabPresenter,
- ) {
- }
+ constructor(@inject("TabPresenter") private tabPresenter: TabPresenter) {}
openToTab(url: string, tabId: number): Promise<any> {
return this.tabPresenter.open(url, tabId);
}
async openNewTab(
- url: string, openerId: number, background: boolean,
+ url: string,
+ openerId: number,
+ background: boolean
): Promise<any> {
const properties: any = { active: !background };
const platform = await browser.runtime.getPlatformInfo();
- if (platform.os !== 'android') {
+ if (platform.os !== "android") {
// openerTabId not supported on Android
properties.openerTabId = openerId;
}
diff --git a/src/background/usecases/MarkUseCase.ts b/src/background/usecases/MarkUseCase.ts
index 2c0bc13..9da9a21 100644
--- a/src/background/usecases/MarkUseCase.ts
+++ b/src/background/usecases/MarkUseCase.ts
@@ -1,18 +1,17 @@
-import { inject, injectable } from 'tsyringe';
-import TabPresenter from '../presenters/TabPresenter';
-import MarkRepository from '../repositories/MarkRepository';
-import ConsoleClient from '../infrastructures/ConsoleClient';
-import ContentMessageClient from '../infrastructures/ContentMessageClient';
+import { inject, injectable } from "tsyringe";
+import TabPresenter from "../presenters/TabPresenter";
+import MarkRepository from "../repositories/MarkRepository";
+import ConsoleClient from "../infrastructures/ConsoleClient";
+import ContentMessageClient from "../infrastructures/ContentMessageClient";
@injectable()
export default class MarkUseCase {
constructor(
- @inject('TabPresenter') private tabPresenter: TabPresenter,
+ @inject("TabPresenter") private tabPresenter: TabPresenter,
private markRepository: MarkRepository,
private consoleClient: ConsoleClient,
- private contentMessageClient: ContentMessageClient,
- ) {
- }
+ private contentMessageClient: ContentMessageClient
+ ) {}
async setGlobal(key: string, x: number, y: number): Promise<any> {
const tab = await this.tabPresenter.getCurrent();
@@ -26,7 +25,9 @@ export default class MarkUseCase {
const mark = await this.markRepository.getMark(key);
if (!mark) {
return this.consoleClient.showError(
- current.id as number, 'Mark is not set');
+ current.id as number,
+ "Mark is not set"
+ );
}
try {
await this.contentMessageClient.scrollTo(mark.tabId, mark.x, mark.y);
@@ -34,7 +35,10 @@ export default class MarkUseCase {
} catch (e) {
const tab = await this.tabPresenter.create(mark.url);
return this.markRepository.setMark(key, {
- tabId: tab.id as number, url: mark.url, x: mark.x, y: mark.y,
+ tabId: tab.id as number,
+ url: mark.url,
+ x: mark.x,
+ y: mark.y,
});
}
}
diff --git a/src/background/usecases/NavigateUseCase.ts b/src/background/usecases/NavigateUseCase.ts
index 3aa1ed6..2e887e7 100644
--- a/src/background/usecases/NavigateUseCase.ts
+++ b/src/background/usecases/NavigateUseCase.ts
@@ -1,14 +1,13 @@
-import { inject, injectable } from 'tsyringe';
-import NavigateClient from '../clients/NavigateClient';
-import TabPresenter from '../presenters/TabPresenter';
+import { inject, injectable } from "tsyringe";
+import NavigateClient from "../clients/NavigateClient";
+import TabPresenter from "../presenters/TabPresenter";
@injectable()
export default class NavigateUseCase {
constructor(
- @inject('TabPresenter') private tabPresenter: TabPresenter,
- private navigateClient: NavigateClient,
- ) {
- }
+ @inject("TabPresenter") private tabPresenter: TabPresenter,
+ private navigateClient: NavigateClient
+ ) {}
async openHistoryNext(): Promise<void> {
const tab = await this.tabPresenter.getCurrent();
@@ -34,16 +33,16 @@ export default class NavigateUseCase {
const tab = await this.tabPresenter.getCurrent();
const url = new URL(tab.url!!);
if (url.hash.length > 0) {
- url.hash = '';
+ url.hash = "";
} else if (url.search.length > 0) {
- url.search = '';
+ url.search = "";
} else {
const basenamePattern = /\/[^/]+$/;
const lastDirPattern = /\/[^/]+\/$/;
if (basenamePattern.test(url.pathname)) {
- url.pathname = url.pathname.replace(basenamePattern, '/');
+ url.pathname = url.pathname.replace(basenamePattern, "/");
} else if (lastDirPattern.test(url.pathname)) {
- url.pathname = url.pathname.replace(lastDirPattern, '/');
+ url.pathname = url.pathname.replace(lastDirPattern, "/");
}
}
await this.tabPresenter.open(url.href);
diff --git a/src/background/usecases/RepeatUseCase.ts b/src/background/usecases/RepeatUseCase.ts
index d78de34..d7235ee 100644
--- a/src/background/usecases/RepeatUseCase.ts
+++ b/src/background/usecases/RepeatUseCase.ts
@@ -1,15 +1,12 @@
-import { injectable } from 'tsyringe';
-import * as operations from '../../shared/operations';
-import RepeatRepository from '../repositories/RepeatRepository';
+import { injectable } from "tsyringe";
+import * as operations from "../../shared/operations";
+import RepeatRepository from "../repositories/RepeatRepository";
type Operation = operations.Operation;
@injectable()
export default class RepeatUseCase {
- constructor(
- private repeatRepository: RepeatRepository,
- ) {
- }
+ constructor(private repeatRepository: RepeatRepository) {}
storeLastOperation(op: Operation): void {
this.repeatRepository.setLastOperation(op);
@@ -22,28 +19,28 @@ export default class RepeatUseCase {
// eslint-disable-next-line complexity
isRepeatable(op: Operation): boolean {
switch (op.type) {
- case operations.NAVIGATE_HISTORY_PREV:
- case operations.NAVIGATE_HISTORY_NEXT:
- case operations.NAVIGATE_LINK_PREV:
- case operations.NAVIGATE_LINK_NEXT:
- case operations.NAVIGATE_PARENT:
- case operations.NAVIGATE_ROOT:
- case operations.PAGE_SOURCE:
- case operations.PAGE_HOME:
- case operations.TAB_CLOSE:
- case operations.TAB_CLOSE_FORCE:
- case operations.TAB_CLOSE_RIGHT:
- case operations.TAB_REOPEN:
- case operations.TAB_RELOAD:
- case operations.TAB_PIN:
- case operations.TAB_UNPIN:
- case operations.TAB_TOGGLE_PINNED:
- case operations.TAB_DUPLICATE:
- case operations.ZOOM_IN:
- case operations.ZOOM_OUT:
- case operations.ZOOM_NEUTRAL:
- case operations.INTERNAL_OPEN_URL:
- return true;
+ case operations.NAVIGATE_HISTORY_PREV:
+ case operations.NAVIGATE_HISTORY_NEXT:
+ case operations.NAVIGATE_LINK_PREV:
+ case operations.NAVIGATE_LINK_NEXT:
+ case operations.NAVIGATE_PARENT:
+ case operations.NAVIGATE_ROOT:
+ case operations.PAGE_SOURCE:
+ case operations.PAGE_HOME:
+ case operations.TAB_CLOSE:
+ case operations.TAB_CLOSE_FORCE:
+ case operations.TAB_CLOSE_RIGHT:
+ case operations.TAB_REOPEN:
+ case operations.TAB_RELOAD:
+ case operations.TAB_PIN:
+ case operations.TAB_UNPIN:
+ case operations.TAB_TOGGLE_PINNED:
+ case operations.TAB_DUPLICATE:
+ case operations.ZOOM_IN:
+ case operations.ZOOM_OUT:
+ case operations.ZOOM_NEUTRAL:
+ case operations.INTERNAL_OPEN_URL:
+ return true;
}
return false;
}
diff --git a/src/background/usecases/SettingUseCase.ts b/src/background/usecases/SettingUseCase.ts
index 69b4572..ccee227 100644
--- a/src/background/usecases/SettingUseCase.ts
+++ b/src/background/usecases/SettingUseCase.ts
@@ -1,20 +1,21 @@
-import {inject, injectable} from 'tsyringe';
-import CachedSettingRepository from '../repositories/CachedSettingRepository';
-import SettingData, {DefaultSettingData} from '../../shared/SettingData';
-import Settings from '../../shared/settings/Settings';
-import Notifier from '../presenters/Notifier';
+import { inject, injectable } from "tsyringe";
+import CachedSettingRepository from "../repositories/CachedSettingRepository";
+import SettingData, { DefaultSettingData } from "../../shared/SettingData";
+import Settings from "../../shared/settings/Settings";
+import Notifier from "../presenters/Notifier";
import SettingRepository from "../repositories/SettingRepository";
@injectable()
export default class SettingUseCase {
-
constructor(
- @inject("LocalSettingRepository") private localSettingRepository: SettingRepository,
- @inject("SyncSettingRepository") private syncSettingRepository: SettingRepository,
- @inject("CachedSettingRepository") private cachedSettingRepository: CachedSettingRepository,
- @inject("Notifier") private notifier: Notifier,
- ) {
- }
+ @inject("LocalSettingRepository")
+ private localSettingRepository: SettingRepository,
+ @inject("SyncSettingRepository")
+ private syncSettingRepository: SettingRepository,
+ @inject("CachedSettingRepository")
+ private cachedSettingRepository: CachedSettingRepository,
+ @inject("Notifier") private notifier: Notifier
+ ) {}
getCached(): Promise<Settings> {
return this.cachedSettingRepository.get();
@@ -42,7 +43,7 @@ export default class SettingUseCase {
private async loadSettings(): Promise<SettingData> {
const sync = await this.syncSettingRepository.load();
if (sync) {
- return sync;
+ return sync;
}
const local = await this.localSettingRepository.load();
if (local) {
@@ -52,7 +53,7 @@ export default class SettingUseCase {
}
private showUnableToLoad(e: Error) {
- console.error('unable to load settings', e);
+ console.error("unable to load settings", e);
this.notifier.notifyInvalidSettings(() => {
browser.runtime.openOptionsPage();
});
diff --git a/src/background/usecases/TabSelectUseCase.ts b/src/background/usecases/TabSelectUseCase.ts
index 271bb6c..663ceb8 100644
--- a/src/background/usecases/TabSelectUseCase.ts
+++ b/src/background/usecases/TabSelectUseCase.ts
@@ -1,19 +1,16 @@
-import { inject, injectable } from 'tsyringe';
-import TabPresenter from '../presenters/TabPresenter';
+import { inject, injectable } from "tsyringe";
+import TabPresenter from "../presenters/TabPresenter";
@injectable()
export default class TabSelectUseCase {
- constructor(
- @inject('TabPresenter') private tabPresenter: TabPresenter,
- ) {
- }
+ constructor(@inject("TabPresenter") private tabPresenter: TabPresenter) {}
async selectPrev(count: number): Promise<any> {
const tabs = await this.tabPresenter.getAll();
if (tabs.length < 2) {
return;
}
- const tab = tabs.find(t => t.active);
+ const tab = tabs.find((t) => t.active);
if (!tab) {
return;
}
@@ -26,7 +23,7 @@ export default class TabSelectUseCase {
if (tabs.length < 2) {
return;
}
- const tab = tabs.find(t => t.active);
+ const tab = tabs.find((t) => t.active);
if (!tab) {
return;
}
@@ -46,7 +43,7 @@ export default class TabSelectUseCase {
async selectPrevSelected(): Promise<any> {
const tabId = await this.tabPresenter.getLastSelectedId();
- if (tabId === null || typeof tabId === 'undefined') {
+ if (tabId === null || typeof tabId === "undefined") {
return Promise.resolve();
}
return this.tabPresenter.select(tabId);
diff --git a/src/background/usecases/TabUseCase.ts b/src/background/usecases/TabUseCase.ts
index 418dde5..1439107 100644
--- a/src/background/usecases/TabUseCase.ts
+++ b/src/background/usecases/TabUseCase.ts
@@ -1,16 +1,15 @@
-import {inject, injectable} from 'tsyringe';
-import TabPresenter from '../presenters/TabPresenter';
-import WindowPresenter from '../presenters/WindowPresenter';
-import BrowserSettingRepository from '../repositories/BrowserSettingRepository';
+import { inject, injectable } from "tsyringe";
+import TabPresenter from "../presenters/TabPresenter";
+import WindowPresenter from "../presenters/WindowPresenter";
+import BrowserSettingRepository from "../repositories/BrowserSettingRepository";
@injectable()
export default class TabUseCase {
constructor(
- @inject('TabPresenter') private tabPresenter: TabPresenter,
+ @inject("TabPresenter") private tabPresenter: TabPresenter,
private windowPresenter: WindowPresenter,
- private browserSettingRepository: BrowserSettingRepository,
- ) {
- }
+ private browserSettingRepository: BrowserSettingRepository
+ ) {}
async close(force: boolean, selectLeft = false): Promise<any> {
const tab = await this.tabPresenter.getCurrent();
@@ -27,7 +26,7 @@ export default class TabUseCase {
async closeRight(): Promise<any> {
const tabs = await this.tabPresenter.getAll();
tabs.sort((t1, t2) => t1.index - t2.index);
- const index = tabs.findIndex(t => t.active);
+ const index = tabs.findIndex((t) => t.active);
if (index < 0) {
return;
}
@@ -65,16 +64,18 @@ export default class TabUseCase {
async openPageSource(): Promise<any> {
const tab = await this.tabPresenter.getCurrent();
- const url = 'view-source:' + tab.url;
+ const url = "view-source:" + tab.url;
return this.tabPresenter.create(url);
}
async openHome(newTab: boolean): Promise<any> {
const tab = await this.tabPresenter.getCurrent();
const urls = await this.browserSettingRepository.getHomepageUrls();
- if (urls.length === 1 && urls[0] === 'about:home') {
+ if (urls.length === 1 && urls[0] === "about:home") {
// eslint-disable-next-line max-len
- throw new Error('Cannot open Firefox Home (about:home) by WebExtensions, set your custom URLs');
+ throw new Error(
+ "Cannot open Firefox Home (about:home) by WebExtensions, set your custom URLs"
+ );
}
if (urls.length === 1 && !newTab) {
return this.tabPresenter.open(urls[0], tab.id);
@@ -85,7 +86,9 @@ export default class TabUseCase {
}
async openURL(
- url: string, newTab?: boolean, newWindow?: boolean,
+ url: string,
+ newTab?: boolean,
+ newWindow?: boolean
): Promise<void> {
if (newWindow) {
await this.windowPresenter.create(url);
diff --git a/src/background/usecases/VersionUseCase.ts b/src/background/usecases/VersionUseCase.ts
index 21a5e2c..74df8a8 100644
--- a/src/background/usecases/VersionUseCase.ts
+++ b/src/background/usecases/VersionUseCase.ts
@@ -1,14 +1,13 @@
-import { injectable, inject } from 'tsyringe';
-import TabPresenter from '../presenters/TabPresenter';
-import Notifier from '../presenters/Notifier';
+import { injectable, inject } from "tsyringe";
+import TabPresenter from "../presenters/TabPresenter";
+import Notifier from "../presenters/Notifier";
@injectable()
export default class VersionUseCase {
constructor(
- @inject('TabPresenter') private tabPresenter: TabPresenter,
- @inject("Notifier") private notifier: Notifier,
- ) {
- }
+ @inject("TabPresenter") private tabPresenter: TabPresenter,
+ @inject("Notifier") private notifier: Notifier
+ ) {}
notify(): Promise<void> {
const manifest = browser.runtime.getManifest();
@@ -22,6 +21,6 @@ export default class VersionUseCase {
if (version) {
return `https://github.com/ueokande/vim-vixen/releases/tag/${version}`;
}
- return 'https://github.com/ueokande/vim-vixen/releases/';
+ return "https://github.com/ueokande/vim-vixen/releases/";
}
}
diff --git a/src/background/usecases/ZoomUseCase.ts b/src/background/usecases/ZoomUseCase.ts
index ca1368d..173e4d7 100644
--- a/src/background/usecases/ZoomUseCase.ts
+++ b/src/background/usecases/ZoomUseCase.ts
@@ -1,23 +1,32 @@
-import { inject, injectable } from 'tsyringe';
-import TabPresenter from '../presenters/TabPresenter';
+import { inject, injectable } from "tsyringe";
+import TabPresenter from "../presenters/TabPresenter";
const ZOOM_SETTINGS: number[] = [
- 0.33, 0.50, 0.66, 0.75, 0.80, 0.90, 1.00,
- 1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00
+ 0.33,
+ 0.5,
+ 0.66,
+ 0.75,
+ 0.8,
+ 0.9,
+ 1.0,
+ 1.1,
+ 1.25,
+ 1.5,
+ 1.75,
+ 2.0,
+ 2.5,
+ 3.0,
];
@injectable()
export default class ZoomUseCase {
- constructor(
- @inject('TabPresenter') private tabPresenter: TabPresenter,
- ) {
- }
+ constructor(@inject("TabPresenter") private tabPresenter: TabPresenter) {}
async zoomIn(): Promise<any> {
const tab = await this.tabPresenter.getCurrent();
const tabId = tab.id as number;
const current = await this.tabPresenter.getZoom(tabId);
- const factor = ZOOM_SETTINGS.find(f => f > current);
+ const factor = ZOOM_SETTINGS.find((f) => f > current);
if (factor) {
return this.tabPresenter.setZoom(tabId as number, factor);
}
@@ -27,7 +36,9 @@ export default class ZoomUseCase {
const tab = await this.tabPresenter.getCurrent();
const tabId = tab.id as number;
const current = await this.tabPresenter.getZoom(tabId);
- const factor = ZOOM_SETTINGS.slice(0).reverse().find(f => f < current);
+ const factor = ZOOM_SETTINGS.slice(0)
+ .reverse()
+ .find((f) => f < current);
if (factor) {
return this.tabPresenter.setZoom(tabId as number, factor);
}
diff --git a/src/background/usecases/parsers.ts b/src/background/usecases/parsers.ts
index 99ff2eb..23a6193 100644
--- a/src/background/usecases/parsers.ts
+++ b/src/background/usecases/parsers.ts
@@ -1,36 +1,39 @@
-import Properties from '../../shared/settings/Properties';
+import Properties from "../../shared/settings/Properties";
const mustNumber = (v: any): number => {
const num = Number(v);
if (isNaN(num)) {
- throw new Error('Not number: ' + v);
+ throw new Error("Not number: " + v);
}
return num;
};
-const parseSetOption = (
- args: string,
-): any[] => {
- let [key, value]: any[] = args.split('=');
+const parseSetOption = (args: string): any[] => {
+ let [key, value]: any[] = args.split("=");
if (value === undefined) {
- value = !key.startsWith('no');
+ value = !key.startsWith("no");
key = value ? key : key.slice(2);
}
const def = Properties.def(key);
if (!def) {
- throw new Error('Unknown property: ' + key);
+ throw new Error("Unknown property: " + key);
}
- if (def.type === 'boolean' && typeof value !== 'boolean' ||
- def.type !== 'boolean' && typeof value === 'boolean') {
- throw new Error('Invalid argument: ' + args);
+ if (
+ (def.type === "boolean" && typeof value !== "boolean") ||
+ (def.type !== "boolean" && typeof value === "boolean")
+ ) {
+ throw new Error("Invalid argument: " + args);
}
switch (def.type) {
- case 'string': return [key, value];
- case 'number': return [key, mustNumber(value)];
- case 'boolean': return [key, value];
- default:
- throw new Error('Unknown property type: ' + def.type);
+ case "string":
+ return [key, value];
+ case "number":
+ return [key, mustNumber(value)];
+ case "boolean":
+ return [key, value];
+ default:
+ throw new Error("Unknown property type: " + def.type);
}
};