diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-19 21:34:08 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-19 21:34:08 +0900 |
commit | cdfd54ed99087dc4a7a3fd13865849ff9ce9e8ba (patch) | |
tree | ca18790151d4e6cf003367f0dd87c27371d2b2c8 /src/background | |
parent | c7803e7c2911f63e43611290b996f526c0f8aaf2 (diff) |
Use TSyringe on background script
Diffstat (limited to 'src/background')
36 files changed, 208 insertions, 200 deletions
diff --git a/src/background/Application.ts b/src/background/Application.ts new file mode 100644 index 0000000..08013cd --- /dev/null +++ b/src/background/Application.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(); + } + }); + } +} diff --git a/src/background/controllers/AddonEnabledController.ts b/src/background/controllers/AddonEnabledController.ts index 251af25..903df40 100644 --- a/src/background/controllers/AddonEnabledController.ts +++ b/src/background/controllers/AddonEnabledController.ts @@ -1,10 +1,12 @@ +import { injectable } from 'tsyringe'; import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase'; +@injectable() export default class AddonEnabledController { - private addonEnabledUseCase: AddonEnabledUseCase; - constructor() { - this.addonEnabledUseCase = new AddonEnabledUseCase(); + constructor( + private addonEnabledUseCase: AddonEnabledUseCase, + ) { } indicate(enabled: boolean): Promise<any> { diff --git a/src/background/controllers/CommandController.ts b/src/background/controllers/CommandController.ts index f3a6b7f..2ad1683 100644 --- a/src/background/controllers/CommandController.ts +++ b/src/background/controllers/CommandController.ts @@ -1,3 +1,4 @@ +import { injectable } from 'tsyringe'; import CompletionsUseCase from '../usecases/CompletionsUseCase'; import CommandUseCase from '../usecases/CommandUseCase'; import CompletionGroup from '../domains/CompletionGroup'; @@ -7,14 +8,12 @@ const trimStart = (str: string): string => { return str.replace(/^\s+/, ''); }; +@injectable() export default class CommandController { - private completionsUseCase: CompletionsUseCase; - - private commandIndicator: CommandUseCase; - - constructor() { - this.completionsUseCase = new CompletionsUseCase(); - this.commandIndicator = new CommandUseCase(); + constructor( + private completionsUseCase: CompletionsUseCase, + private commandIndicator: CommandUseCase, + ) { } getCompletions(line: string): Promise<CompletionGroup[]> { diff --git a/src/background/controllers/FindController.ts b/src/background/controllers/FindController.ts index 28959e2..1cec962 100644 --- a/src/background/controllers/FindController.ts +++ b/src/background/controllers/FindController.ts @@ -1,10 +1,11 @@ +import { injectable } from 'tsyringe'; import FindUseCase from '../usecases/FindUseCase'; +@injectable() export default class FindController { - private findUseCase: FindUseCase; - - constructor() { - this.findUseCase = new FindUseCase(); + constructor( + private findUseCase: FindUseCase, + ) { } getKeyword(): Promise<string> { diff --git a/src/background/controllers/LinkController.ts b/src/background/controllers/LinkController.ts index 707b28a..af6148e 100644 --- a/src/background/controllers/LinkController.ts +++ b/src/background/controllers/LinkController.ts @@ -1,10 +1,11 @@ +import { injectable } from 'tsyringe'; import LinkUseCase from '../usecases/LinkUseCase'; +@injectable() export default class LinkController { - private linkUseCase: LinkUseCase; - - constructor() { - this.linkUseCase = new LinkUseCase(); + constructor( + private linkUseCase: LinkUseCase, + ) { } openToTab(url: string, tabId: number): Promise<void> { diff --git a/src/background/controllers/MarkController.ts b/src/background/controllers/MarkController.ts index 419a08b..4726fbc 100644 --- a/src/background/controllers/MarkController.ts +++ b/src/background/controllers/MarkController.ts @@ -1,10 +1,11 @@ +import { injectable } from 'tsyringe'; import MarkUseCase from '../usecases/MarkUseCase'; +@injectable() export default class MarkController { - private markUseCase: MarkUseCase; - - constructor() { - this.markUseCase = new MarkUseCase(); + constructor( + private markUseCase: MarkUseCase, + ) { } setGlobal(key: string, x: number, y: number): Promise<any> { diff --git a/src/background/controllers/OperationController.ts b/src/background/controllers/OperationController.ts index fa09512..de6f8cb 100644 --- a/src/background/controllers/OperationController.ts +++ b/src/background/controllers/OperationController.ts @@ -1,3 +1,4 @@ +import { injectable } from 'tsyringe'; import * as operations from '../../shared/operations'; import FindUseCase from '../usecases/FindUseCase'; import ConsoleUseCase from '../usecases/ConsoleUseCase'; @@ -5,23 +6,15 @@ import TabUseCase from '../usecases/TabUseCase'; import TabSelectUseCase from '../usecases/TabSelectUseCase'; import ZoomUseCase from '../usecases/ZoomUseCase'; +@injectable() export default class OperationController { - private findUseCase: FindUseCase; - - private consoleUseCase: ConsoleUseCase; - - private tabUseCase: TabUseCase; - - 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(); + constructor( + private findUseCase: FindUseCase, + private consoleUseCase: ConsoleUseCase, + private tabUseCase: TabUseCase, + private tabSelectUseCase: TabSelectUseCase, + private zoomUseCase: ZoomUseCase, + ) { } // eslint-disable-next-line complexity, max-lines-per-function diff --git a/src/background/controllers/SettingController.ts b/src/background/controllers/SettingController.ts index dfd2817..34951ff 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'; +@injectable() export default class SettingController { - private settingUseCase: SettingUseCase; - - private contentMessageClient: ContentMessageClient; - - constructor() { - this.settingUseCase = new SettingUseCase(); - this.contentMessageClient = new ContentMessageClient(); + constructor( + private settingUseCase: SettingUseCase, + private contentMessageClient: ContentMessageClient, + ) { } getSetting(): Promise<Settings> { diff --git a/src/background/controllers/VersionController.ts b/src/background/controllers/VersionController.ts index 2e2a197..b00185a 100644 --- a/src/background/controllers/VersionController.ts +++ b/src/background/controllers/VersionController.ts @@ -1,10 +1,11 @@ +import { injectable } from 'tsyringe'; import VersionUseCase from '../usecases/VersionUseCase'; +@injectable() export default class VersionController { - private versionUseCase: VersionUseCase; - - constructor() { - this.versionUseCase = new VersionUseCase(); + constructor( + private versionUseCase: VersionUseCase, + ) { } notify(): Promise<void> { diff --git a/src/background/index.ts b/src/background/index.ts index f9efd4d..26b0f6b 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -1,23 +1,6 @@ -import ContentMessageListener from './infrastructures/ContentMessageListener'; -import SettingController from './controllers/SettingController'; -import VersionController from './controllers/VersionController'; +import 'reflect-metadata'; +import { container } from 'tsyringe'; +import Application from './Application'; -let settingController = new SettingController(); -settingController.reload(); - -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(); - } -}); +let app = container.resolve(Application); +app.run(); diff --git a/src/background/infrastructures/ConsoleClient.ts b/src/background/infrastructures/ConsoleClient.ts index c162634..1385fe7 100644 --- a/src/background/infrastructures/ConsoleClient.ts +++ b/src/background/infrastructures/ConsoleClient.ts @@ -1,5 +1,7 @@ +import { injectable } from 'tsyringe'; import * as messages from '../../shared/messages'; +@injectable() export default class ConsoleClient { showCommand(tabId: number, command: string): Promise<any> { return browser.tabs.sendMessage(tabId, { diff --git a/src/background/infrastructures/ContentMessageClient.ts b/src/background/infrastructures/ContentMessageClient.ts index 2215330..2983409 100644 --- a/src/background/infrastructures/ContentMessageClient.ts +++ b/src/background/infrastructures/ContentMessageClient.ts @@ -1,5 +1,7 @@ +import { injectable } from 'tsyringe'; import * as messages from '../../shared/messages'; +@injectable() export default class ContentMessageClient { async broadcastSettingsChanged(): Promise<void> { let tabs = await browser.tabs.query({}); diff --git a/src/background/infrastructures/ContentMessageListener.ts b/src/background/infrastructures/ContentMessageListener.ts index 1cc2696..3d24741 100644 --- a/src/background/infrastructures/ContentMessageListener.ts +++ b/src/background/infrastructures/ContentMessageListener.ts @@ -1,3 +1,4 @@ +import { injectable } from 'tsyringe'; import * as messages from '../../shared/messages'; import CompletionGroup from '../domains/CompletionGroup'; import CommandController from '../controllers/CommandController'; @@ -8,32 +9,19 @@ import LinkController from '../controllers/LinkController'; import OperationController from '../controllers/OperationController'; import MarkController from '../controllers/MarkController'; +@injectable() 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}; - constructor() { - this.settingController = new SettingController(); - this.commandController = new CommandController(); - this.findController = new FindController(); - this.addonEnabledController = new AddonEnabledController(); - this.linkController = new LinkController(); - this.backgroundOperationController = new OperationController(); - this.markController = new MarkController(); - + constructor( + private settingController: SettingController, + private commandController: CommandController, + private findController: FindController, + private addonEnabledController: AddonEnabledController, + private linkController: LinkController, + private backgroundOperationController: OperationController, + private markController: MarkController, + ) { this.consolePorts = {}; } diff --git a/src/background/presenters/IndicatorPresenter.ts b/src/background/presenters/IndicatorPresenter.ts index 1c81cf5..99f92b5 100644 --- a/src/background/presenters/IndicatorPresenter.ts +++ b/src/background/presenters/IndicatorPresenter.ts @@ -1,3 +1,6 @@ +import { injectable } from 'tsyringe'; + +@injectable() export default class IndicatorPresenter { indicate(enabled: boolean): Promise<void> { let path = enabled diff --git a/src/background/presenters/NotifyPresenter.ts b/src/background/presenters/NotifyPresenter.ts index 23932f7..8fa4acb 100644 --- a/src/background/presenters/NotifyPresenter.ts +++ b/src/background/presenters/NotifyPresenter.ts @@ -1,5 +1,8 @@ +import { injectable } from 'tsyringe'; + const NOTIFICATION_ID = 'vimvixen-update'; +@injectable() export default class NotifyPresenter { async notify( title: string, diff --git a/src/background/presenters/TabPresenter.ts b/src/background/presenters/TabPresenter.ts index 33c6513..5665bf0 100644 --- a/src/background/presenters/TabPresenter.ts +++ b/src/background/presenters/TabPresenter.ts @@ -1,3 +1,4 @@ +import { injectable } from 'tsyringe'; import MemoryStorage from '../infrastructures/MemoryStorage'; const CURRENT_SELECTED_KEY = 'tabs.current.selected'; @@ -5,6 +6,7 @@ const LAST_SELECTED_KEY = 'tabs.last.selected'; type Tab = browser.tabs.Tab; +@injectable() export default class TabPresenter { open(url: string, tabId?: number): Promise<Tab> { return browser.tabs.update(tabId, { url }); diff --git a/src/background/presenters/WindowPresenter.ts b/src/background/presenters/WindowPresenter.ts index e04f258..150a48b 100644 --- a/src/background/presenters/WindowPresenter.ts +++ b/src/background/presenters/WindowPresenter.ts @@ -1,3 +1,6 @@ +import { injectable } from 'tsyringe'; + +@injectable() export default class WindowPresenter { create(url: string): Promise<browser.windows.Window> { return browser.windows.create({ url }); diff --git a/src/background/repositories/BookmarkRepository.ts b/src/background/repositories/BookmarkRepository.ts index b4da509..d266ae6 100644 --- a/src/background/repositories/BookmarkRepository.ts +++ b/src/background/repositories/BookmarkRepository.ts @@ -1,3 +1,6 @@ +import { injectable } from 'tsyringe'; + +@injectable() export default class BookmarkRepository { async create( title: string, url: string diff --git a/src/background/repositories/BrowserSettingRepository.ts b/src/background/repositories/BrowserSettingRepository.ts index 33b35dd..9cfb35e 100644 --- a/src/background/repositories/BrowserSettingRepository.ts +++ b/src/background/repositories/BrowserSettingRepository.ts @@ -1,3 +1,4 @@ +import { injectable } from 'tsyringe'; import * as urls from '../../shared/urls'; declare namespace browser.browserSettings.homepageOverride { @@ -16,6 +17,7 @@ declare namespace browser.browserSettings.homepageOverride { function get(param: object): Promise<BrowserSettings>; } +@injectable() export default class BrowserSettingRepository { async getHomepageUrls(): Promise<string[]> { let { value } = await browser.browserSettings.homepageOverride.get({}); diff --git a/src/background/repositories/CompletionsRepository.ts b/src/background/repositories/CompletionsRepository.ts index 18af587..dfdbc27 100644 --- a/src/background/repositories/CompletionsRepository.ts +++ b/src/background/repositories/CompletionsRepository.ts @@ -1,6 +1,9 @@ +import { injectable } from 'tsyringe'; + type Tab = browser.tabs.Tab; type BookmarkTreeNode = browser.bookmarks.BookmarkTreeNode; +@injectable() export default class CompletionsRepository { async queryBookmarks(keywords: string): Promise<BookmarkTreeNode[]> { let items = await browser.bookmarks.search({ query: keywords }); diff --git a/src/background/repositories/FindRepository.ts b/src/background/repositories/FindRepository.ts index bf286e6..6a087f5 100644 --- a/src/background/repositories/FindRepository.ts +++ b/src/background/repositories/FindRepository.ts @@ -1,7 +1,9 @@ +import { injectable } from 'tsyringe'; import MemoryStorage from '../infrastructures/MemoryStorage'; const FIND_KEYWORD_KEY = 'find-keyword'; +@injectable() export default class FindRepository { private cache: MemoryStorage; diff --git a/src/background/repositories/MarkRepository.ts b/src/background/repositories/MarkRepository.ts index 69c85f6..c106fff 100644 --- a/src/background/repositories/MarkRepository.ts +++ b/src/background/repositories/MarkRepository.ts @@ -1,8 +1,10 @@ +import { injectable } from 'tsyringe'; import MemoryStorage from '../infrastructures/MemoryStorage'; import GlobalMark from '../domains/GlobalMark'; const MARK_KEY = 'mark'; +@injectable() export default class MarkRepository { private cache: MemoryStorage; diff --git a/src/background/repositories/PersistentSettingRepository.ts b/src/background/repositories/PersistentSettingRepository.ts index ff882a5..927bce9 100644 --- a/src/background/repositories/PersistentSettingRepository.ts +++ b/src/background/repositories/PersistentSettingRepository.ts @@ -1,5 +1,7 @@ +import { injectable } from 'tsyringe'; import SettingData from '../../shared/SettingData'; +@injectable() export default class SettingRepository { async load(): Promise<SettingData | null> { let { settings } = await browser.storage.local.get('settings'); diff --git a/src/background/repositories/SettingRepository.ts b/src/background/repositories/SettingRepository.ts index eb83a2c..2f159e5 100644 --- a/src/background/repositories/SettingRepository.ts +++ b/src/background/repositories/SettingRepository.ts @@ -1,9 +1,11 @@ +import { injectable } from 'tsyringe'; import MemoryStorage from '../infrastructures/MemoryStorage'; import Settings from '../../shared/Settings'; import * as PropertyDefs from '../../shared/property-defs'; const CACHED_SETTING_KEY = 'setting'; +@injectable() export default class SettingRepository { private cache: MemoryStorage; diff --git a/src/background/usecases/AddonEnabledUseCase.ts b/src/background/usecases/AddonEnabledUseCase.ts index 0a6fb03..bb5cd90 100644 --- a/src/background/usecases/AddonEnabledUseCase.ts +++ b/src/background/usecases/AddonEnabledUseCase.ts @@ -1,27 +1,21 @@ +import { injectable } from 'tsyringe'; import IndicatorPresenter from '../presenters/IndicatorPresenter'; import TabPresenter from '../presenters/TabPresenter'; import ContentMessageClient from '../infrastructures/ContentMessageClient'; +@injectable() export default class AddonEnabledUseCase { - private indicatorPresentor: IndicatorPresenter; - - private tabPresenter: TabPresenter; - - private contentMessageClient: ContentMessageClient; - - constructor() { - this.indicatorPresentor = new IndicatorPresenter(); - + constructor( + private indicatorPresentor: IndicatorPresenter, + private tabPresenter: TabPresenter, + private contentMessageClient: ContentMessageClient, + ) { this.indicatorPresentor.onClick((tab) => { if (tab.id) { this.onIndicatorClick(tab.id); } }); - - this.tabPresenter = new TabPresenter(); this.tabPresenter.onSelected(info => this.onTabSelected(info.tabId)); - - this.contentMessageClient = new ContentMessageClient(); } indicate(enabled: boolean): Promise<void> { diff --git a/src/background/usecases/CommandUseCase.ts b/src/background/usecases/CommandUseCase.ts index 2247d7b..921a779 100644 --- a/src/background/usecases/CommandUseCase.ts +++ b/src/background/usecases/CommandUseCase.ts @@ -1,3 +1,4 @@ +import { injectable } from 'tsyringe'; import * as parsers from './parsers'; import * as urls from '../../shared/urls'; import TabPresenter from '../presenters/TabPresenter'; @@ -7,27 +8,16 @@ import BookmarkRepository from '../repositories/BookmarkRepository'; import ConsoleClient from '../infrastructures/ConsoleClient'; import ContentMessageClient from '../infrastructures/ContentMessageClient'; +@injectable() export default class CommandIndicator { - private tabPresenter: TabPresenter; - - private windowPresenter: WindowPresenter; - - private settingRepository: SettingRepository; - - private bookmarkRepository: BookmarkRepository; - - 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(); + constructor( + private tabPresenter: TabPresenter, + private windowPresenter: WindowPresenter, + private settingRepository: SettingRepository, + private bookmarkRepository: BookmarkRepository, + private consoleClient: ConsoleClient, + private contentMessageClient: ContentMessageClient, + ) { } async open(keywords: string): Promise<browser.tabs.Tab> { diff --git a/src/background/usecases/CompletionsUseCase.ts b/src/background/usecases/CompletionsUseCase.ts index da36e3c..705555b 100644 --- a/src/background/usecases/CompletionsUseCase.ts +++ b/src/background/usecases/CompletionsUseCase.ts @@ -1,3 +1,4 @@ +import { injectable } from 'tsyringe'; import CompletionGroup from '../domains/CompletionGroup'; import CommandDocs from '../domains/CommandDocs'; import CompletionsRepository from '../repositories/CompletionsRepository'; @@ -11,17 +12,13 @@ const COMPLETION_ITEM_LIMIT = 10; type Tab = browser.tabs.Tab; type HistoryItem = browser.history.HistoryItem; +@injectable() export default class CompletionsUseCase { - private tabPresenter: TabPresenter; - - private completionsRepository: CompletionsRepository; - - private settingRepository: SettingRepository; - - constructor() { - this.tabPresenter = new TabPresenter(); - this.completionsRepository = new CompletionsRepository(); - this.settingRepository = new SettingRepository(); + constructor( + private tabPresenter: TabPresenter, + private completionsRepository: CompletionsRepository, + private settingRepository: SettingRepository, + ) { } queryConsoleCommand(prefix: string): Promise<CompletionGroup[]> { diff --git a/src/background/usecases/ConsoleUseCase.ts b/src/background/usecases/ConsoleUseCase.ts index 60c0439..d0bd7bb 100644 --- a/src/background/usecases/ConsoleUseCase.ts +++ b/src/background/usecases/ConsoleUseCase.ts @@ -1,14 +1,14 @@ +import { injectable } from 'tsyringe'; import TabPresenter from '../presenters/TabPresenter'; import ConsoleClient from '../infrastructures/ConsoleClient'; +@injectable() export default class ConsoleUseCase { - private tabPresenter: TabPresenter; - private consoleClient: ConsoleClient; - - constructor() { - this.tabPresenter = new TabPresenter(); - this.consoleClient = new ConsoleClient(); + constructor( + private tabPresenter: TabPresenter, + private consoleClient: ConsoleClient, + ) { } async showCommand(): Promise<any> { diff --git a/src/background/usecases/FindUseCase.ts b/src/background/usecases/FindUseCase.ts index d567800..41b9cbd 100644 --- a/src/background/usecases/FindUseCase.ts +++ b/src/background/usecases/FindUseCase.ts @@ -1,18 +1,15 @@ +import { injectable } from 'tsyringe'; import FindRepository from '../repositories/FindRepository'; import TabPresenter from '../presenters/TabPresenter'; import ConsoleClient from '../infrastructures/ConsoleClient'; +@injectable() export default class FindUseCase { - private tabPresenter: TabPresenter; - - private findRepository: FindRepository; - - private consoleClient: ConsoleClient; - - constructor() { - this.tabPresenter = new TabPresenter(); - this.findRepository = new FindRepository(); - this.consoleClient = new ConsoleClient(); + constructor( + private tabPresenter: TabPresenter, + private findRepository: FindRepository, + private consoleClient: ConsoleClient, + ) { } getKeyword(): Promise<string> { diff --git a/src/background/usecases/LinkUseCase.ts b/src/background/usecases/LinkUseCase.ts index 480f6b5..e87867d 100644 --- a/src/background/usecases/LinkUseCase.ts +++ b/src/background/usecases/LinkUseCase.ts @@ -1,10 +1,11 @@ +import { injectable } from 'tsyringe'; import TabPresenter from '../presenters/TabPresenter'; +@injectable() export default class LinkUseCase { - private tabPresenter: TabPresenter; - - constructor() { - this.tabPresenter = new TabPresenter(); + constructor( + private tabPresenter: TabPresenter, + ) { } openToTab(url: string, tabId: number): Promise<any> { diff --git a/src/background/usecases/MarkUseCase.ts b/src/background/usecases/MarkUseCase.ts index e376c55..8cb96da 100644 --- a/src/background/usecases/MarkUseCase.ts +++ b/src/background/usecases/MarkUseCase.ts @@ -1,22 +1,17 @@ +import { 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 { - private tabPresenter: TabPresenter; - - private markRepository: MarkRepository; - - private consoleClient: ConsoleClient; - - private contentMessageClient: ContentMessageClient; - - constructor() { - this.tabPresenter = new TabPresenter(); - this.markRepository = new MarkRepository(); - this.consoleClient = new ConsoleClient(); - this.contentMessageClient = new ContentMessageClient(); + constructor( + private tabPresenter: TabPresenter, + private markRepository: MarkRepository, + private consoleClient: ConsoleClient, + private contentMessageClient: ContentMessageClient, + ) { } async setGlobal(key: string, x: number, y: number): Promise<any> { diff --git a/src/background/usecases/SettingUseCase.ts b/src/background/usecases/SettingUseCase.ts index aa3b534..fd00f80 100644 --- a/src/background/usecases/SettingUseCase.ts +++ b/src/background/usecases/SettingUseCase.ts @@ -1,17 +1,17 @@ -// eslint-disable-next-line max-len -import PersistentSettingRepository from '../repositories/PersistentSettingRepository'; +import { injectable } from 'tsyringe'; +import PersistentSettingRepository + from '../repositories/PersistentSettingRepository'; import SettingRepository from '../repositories/SettingRepository'; import { DefaultSettingData } from '../../shared/SettingData'; import Settings from '../../shared/Settings'; +@injectable() export default class SettingUseCase { - private persistentSettingRepository: PersistentSettingRepository; - private settingRepository: SettingRepository; - - constructor() { - this.persistentSettingRepository = new PersistentSettingRepository(); - this.settingRepository = new SettingRepository(); + constructor( + private persistentSettingRepository: PersistentSettingRepository, + private settingRepository: SettingRepository, + ) { } get(): Promise<Settings> { diff --git a/src/background/usecases/TabSelectUseCase.ts b/src/background/usecases/TabSelectUseCase.ts index a0b52f0..df3db94 100644 --- a/src/background/usecases/TabSelectUseCase.ts +++ b/src/background/usecases/TabSelectUseCase.ts @@ -1,10 +1,11 @@ +import { injectable } from 'tsyringe'; import TabPresenter from '../presenters/TabPresenter'; +@injectable() export default class TabSelectUseCase { - private tabPresenter: TabPresenter; - - constructor() { - this.tabPresenter = new TabPresenter(); + constructor( + private tabPresenter: TabPresenter, + ) { } async selectPrev(count: number): Promise<any> { diff --git a/src/background/usecases/TabUseCase.ts b/src/background/usecases/TabUseCase.ts index 1615333..0239a87 100644 --- a/src/background/usecases/TabUseCase.ts +++ b/src/background/usecases/TabUseCase.ts @@ -1,14 +1,13 @@ +import { injectable } from 'tsyringe'; import TabPresenter from '../presenters/TabPresenter'; import BrowserSettingRepository from '../repositories/BrowserSettingRepository'; +@injectable() export default class TabUseCase { - private tabPresenter: TabPresenter; - - private browserSettingRepository: BrowserSettingRepository; - - constructor() { - this.tabPresenter = new TabPresenter(); - this.browserSettingRepository = new BrowserSettingRepository(); + constructor( + private tabPresenter: TabPresenter, + private browserSettingRepository: BrowserSettingRepository, + ) { } async close(force: boolean): Promise<any> { diff --git a/src/background/usecases/VersionUseCase.ts b/src/background/usecases/VersionUseCase.ts index 8154eba..1d9ef8b 100644 --- a/src/background/usecases/VersionUseCase.ts +++ b/src/background/usecases/VersionUseCase.ts @@ -1,14 +1,13 @@ +import { injectable } from 'tsyringe'; import TabPresenter from '../presenters/TabPresenter'; import NotifyPresenter from '../presenters/NotifyPresenter'; +@injectable() export default class VersionUseCase { - private tabPresenter: TabPresenter; - - private notifyPresenter: NotifyPresenter; - - constructor() { - this.tabPresenter = new TabPresenter(); - this.notifyPresenter = new NotifyPresenter(); + constructor( + private tabPresenter: TabPresenter, + private notifyPresenter: NotifyPresenter, + ) { } notify(): Promise<void> { diff --git a/src/background/usecases/ZoomUseCase.ts b/src/background/usecases/ZoomUseCase.ts index 661c3cd..32ba897 100644 --- a/src/background/usecases/ZoomUseCase.ts +++ b/src/background/usecases/ZoomUseCase.ts @@ -1,3 +1,4 @@ +import { injectable } from 'tsyringe'; import TabPresenter from '../presenters/TabPresenter'; 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 ]; +@injectable() export default class ZoomUseCase { - private tabPresenter: TabPresenter; - - constructor() { - this.tabPresenter = new TabPresenter(); + constructor( + private tabPresenter: TabPresenter, + ) { } async zoomIn(): Promise<any> { |