Use TSyringe on background script

jh-changes
Shin'ya Ueoka 6 years ago
parent c7803e7c29
commit cdfd54ed99
  1. 35
      src/background/Application.ts
  2. 8
      src/background/controllers/AddonEnabledController.ts
  3. 13
      src/background/controllers/CommandController.ts
  4. 9
      src/background/controllers/FindController.ts
  5. 9
      src/background/controllers/LinkController.ts
  6. 9
      src/background/controllers/MarkController.ts
  7. 25
      src/background/controllers/OperationController.ts
  8. 13
      src/background/controllers/SettingController.ts
  9. 9
      src/background/controllers/VersionController.ts
  10. 27
      src/background/index.ts
  11. 2
      src/background/infrastructures/ConsoleClient.ts
  12. 2
      src/background/infrastructures/ContentMessageClient.ts
  13. 34
      src/background/infrastructures/ContentMessageListener.ts
  14. 3
      src/background/presenters/IndicatorPresenter.ts
  15. 3
      src/background/presenters/NotifyPresenter.ts
  16. 2
      src/background/presenters/TabPresenter.ts
  17. 3
      src/background/presenters/WindowPresenter.ts
  18. 3
      src/background/repositories/BookmarkRepository.ts
  19. 2
      src/background/repositories/BrowserSettingRepository.ts
  20. 3
      src/background/repositories/CompletionsRepository.ts
  21. 2
      src/background/repositories/FindRepository.ts
  22. 2
      src/background/repositories/MarkRepository.ts
  23. 2
      src/background/repositories/PersistentSettingRepository.ts
  24. 2
      src/background/repositories/SettingRepository.ts
  25. 20
      src/background/usecases/AddonEnabledUseCase.ts
  26. 30
      src/background/usecases/CommandUseCase.ts
  27. 17
      src/background/usecases/CompletionsUseCase.ts
  28. 12
      src/background/usecases/ConsoleUseCase.ts
  29. 17
      src/background/usecases/FindUseCase.ts
  30. 9
      src/background/usecases/LinkUseCase.ts
  31. 21
      src/background/usecases/MarkUseCase.ts
  32. 16
      src/background/usecases/SettingUseCase.ts
  33. 9
      src/background/usecases/TabSelectUseCase.ts
  34. 13
      src/background/usecases/TabUseCase.ts
  35. 13
      src/background/usecases/VersionUseCase.ts
  36. 9
      src/background/usecases/ZoomUseCase.ts
  37. 6
      test/main.ts

@ -0,0 +1,35 @@
import { injectable } from 'tsyringe';
import ContentMessageListener from './infrastructures/ContentMessageListener';
import SettingController from './controllers/SettingController';
import VersionController from './controllers/VersionController';
@injectable()
export default class Application {
constructor(
private contentMessageListener: ContentMessageListener,
private settingController: SettingController,
private versionController: VersionController,
) {
}
run() {
this.settingController.reload();
browser.runtime.onInstalled.addListener((details) => {
if (details.reason !== 'install' && details.reason !== 'update') {
return;
}
this.versionController.notify();
});
this.contentMessageListener.run();
browser.storage.onChanged.addListener((changes, area) => {
if (area !== 'local') {
return;
}
if (changes.settings) {
this.settingController.reload();
}
});
}
}

@ -1,10 +1,12 @@
import { injectable } from 'tsyringe';
import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase'; import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase';
@injectable()
export default class AddonEnabledController { export default class AddonEnabledController {
private addonEnabledUseCase: AddonEnabledUseCase;
constructor() { constructor(
this.addonEnabledUseCase = new AddonEnabledUseCase(); private addonEnabledUseCase: AddonEnabledUseCase,
) {
} }
indicate(enabled: boolean): Promise<any> { indicate(enabled: boolean): Promise<any> {

@ -1,3 +1,4 @@
import { injectable } from 'tsyringe';
import CompletionsUseCase from '../usecases/CompletionsUseCase'; import CompletionsUseCase from '../usecases/CompletionsUseCase';
import CommandUseCase from '../usecases/CommandUseCase'; import CommandUseCase from '../usecases/CommandUseCase';
import CompletionGroup from '../domains/CompletionGroup'; import CompletionGroup from '../domains/CompletionGroup';
@ -7,14 +8,12 @@ const trimStart = (str: string): string => {
return str.replace(/^\s+/, ''); return str.replace(/^\s+/, '');
}; };
@injectable()
export default class CommandController { export default class CommandController {
private completionsUseCase: CompletionsUseCase; constructor(
private completionsUseCase: CompletionsUseCase,
private commandIndicator: CommandUseCase; private commandIndicator: CommandUseCase,
) {
constructor() {
this.completionsUseCase = new CompletionsUseCase();
this.commandIndicator = new CommandUseCase();
} }
getCompletions(line: string): Promise<CompletionGroup[]> { getCompletions(line: string): Promise<CompletionGroup[]> {

@ -1,10 +1,11 @@
import { injectable } from 'tsyringe';
import FindUseCase from '../usecases/FindUseCase'; import FindUseCase from '../usecases/FindUseCase';
@injectable()
export default class FindController { export default class FindController {
private findUseCase: FindUseCase; constructor(
private findUseCase: FindUseCase,
constructor() { ) {
this.findUseCase = new FindUseCase();
} }
getKeyword(): Promise<string> { getKeyword(): Promise<string> {

@ -1,10 +1,11 @@
import { injectable } from 'tsyringe';
import LinkUseCase from '../usecases/LinkUseCase'; import LinkUseCase from '../usecases/LinkUseCase';
@injectable()
export default class LinkController { export default class LinkController {
private linkUseCase: LinkUseCase; constructor(
private linkUseCase: LinkUseCase,
constructor() { ) {
this.linkUseCase = new LinkUseCase();
} }
openToTab(url: string, tabId: number): Promise<void> { openToTab(url: string, tabId: number): Promise<void> {

@ -1,10 +1,11 @@
import { injectable } from 'tsyringe';
import MarkUseCase from '../usecases/MarkUseCase'; import MarkUseCase from '../usecases/MarkUseCase';
@injectable()
export default class MarkController { export default class MarkController {
private markUseCase: MarkUseCase; constructor(
private markUseCase: MarkUseCase,
constructor() { ) {
this.markUseCase = new MarkUseCase();
} }
setGlobal(key: string, x: number, y: number): Promise<any> { setGlobal(key: string, x: number, y: number): Promise<any> {

@ -1,3 +1,4 @@
import { injectable } from 'tsyringe';
import * as operations from '../../shared/operations'; import * as operations from '../../shared/operations';
import FindUseCase from '../usecases/FindUseCase'; import FindUseCase from '../usecases/FindUseCase';
import ConsoleUseCase from '../usecases/ConsoleUseCase'; import ConsoleUseCase from '../usecases/ConsoleUseCase';
@ -5,23 +6,15 @@ import TabUseCase from '../usecases/TabUseCase';
import TabSelectUseCase from '../usecases/TabSelectUseCase'; import TabSelectUseCase from '../usecases/TabSelectUseCase';
import ZoomUseCase from '../usecases/ZoomUseCase'; import ZoomUseCase from '../usecases/ZoomUseCase';
@injectable()
export default class OperationController { export default class OperationController {
private findUseCase: FindUseCase; constructor(
private findUseCase: FindUseCase,
private consoleUseCase: ConsoleUseCase; private consoleUseCase: ConsoleUseCase,
private tabUseCase: TabUseCase,
private tabUseCase: TabUseCase; private tabSelectUseCase: TabSelectUseCase,
private zoomUseCase: ZoomUseCase,
private tabSelectUseCase: TabSelectUseCase; ) {
private zoomUseCase: ZoomUseCase;
constructor() {
this.findUseCase = new FindUseCase();
this.consoleUseCase = new ConsoleUseCase();
this.tabUseCase = new TabUseCase();
this.tabSelectUseCase = new TabSelectUseCase();
this.zoomUseCase = new ZoomUseCase();
} }
// eslint-disable-next-line complexity, max-lines-per-function // eslint-disable-next-line complexity, max-lines-per-function

@ -1,15 +1,14 @@
import { injectable } from 'tsyringe';
import SettingUseCase from '../usecases/SettingUseCase'; import SettingUseCase from '../usecases/SettingUseCase';
import ContentMessageClient from '../infrastructures/ContentMessageClient'; import ContentMessageClient from '../infrastructures/ContentMessageClient';
import Settings from '../../shared/Settings'; import Settings from '../../shared/Settings';
@injectable()
export default class SettingController { export default class SettingController {
private settingUseCase: SettingUseCase; constructor(
private settingUseCase: SettingUseCase,
private contentMessageClient: ContentMessageClient; private contentMessageClient: ContentMessageClient,
) {
constructor() {
this.settingUseCase = new SettingUseCase();
this.contentMessageClient = new ContentMessageClient();
} }
getSetting(): Promise<Settings> { getSetting(): Promise<Settings> {

@ -1,10 +1,11 @@
import { injectable } from 'tsyringe';
import VersionUseCase from '../usecases/VersionUseCase'; import VersionUseCase from '../usecases/VersionUseCase';
@injectable()
export default class VersionController { export default class VersionController {
private versionUseCase: VersionUseCase; constructor(
private versionUseCase: VersionUseCase,
constructor() { ) {
this.versionUseCase = new VersionUseCase();
} }
notify(): Promise<void> { notify(): Promise<void> {

@ -1,23 +1,6 @@
import ContentMessageListener from './infrastructures/ContentMessageListener'; import 'reflect-metadata';
import SettingController from './controllers/SettingController'; import { container } from 'tsyringe';
import VersionController from './controllers/VersionController'; import Application from './Application';
let settingController = new SettingController(); let app = container.resolve(Application);
settingController.reload(); app.run();
browser.runtime.onInstalled.addListener((details) => {
if (details.reason !== 'install' && details.reason !== 'update') {
return;
}
new VersionController().notify();
});
new ContentMessageListener().run();
browser.storage.onChanged.addListener((changes, area) => {
if (area !== 'local') {
return;
}
if (changes.settings) {
settingController.reload();
}
});

@ -1,5 +1,7 @@
import { injectable } from 'tsyringe';
import * as messages from '../../shared/messages'; import * as messages from '../../shared/messages';
@injectable()
export default class ConsoleClient { export default class ConsoleClient {
showCommand(tabId: number, command: string): Promise<any> { showCommand(tabId: number, command: string): Promise<any> {
return browser.tabs.sendMessage(tabId, { return browser.tabs.sendMessage(tabId, {

@ -1,5 +1,7 @@
import { injectable } from 'tsyringe';
import * as messages from '../../shared/messages'; import * as messages from '../../shared/messages';
@injectable()
export default class ContentMessageClient { export default class ContentMessageClient {
async broadcastSettingsChanged(): Promise<void> { async broadcastSettingsChanged(): Promise<void> {
let tabs = await browser.tabs.query({}); let tabs = await browser.tabs.query({});

@ -1,3 +1,4 @@
import { injectable } from 'tsyringe';
import * as messages from '../../shared/messages'; import * as messages from '../../shared/messages';
import CompletionGroup from '../domains/CompletionGroup'; import CompletionGroup from '../domains/CompletionGroup';
import CommandController from '../controllers/CommandController'; import CommandController from '../controllers/CommandController';
@ -8,32 +9,19 @@ import LinkController from '../controllers/LinkController';
import OperationController from '../controllers/OperationController'; import OperationController from '../controllers/OperationController';
import MarkController from '../controllers/MarkController'; import MarkController from '../controllers/MarkController';
@injectable()
export default class ContentMessageListener { export default class ContentMessageListener {
private settingController: SettingController;
private commandController: CommandController;
private findController: FindController;
private addonEnabledController: AddonEnabledController;
private linkController: LinkController;
private backgroundOperationController: OperationController;
private markController: MarkController;
private consolePorts: {[tabId: number]: browser.runtime.Port}; private consolePorts: {[tabId: number]: browser.runtime.Port};
constructor() { constructor(
this.settingController = new SettingController(); private settingController: SettingController,
this.commandController = new CommandController(); private commandController: CommandController,
this.findController = new FindController(); private findController: FindController,
this.addonEnabledController = new AddonEnabledController(); private addonEnabledController: AddonEnabledController,
this.linkController = new LinkController(); private linkController: LinkController,
this.backgroundOperationController = new OperationController(); private backgroundOperationController: OperationController,
this.markController = new MarkController(); private markController: MarkController,
) {
this.consolePorts = {}; this.consolePorts = {};
} }

@ -1,3 +1,6 @@
import { injectable } from 'tsyringe';
@injectable()
export default class IndicatorPresenter { export default class IndicatorPresenter {
indicate(enabled: boolean): Promise<void> { indicate(enabled: boolean): Promise<void> {
let path = enabled let path = enabled

@ -1,5 +1,8 @@
import { injectable } from 'tsyringe';
const NOTIFICATION_ID = 'vimvixen-update'; const NOTIFICATION_ID = 'vimvixen-update';
@injectable()
export default class NotifyPresenter { export default class NotifyPresenter {
async notify( async notify(
title: string, title: string,

@ -1,3 +1,4 @@
import { injectable } from 'tsyringe';
import MemoryStorage from '../infrastructures/MemoryStorage'; import MemoryStorage from '../infrastructures/MemoryStorage';
const CURRENT_SELECTED_KEY = 'tabs.current.selected'; const CURRENT_SELECTED_KEY = 'tabs.current.selected';
@ -5,6 +6,7 @@ const LAST_SELECTED_KEY = 'tabs.last.selected';
type Tab = browser.tabs.Tab; type Tab = browser.tabs.Tab;
@injectable()
export default class TabPresenter { export default class TabPresenter {
open(url: string, tabId?: number): Promise<Tab> { open(url: string, tabId?: number): Promise<Tab> {
return browser.tabs.update(tabId, { url }); return browser.tabs.update(tabId, { url });

@ -1,3 +1,6 @@
import { injectable } from 'tsyringe';
@injectable()
export default class WindowPresenter { export default class WindowPresenter {
create(url: string): Promise<browser.windows.Window> { create(url: string): Promise<browser.windows.Window> {
return browser.windows.create({ url }); return browser.windows.create({ url });

@ -1,3 +1,6 @@
import { injectable } from 'tsyringe';
@injectable()
export default class BookmarkRepository { export default class BookmarkRepository {
async create( async create(
title: string, url: string title: string, url: string

@ -1,3 +1,4 @@
import { injectable } from 'tsyringe';
import * as urls from '../../shared/urls'; import * as urls from '../../shared/urls';
declare namespace browser.browserSettings.homepageOverride { declare namespace browser.browserSettings.homepageOverride {
@ -16,6 +17,7 @@ declare namespace browser.browserSettings.homepageOverride {
function get(param: object): Promise<BrowserSettings>; function get(param: object): Promise<BrowserSettings>;
} }
@injectable()
export default class BrowserSettingRepository { export default class BrowserSettingRepository {
async getHomepageUrls(): Promise<string[]> { async getHomepageUrls(): Promise<string[]> {
let { value } = await browser.browserSettings.homepageOverride.get({}); let { value } = await browser.browserSettings.homepageOverride.get({});

@ -1,6 +1,9 @@
import { injectable } from 'tsyringe';
type Tab = browser.tabs.Tab; type Tab = browser.tabs.Tab;
type BookmarkTreeNode = browser.bookmarks.BookmarkTreeNode; type BookmarkTreeNode = browser.bookmarks.BookmarkTreeNode;
@injectable()
export default class CompletionsRepository { export default class CompletionsRepository {
async queryBookmarks(keywords: string): Promise<BookmarkTreeNode[]> { async queryBookmarks(keywords: string): Promise<BookmarkTreeNode[]> {
let items = await browser.bookmarks.search({ query: keywords }); let items = await browser.bookmarks.search({ query: keywords });

@ -1,7 +1,9 @@
import { injectable } from 'tsyringe';
import MemoryStorage from '../infrastructures/MemoryStorage'; import MemoryStorage from '../infrastructures/MemoryStorage';
const FIND_KEYWORD_KEY = 'find-keyword'; const FIND_KEYWORD_KEY = 'find-keyword';
@injectable()
export default class FindRepository { export default class FindRepository {
private cache: MemoryStorage; private cache: MemoryStorage;

@ -1,8 +1,10 @@
import { injectable } from 'tsyringe';
import MemoryStorage from '../infrastructures/MemoryStorage'; import MemoryStorage from '../infrastructures/MemoryStorage';
import GlobalMark from '../domains/GlobalMark'; import GlobalMark from '../domains/GlobalMark';
const MARK_KEY = 'mark'; const MARK_KEY = 'mark';
@injectable()
export default class MarkRepository { export default class MarkRepository {
private cache: MemoryStorage; private cache: MemoryStorage;

@ -1,5 +1,7 @@
import { injectable } from 'tsyringe';
import SettingData from '../../shared/SettingData'; import SettingData from '../../shared/SettingData';
@injectable()
export default class SettingRepository { export default class SettingRepository {
async load(): Promise<SettingData | null> { async load(): Promise<SettingData | null> {
let { settings } = await browser.storage.local.get('settings'); let { settings } = await browser.storage.local.get('settings');

@ -1,9 +1,11 @@
import { injectable } from 'tsyringe';
import MemoryStorage from '../infrastructures/MemoryStorage'; import MemoryStorage from '../infrastructures/MemoryStorage';
import Settings from '../../shared/Settings'; import Settings from '../../shared/Settings';
import * as PropertyDefs from '../../shared/property-defs'; import * as PropertyDefs from '../../shared/property-defs';
const CACHED_SETTING_KEY = 'setting'; const CACHED_SETTING_KEY = 'setting';
@injectable()
export default class SettingRepository { export default class SettingRepository {
private cache: MemoryStorage; private cache: MemoryStorage;

@ -1,27 +1,21 @@
import { injectable } from 'tsyringe';
import IndicatorPresenter from '../presenters/IndicatorPresenter'; import IndicatorPresenter from '../presenters/IndicatorPresenter';
import TabPresenter from '../presenters/TabPresenter'; import TabPresenter from '../presenters/TabPresenter';
import ContentMessageClient from '../infrastructures/ContentMessageClient'; import ContentMessageClient from '../infrastructures/ContentMessageClient';
@injectable()
export default class AddonEnabledUseCase { export default class AddonEnabledUseCase {
private indicatorPresentor: IndicatorPresenter; constructor(
private indicatorPresentor: IndicatorPresenter,
private tabPresenter: TabPresenter; private tabPresenter: TabPresenter,
private contentMessageClient: ContentMessageClient,
private contentMessageClient: ContentMessageClient; ) {
constructor() {
this.indicatorPresentor = new IndicatorPresenter();
this.indicatorPresentor.onClick((tab) => { this.indicatorPresentor.onClick((tab) => {
if (tab.id) { if (tab.id) {
this.onIndicatorClick(tab.id); this.onIndicatorClick(tab.id);
} }
}); });
this.tabPresenter = new TabPresenter();
this.tabPresenter.onSelected(info => this.onTabSelected(info.tabId)); this.tabPresenter.onSelected(info => this.onTabSelected(info.tabId));
this.contentMessageClient = new ContentMessageClient();
} }
indicate(enabled: boolean): Promise<void> { indicate(enabled: boolean): Promise<void> {

@ -1,3 +1,4 @@
import { injectable } from 'tsyringe';
import * as parsers from './parsers'; import * as parsers from './parsers';
import * as urls from '../../shared/urls'; import * as urls from '../../shared/urls';
import TabPresenter from '../presenters/TabPresenter'; import TabPresenter from '../presenters/TabPresenter';
@ -7,27 +8,16 @@ import BookmarkRepository from '../repositories/BookmarkRepository';
import ConsoleClient from '../infrastructures/ConsoleClient'; import ConsoleClient from '../infrastructures/ConsoleClient';
import ContentMessageClient from '../infrastructures/ContentMessageClient'; import ContentMessageClient from '../infrastructures/ContentMessageClient';
@injectable()
export default class CommandIndicator { export default class CommandIndicator {
private tabPresenter: TabPresenter; constructor(
private tabPresenter: TabPresenter,
private windowPresenter: WindowPresenter; private windowPresenter: WindowPresenter,
private settingRepository: SettingRepository,
private settingRepository: SettingRepository; private bookmarkRepository: BookmarkRepository,
private consoleClient: ConsoleClient,
private bookmarkRepository: BookmarkRepository; private contentMessageClient: ContentMessageClient,
) {
private consoleClient: ConsoleClient;
private contentMessageClient: ContentMessageClient;
constructor() {
this.tabPresenter = new TabPresenter();
this.windowPresenter = new WindowPresenter();
this.settingRepository = new SettingRepository();
this.bookmarkRepository = new BookmarkRepository();
this.consoleClient = new ConsoleClient();
this.contentMessageClient = new ContentMessageClient();
} }
async open(keywords: string): Promise<browser.tabs.Tab> { async open(keywords: string): Promise<browser.tabs.Tab> {

@ -1,3 +1,4 @@
import { injectable } from 'tsyringe';
import CompletionGroup from '../domains/CompletionGroup'; import CompletionGroup from '../domains/CompletionGroup';
import CommandDocs from '../domains/CommandDocs'; import CommandDocs from '../domains/CommandDocs';
import CompletionsRepository from '../repositories/CompletionsRepository'; import CompletionsRepository from '../repositories/CompletionsRepository';
@ -11,17 +12,13 @@ const COMPLETION_ITEM_LIMIT = 10;
type Tab = browser.tabs.Tab; type Tab = browser.tabs.Tab;
type HistoryItem = browser.history.HistoryItem; type HistoryItem = browser.history.HistoryItem;
@injectable()
export default class CompletionsUseCase { export default class CompletionsUseCase {
private tabPresenter: TabPresenter; constructor(
private tabPresenter: TabPresenter,
private completionsRepository: CompletionsRepository; private completionsRepository: CompletionsRepository,
private settingRepository: SettingRepository,
private settingRepository: SettingRepository; ) {
constructor() {
this.tabPresenter = new TabPresenter();
this.completionsRepository = new CompletionsRepository();
this.settingRepository = new SettingRepository();
} }
queryConsoleCommand(prefix: string): Promise<CompletionGroup[]> { queryConsoleCommand(prefix: string): Promise<CompletionGroup[]> {

@ -1,14 +1,14 @@
import { injectable } from 'tsyringe';
import TabPresenter from '../presenters/TabPresenter'; import TabPresenter from '../presenters/TabPresenter';
import ConsoleClient from '../infrastructures/ConsoleClient'; import ConsoleClient from '../infrastructures/ConsoleClient';
@injectable()
export default class ConsoleUseCase { export default class ConsoleUseCase {
private tabPresenter: TabPresenter;
private consoleClient: ConsoleClient; constructor(
private tabPresenter: TabPresenter,
constructor() { private consoleClient: ConsoleClient,
this.tabPresenter = new TabPresenter(); ) {
this.consoleClient = new ConsoleClient();
} }
async showCommand(): Promise<any> { async showCommand(): Promise<any> {

@ -1,18 +1,15 @@
import { injectable } from 'tsyringe';
import FindRepository from '../repositories/FindRepository'; import FindRepository from '../repositories/FindRepository';
import TabPresenter from '../presenters/TabPresenter'; import TabPresenter from '../presenters/TabPresenter';
import ConsoleClient from '../infrastructures/ConsoleClient'; import ConsoleClient from '../infrastructures/ConsoleClient';
@injectable()
export default class FindUseCase { export default class FindUseCase {
private tabPresenter: TabPresenter; constructor(
private tabPresenter: TabPresenter,
private findRepository: FindRepository; private findRepository: FindRepository,
private consoleClient: ConsoleClient,
private consoleClient: ConsoleClient; ) {
constructor() {
this.tabPresenter = new TabPresenter();
this.findRepository = new FindRepository();
this.consoleClient = new ConsoleClient();
} }
getKeyword(): Promise<string> { getKeyword(): Promise<string> {

@ -1,10 +1,11 @@
import { injectable } from 'tsyringe';
import TabPresenter from '../presenters/TabPresenter'; import TabPresenter from '../presenters/TabPresenter';
@injectable()
export default class LinkUseCase { export default class LinkUseCase {
private tabPresenter: TabPresenter; constructor(
private tabPresenter: TabPresenter,
constructor() { ) {
this.tabPresenter = new TabPresenter();
} }
openToTab(url: string, tabId: number): Promise<any> { openToTab(url: string, tabId: number): Promise<any> {

@ -1,22 +1,17 @@
import { injectable } from 'tsyringe';
import TabPresenter from '../presenters/TabPresenter'; import TabPresenter from '../presenters/TabPresenter';
import MarkRepository from '../repositories/MarkRepository'; import MarkRepository from '../repositories/MarkRepository';
import ConsoleClient from '../infrastructures/ConsoleClient'; import ConsoleClient from '../infrastructures/ConsoleClient';
import ContentMessageClient from '../infrastructures/ContentMessageClient'; import ContentMessageClient from '../infrastructures/ContentMessageClient';
@injectable()
export default class MarkUseCase { export default class MarkUseCase {
private tabPresenter: TabPresenter; constructor(
private tabPresenter: TabPresenter,
private markRepository: MarkRepository; private markRepository: MarkRepository,
private consoleClient: ConsoleClient,
private consoleClient: ConsoleClient; private contentMessageClient: ContentMessageClient,
) {
private contentMessageClient: ContentMessageClient;
constructor() {
this.tabPresenter = new TabPresenter();
this.markRepository = new MarkRepository();
this.consoleClient = new ConsoleClient();
this.contentMessageClient = new ContentMessageClient();
} }
async setGlobal(key: string, x: number, y: number): Promise<any> { async setGlobal(key: string, x: number, y: number): Promise<any> {

@ -1,17 +1,17 @@
// eslint-disable-next-line max-len import { injectable } from 'tsyringe';
import PersistentSettingRepository from '../repositories/PersistentSettingRepository'; import PersistentSettingRepository
from '../repositories/PersistentSettingRepository';
import SettingRepository from '../repositories/SettingRepository'; import SettingRepository from '../repositories/SettingRepository';
import { DefaultSettingData } from '../../shared/SettingData'; import { DefaultSettingData } from '../../shared/SettingData';
import Settings from '../../shared/Settings'; import Settings from '../../shared/Settings';
@injectable()
export default class SettingUseCase { export default class SettingUseCase {
private persistentSettingRepository: PersistentSettingRepository;
private settingRepository: SettingRepository; constructor(
private persistentSettingRepository: PersistentSettingRepository,
constructor() { private settingRepository: SettingRepository,
this.persistentSettingRepository = new PersistentSettingRepository(); ) {
this.settingRepository = new SettingRepository();
} }
get(): Promise<Settings> { get(): Promise<Settings> {

@ -1,10 +1,11 @@
import { injectable } from 'tsyringe';
import TabPresenter from '../presenters/TabPresenter'; import TabPresenter from '../presenters/TabPresenter';
@injectable()
export default class TabSelectUseCase { export default class TabSelectUseCase {
private tabPresenter: TabPresenter; constructor(
private tabPresenter: TabPresenter,
constructor() { ) {
this.tabPresenter = new TabPresenter();
} }
async selectPrev(count: number): Promise<any> { async selectPrev(count: number): Promise<any> {

@ -1,14 +1,13 @@
import { injectable } from 'tsyringe';
import TabPresenter from '../presenters/TabPresenter'; import TabPresenter from '../presenters/TabPresenter';
import BrowserSettingRepository from '../repositories/BrowserSettingRepository'; import BrowserSettingRepository from '../repositories/BrowserSettingRepository';
@injectable()
export default class TabUseCase { export default class TabUseCase {
private tabPresenter: TabPresenter; constructor(
private tabPresenter: TabPresenter,
private browserSettingRepository: BrowserSettingRepository; private browserSettingRepository: BrowserSettingRepository,
) {
constructor() {
this.tabPresenter = new TabPresenter();
this.browserSettingRepository = new BrowserSettingRepository();
} }
async close(force: boolean): Promise<any> { async close(force: boolean): Promise<any> {

@ -1,14 +1,13 @@
import { injectable } from 'tsyringe';
import TabPresenter from '../presenters/TabPresenter'; import TabPresenter from '../presenters/TabPresenter';
import NotifyPresenter from '../presenters/NotifyPresenter'; import NotifyPresenter from '../presenters/NotifyPresenter';
@injectable()
export default class VersionUseCase { export default class VersionUseCase {
private tabPresenter: TabPresenter; constructor(
private tabPresenter: TabPresenter,
private notifyPresenter: NotifyPresenter; private notifyPresenter: NotifyPresenter,
) {
constructor() {
this.tabPresenter = new TabPresenter();
this.notifyPresenter = new NotifyPresenter();
} }
notify(): Promise<void> { notify(): Promise<void> {

@ -1,3 +1,4 @@
import { injectable } from 'tsyringe';
import TabPresenter from '../presenters/TabPresenter'; import TabPresenter from '../presenters/TabPresenter';
const ZOOM_SETTINGS: number[] = [ const ZOOM_SETTINGS: number[] = [
@ -5,11 +6,11 @@ const ZOOM_SETTINGS: number[] = [
1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00 1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00
]; ];
@injectable()
export default class ZoomUseCase { export default class ZoomUseCase {
private tabPresenter: TabPresenter; constructor(
private tabPresenter: TabPresenter,
constructor() { ) {
this.tabPresenter = new TabPresenter();
} }
async zoomIn(): Promise<any> { async zoomIn(): Promise<any> {

@ -1,6 +1,8 @@
import chai from 'chai'; import 'reflect-metadata';
import { expect } from 'chai';
const browserFake = require('webextensions-api-fake'); const browserFake = require('webextensions-api-fake');
const browser = browserFake(); const browser = browserFake();
global.expect = chai.expect; global.expect = expect;
global.browser = browser; global.browser = browser;