Use TSyringe on content script

jh-changes
Shin'ya Ueoka 6 years ago
parent 71f3a1ea2d
commit 1666e626b0
  1. 111
      src/content/Application.ts
  2. 2
      src/content/MessageListener.ts
  3. 2
      src/content/client/BackgroundClient.ts
  4. 11
      src/content/controllers/AddonEnabledController.ts
  5. 11
      src/content/controllers/ConsoleFrameController.ts
  6. 11
      src/content/controllers/FindController.ts
  7. 11
      src/content/controllers/FollowKeyController.ts
  8. 11
      src/content/controllers/FollowMasterController.ts
  9. 11
      src/content/controllers/FollowSlaveController.ts
  10. 59
      src/content/controllers/KeymapController.ts
  11. 11
      src/content/controllers/MarkController.ts
  12. 16
      src/content/controllers/MarkKeyController.ts
  13. 15
      src/content/controllers/SettingController.ts
  14. 52
      src/content/di.ts
  15. 16
      src/content/index.ts
  16. 97
      src/content/routes.ts
  17. 22
      src/content/usecases/AddonEnabledUseCase.ts
  18. 37
      src/content/usecases/ClipboardUseCase.ts
  19. 15
      src/content/usecases/ConsoleFrameUseCase.ts
  20. 14
      src/content/usecases/FindSlaveUseCase.ts
  21. 35
      src/content/usecases/FindUseCase.ts
  22. 14
      src/content/usecases/FocusUseCase.ts
  23. 35
      src/content/usecases/FollowMasterUseCase.ts
  24. 38
      src/content/usecases/FollowSlaveUseCase.ts
  25. 33
      src/content/usecases/KeymapUseCase.ts
  26. 14
      src/content/usecases/MarkKeyUseCase.ts
  27. 46
      src/content/usecases/MarkUseCase.ts
  28. 15
      src/content/usecases/NavigateUseCase.ts
  29. 22
      src/content/usecases/ScrollUseCase.ts
  30. 21
      src/content/usecases/SettingUseCase.ts
  31. 2
      test/content/usecases/AddonEnabledUseCase.test.ts
  32. 8
      test/content/usecases/ClipboardUseCase.test.ts
  33. 2
      test/content/usecases/FindUseCase.test.ts
  34. 11
      test/content/usecases/MarkUseCase.test.ts
  35. 2
      test/content/usecases/SettingUseCaase.test.ts

@ -0,0 +1,111 @@
import { injectable } from 'tsyringe';
import MessageListener from './MessageListener';
import FindController from './controllers/FindController';
import MarkController from './controllers/MarkController';
import FollowMasterController from './controllers/FollowMasterController';
import FollowSlaveController from './controllers/FollowSlaveController';
import FollowKeyController from './controllers/FollowKeyController';
import InputDriver from './InputDriver';
import KeymapController from './controllers/KeymapController';
import AddonEnabledUseCase from './usecases/AddonEnabledUseCase';
import MarkKeyController from './controllers/MarkKeyController';
import AddonEnabledController from './controllers/AddonEnabledController';
import SettingController from './controllers/SettingController';
import ConsoleFrameController from './controllers/ConsoleFrameController';
import * as messages from '../shared/messages';
type Message = messages.Message;
@injectable()
export default class Application {
// eslint-disable-next-line max-params
constructor(
private messageListener: MessageListener,
private findController: FindController,
private markController: MarkController,
private followMasterController: FollowMasterController,
private followSlaveController: FollowSlaveController,
private followKeyController: FollowKeyController,
private keymapController: KeymapController,
private addonEnabledUseCase: AddonEnabledUseCase,
private markKeyController: MarkKeyController,
private addonEnabledController: AddonEnabledController,
private settingController: SettingController,
private consoleFrameController: ConsoleFrameController,
) {
}
run() {
this.routeCommonComponents();
if (window.self === window.top) {
this.routeMasterComponents();
}
}
private routeMasterComponents() {
this.messageListener.onWebMessage((msg: Message, sender: Window) => {
switch (msg.type) {
case messages.CONSOLE_ENTER_FIND:
return this.findController.start(msg);
case messages.FIND_NEXT:
return this.findController.next(msg);
case messages.FIND_PREV:
return this.findController.prev(msg);
case messages.CONSOLE_UNFOCUS:
return this.consoleFrameController.unfocus(msg);
case messages.FOLLOW_START:
return this.followMasterController.followStart(msg);
case messages.FOLLOW_RESPONSE_COUNT_TARGETS:
return this.followMasterController.responseCountTargets(msg, sender);
case messages.FOLLOW_KEY_PRESS:
return this.followMasterController.keyPress(msg);
}
return undefined;
});
this.messageListener.onBackgroundMessage((msg: Message) => {
switch (msg.type) {
case messages.ADDON_ENABLED_QUERY:
return this.addonEnabledController.getAddonEnabled(msg);
case messages.TAB_SCROLL_TO:
return this.markController.scrollTo(msg);
}
return undefined;
});
}
private routeCommonComponents() {
this.messageListener.onWebMessage((msg: Message) => {
switch (msg.type) {
case messages.FOLLOW_REQUEST_COUNT_TARGETS:
return this.followSlaveController.countTargets(msg);
case messages.FOLLOW_CREATE_HINTS:
return this.followSlaveController.createHints(msg);
case messages.FOLLOW_SHOW_HINTS:
return this.followSlaveController.showHints(msg);
case messages.FOLLOW_ACTIVATE:
return this.followSlaveController.activate(msg);
case messages.FOLLOW_REMOVE_HINTS:
return this.followSlaveController.clear(msg);
}
return undefined;
});
this.messageListener.onBackgroundMessage((msg: Message): any => {
switch (msg.type) {
case messages.SETTINGS_CHANGED:
return this.settingController.reloadSettings(msg);
case messages.ADDON_TOGGLE_ENABLED:
return this.addonEnabledUseCase.toggle();
}
});
let inputDriver = new InputDriver(window.document.body);
inputDriver.onKey(key => this.followKeyController.press(key));
inputDriver.onKey(key => this.markKeyController.press(key));
inputDriver.onKey(key => this.keymapController.press(key));
this.settingController.initSettings();
}
}

@ -1,7 +1,9 @@
import { injectable } from 'tsyringe';
import { Message, valueOf } from '../shared/messages'; import { Message, valueOf } from '../shared/messages';
export type WebExtMessageSender = browser.runtime.MessageSender; export type WebExtMessageSender = browser.runtime.MessageSender;
@injectable()
export default class MessageListener { export default class MessageListener {
onWebMessage( onWebMessage(
listener: (msg: Message, sender: Window) => void, listener: (msg: Message, sender: Window) => void,

@ -1,6 +1,8 @@
import { injectable } from 'tsyringe';
import * as operations from '../../shared/operations'; import * as operations from '../../shared/operations';
import * as messages from '../../shared/messages'; import * as messages from '../../shared/messages';
@injectable()
export default class BackgroundClient { export default class BackgroundClient {
execBackgroundOp(op: operations.Operation): Promise<void> { execBackgroundOp(op: operations.Operation): Promise<void> {
return browser.runtime.sendMessage({ return browser.runtime.sendMessage({

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import * as messages from '../../shared/messages'; import * as messages from '../../shared/messages';
import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase'; import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase';
@injectable()
export default class AddonEnabledController { export default class AddonEnabledController {
private addonEnabledUseCase: AddonEnabledUseCase; constructor(
private addonEnabledUseCase: AddonEnabledUseCase,
constructor({ ) {
addonEnabledUseCase = new AddonEnabledUseCase(),
} = {}) {
this.addonEnabledUseCase = addonEnabledUseCase;
} }
getAddonEnabled( getAddonEnabled(

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import ConsoleFrameUseCase from '../usecases/ConsoleFrameUseCase'; import ConsoleFrameUseCase from '../usecases/ConsoleFrameUseCase';
import * as messages from '../../shared/messages'; import * as messages from '../../shared/messages';
@injectable()
export default class ConsoleFrameController { export default class ConsoleFrameController {
private consoleFrameUseCase: ConsoleFrameUseCase; constructor(
private consoleFrameUseCase: ConsoleFrameUseCase,
constructor({ ) {
consoleFrameUseCase = new ConsoleFrameUseCase(),
} = {}) {
this.consoleFrameUseCase = consoleFrameUseCase;
} }
unfocus(_message: messages.Message) { unfocus(_message: messages.Message) {

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import * as messages from '../../shared/messages'; import * as messages from '../../shared/messages';
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({ ) {
findUseCase = new FindUseCase(),
} = {}) {
this.findUseCase = findUseCase;
} }
async start(m: messages.ConsoleEnterFindMessage): Promise<void> { async start(m: messages.ConsoleEnterFindMessage): Promise<void> {

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import FollowSlaveUseCase from '../usecases/FollowSlaveUseCase'; import FollowSlaveUseCase from '../usecases/FollowSlaveUseCase';
import Key from '../domains/Key'; import Key from '../domains/Key';
@injectable()
export default class FollowKeyController { export default class FollowKeyController {
private followSlaveUseCase: FollowSlaveUseCase; constructor(
private followSlaveUseCase: FollowSlaveUseCase,
constructor({ ) {
followSlaveUseCase = new FollowSlaveUseCase(),
} = {}) {
this.followSlaveUseCase = followSlaveUseCase;
} }
press(key: Key): boolean { press(key: Key): boolean {

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import FollowMasterUseCase from '../usecases/FollowMasterUseCase'; import FollowMasterUseCase from '../usecases/FollowMasterUseCase';
import * as messages from '../../shared/messages'; import * as messages from '../../shared/messages';
@injectable()
export default class FollowMasterController { export default class FollowMasterController {
private followMasterUseCase: FollowMasterUseCase; constructor(
private followMasterUseCase: FollowMasterUseCase,
constructor({ ) {
followMasterUseCase = new FollowMasterUseCase(),
} = {}) {
this.followMasterUseCase = followMasterUseCase;
} }
followStart(m: messages.FollowStartMessage): void { followStart(m: messages.FollowStartMessage): void {

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import * as messages from '../../shared/messages'; import * as messages from '../../shared/messages';
import FollowSlaveUseCase from '../usecases/FollowSlaveUseCase'; import FollowSlaveUseCase from '../usecases/FollowSlaveUseCase';
@injectable()
export default class FollowSlaveController { export default class FollowSlaveController {
private usecase: FollowSlaveUseCase; constructor(
private usecase: FollowSlaveUseCase,
constructor({ ) {
usecase = new FollowSlaveUseCase(),
} = {}) {
this.usecase = usecase;
} }
countTargets(m: messages.FollowRequestCountTargetsMessage): void { countTargets(m: messages.FollowRequestCountTargetsMessage): void {

@ -1,3 +1,4 @@
import { injectable, inject } from 'tsyringe';
import * as operations from '../../shared/operations'; import * as operations from '../../shared/operations';
import KeymapUseCase from '../usecases/KeymapUseCase'; import KeymapUseCase from '../usecases/KeymapUseCase';
import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase'; import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase';
@ -8,53 +9,25 @@ import FocusUseCase from '../usecases/FocusUseCase';
import ClipboardUseCase from '../usecases/ClipboardUseCase'; import ClipboardUseCase from '../usecases/ClipboardUseCase';
import BackgroundClient from '../client/BackgroundClient'; import BackgroundClient from '../client/BackgroundClient';
import MarkKeyyUseCase from '../usecases/MarkKeyUseCase'; import MarkKeyyUseCase from '../usecases/MarkKeyUseCase';
import FollowMasterClient, { FollowMasterClientImpl } import FollowMasterClient from '../client/FollowMasterClient';
from '../client/FollowMasterClient';
import Key from '../domains/Key'; import Key from '../domains/Key';
@injectable()
export default class KeymapController { export default class KeymapController {
private keymapUseCase: KeymapUseCase; constructor(
private keymapUseCase: KeymapUseCase,
private addonEnabledUseCase: AddonEnabledUseCase,
private findSlaveUseCase: FindSlaveUseCase,
private scrollUseCase: ScrollUseCase,
private navigateUseCase: NavigateUseCase,
private focusUseCase: FocusUseCase,
private clipbaordUseCase: ClipboardUseCase,
private backgroundClient: BackgroundClient,
private markKeyUseCase: MarkKeyyUseCase,
private addonEnabledUseCase: AddonEnabledUseCase; @inject('FollowMasterClient')
private followMasterClient: FollowMasterClient,
private findSlaveUseCase: FindSlaveUseCase; ) {
private scrollUseCase: ScrollUseCase;
private navigateUseCase: NavigateUseCase;
private focusUseCase: FocusUseCase;
private clipbaordUseCase: ClipboardUseCase;
private backgroundClient: BackgroundClient;
private markKeyUseCase: MarkKeyyUseCase;
private followMasterClient: FollowMasterClient;
constructor({
keymapUseCase = new KeymapUseCase(),
addonEnabledUseCase = new AddonEnabledUseCase(),
findSlaveUseCase = new FindSlaveUseCase(),
scrollUseCase = new ScrollUseCase(),
navigateUseCase = new NavigateUseCase(),
focusUseCase = new FocusUseCase(),
clipbaordUseCase = new ClipboardUseCase(),
backgroundClient = new BackgroundClient(),
markKeyUseCase = new MarkKeyyUseCase(),
followMasterClient = new FollowMasterClientImpl(window.top),
} = {}) {
this.keymapUseCase = keymapUseCase;
this.addonEnabledUseCase = addonEnabledUseCase;
this.findSlaveUseCase = findSlaveUseCase;
this.scrollUseCase = scrollUseCase;
this.navigateUseCase = navigateUseCase;
this.focusUseCase = focusUseCase;
this.clipbaordUseCase = clipbaordUseCase;
this.backgroundClient = backgroundClient;
this.markKeyUseCase = markKeyUseCase;
this.followMasterClient = followMasterClient;
} }
// eslint-disable-next-line complexity, max-lines-per-function // eslint-disable-next-line complexity, max-lines-per-function

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import * as messages from '../../shared/messages'; import * as messages from '../../shared/messages';
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({ ) {
markUseCase = new MarkUseCase(),
} = {}) {
this.markUseCase = markUseCase;
} }
scrollTo(message: messages.TabScrollToMessage) { scrollTo(message: messages.TabScrollToMessage) {

@ -1,18 +1,14 @@
import { injectable } from 'tsyringe';
import MarkUseCase from '../usecases/MarkUseCase'; import MarkUseCase from '../usecases/MarkUseCase';
import MarkKeyyUseCase from '../usecases/MarkKeyUseCase'; import MarkKeyyUseCase from '../usecases/MarkKeyUseCase';
import Key from '../domains/Key'; import Key from '../domains/Key';
@injectable()
export default class MarkKeyController { export default class MarkKeyController {
private markUseCase: MarkUseCase; constructor(
private markUseCase: MarkUseCase,
private markKeyUseCase: MarkKeyyUseCase; private markKeyUseCase: MarkKeyyUseCase,
) {
constructor({
markUseCase = new MarkUseCase(),
markKeyUseCase = new MarkKeyyUseCase(),
} = {}) {
this.markUseCase = markUseCase;
this.markKeyUseCase = markKeyUseCase;
} }
press(key: Key): boolean { press(key: Key): boolean {

@ -1,20 +1,17 @@
import { injectable } from 'tsyringe';
import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase'; import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase';
import SettingUseCase from '../usecases/SettingUseCase'; import SettingUseCase from '../usecases/SettingUseCase';
import * as blacklists from '../../shared/blacklists'; import * as blacklists from '../../shared/blacklists';
import * as messages from '../../shared/messages'; import * as messages from '../../shared/messages';
@injectable()
export default class SettingController { export default class SettingController {
private addonEnabledUseCase: AddonEnabledUseCase;
private settingUseCase: SettingUseCase; constructor(
private addonEnabledUseCase: AddonEnabledUseCase,
constructor({ private settingUseCase: SettingUseCase,
addonEnabledUseCase = new AddonEnabledUseCase(), ) {
settingUseCase = new SettingUseCase(),
} = {}) {
this.addonEnabledUseCase = addonEnabledUseCase;
this.settingUseCase = settingUseCase;
} }
async initSettings(): Promise<void> { async initSettings(): Promise<void> {

@ -0,0 +1,52 @@
/* eslint-disable max-len */
import { FollowMasterClientImpl } from './client/FollowMasterClient';
import { AddonIndicatorClientImpl } from './client/AddonIndicatorClient';
import { AddonEnabledRepositoryImpl } from './repositories/AddonEnabledRepository';
import { ClipboardRepositoryImpl } from './repositories/ClipboardRepository';
import { SettingRepositoryImpl } from './repositories/SettingRepository';
import { TabsClientImpl } from './client/TabsClient';
import { ConsoleClientImpl } from './client/ConsoleClient';
import { ConsoleFramePresenterImpl } from './presenters/ConsoleFramePresenter';
import { FindMasterClientImpl } from './client/FindMasterClient';
import { FindPresenterImpl } from './presenters/FindPresenter';
import { FindRepositoryImpl } from './repositories/FindRepository';
import { FindClientImpl } from './client/FindClient';
import { FocusPresenterImpl } from './presenters/FocusPresenter';
import { FollowKeyRepositoryImpl } from './repositories/FollowKeyRepository';
import { FollowMasterRepositoryImpl } from './repositories/FollowMasterRepository';
import { FollowSlaveRepositoryImpl } from './repositories/FollowSlaveRepository';
import { FollowPresenterImpl } from './presenters/FollowPresenter';
import { KeymapRepositoryImpl } from './repositories/KeymapRepository';
import { MarkKeyRepositoryImpl } from './repositories/MarkKeyRepository';
import { ScrollPresenterImpl } from './presenters/ScrollPresenter';
import { MarkClientImpl } from './client/MarkClient';
import { MarkRepositoryImpl } from './repositories/MarkRepository';
import { NavigationPresenterImpl } from './presenters/NavigationPresenter';
import { SettingClientImpl } from './client/SettingClient';
import { container } from 'tsyringe';
container.register('FollowMasterClient', { useValue: new FollowMasterClientImpl(window.top) });
container.register('AddonIndicatorClient', { useClass: AddonIndicatorClientImpl });
container.register('AddonEnabledRepository', { useClass: AddonEnabledRepositoryImpl });
container.register('ClipboardRepository', { useClass: ClipboardRepositoryImpl });
container.register('SettingRepository', { useClass: SettingRepositoryImpl });
container.register('TabsClient', { useClass: TabsClientImpl });
container.register('ConsoleClient', { useClass: ConsoleClientImpl });
container.register('ConsoleFramePresenter', { useClass: ConsoleFramePresenterImpl });
container.register('FindMasterClient', { useClass: FindMasterClientImpl });
container.register('FindPresenter', { useClass: FindPresenterImpl });
container.register('FindRepository', { useClass: FindRepositoryImpl });
container.register('FindClient', { useClass: FindClientImpl });
container.register('FocusPresenter', { useClass: FocusPresenterImpl });
container.register('FollowKeyRepository', { useClass: FollowKeyRepositoryImpl });
container.register('FollowMasterRepository', { useClass: FollowMasterRepositoryImpl });
container.register('FollowSlaveRepository', { useClass: FollowSlaveRepositoryImpl });
container.register('FollowPresenter', { useClass: FollowPresenterImpl });
container.register('KeymapRepository', { useClass: KeymapRepositoryImpl });
container.register('MarkKeyRepository', { useClass: MarkKeyRepositoryImpl });
container.register('ScrollPresenter', { useClass: ScrollPresenterImpl });
container.register('MarkClient', { useClass: MarkClientImpl });
container.register('MarkRepository', { useClass: MarkRepositoryImpl });
container.register('NavigationPresenter', { useClass: NavigationPresenterImpl });
container.register('SettingClient', { useClass: SettingClientImpl });

@ -1,15 +1,19 @@
import { ConsoleFramePresenterImpl } from './presenters/ConsoleFramePresenter'; import 'reflect-metadata';
import Application from './Application';
import consoleFrameStyle from './site-style'; import consoleFrameStyle from './site-style';
import * as routes from './routes'; import { ConsoleFramePresenterImpl } from './presenters/ConsoleFramePresenter';
import { container } from 'tsyringe';
import './di';
if (window.self === window.top) { if (window.self === window.top) {
routes.routeMasterComponents();
new ConsoleFramePresenterImpl().initialize(); new ConsoleFramePresenterImpl().initialize();
} }
routes.routeComponents(); try {
let app = container.resolve(Application);
app.run();
} catch (e) { console.error(e); }
let style = window.document.createElement('style'); let style = window.document.createElement('style');
style.textContent = consoleFrameStyle; style.textContent = consoleFrameStyle;

@ -1,97 +0,0 @@
import MessageListener from './MessageListener';
import FindController from './controllers/FindController';
import MarkController from './controllers/MarkController';
import FollowMasterController from './controllers/FollowMasterController';
import FollowSlaveController from './controllers/FollowSlaveController';
import FollowKeyController from './controllers/FollowKeyController';
import InputDriver from './InputDriver';
import KeymapController from './controllers/KeymapController';
import AddonEnabledUseCase from './usecases/AddonEnabledUseCase';
import MarkKeyController from './controllers/MarkKeyController';
import AddonEnabledController from './controllers/AddonEnabledController';
import SettingController from './controllers/SettingController';
import ConsoleFrameController from './controllers/ConsoleFrameController';
import * as messages from '../shared/messages';
export const routeComponents = () => {
let listener = new MessageListener();
let followSlaveController = new FollowSlaveController();
listener.onWebMessage((message: messages.Message) => {
switch (message.type) {
case messages.FOLLOW_REQUEST_COUNT_TARGETS:
return followSlaveController.countTargets(message);
case messages.FOLLOW_CREATE_HINTS:
return followSlaveController.createHints(message);
case messages.FOLLOW_SHOW_HINTS:
return followSlaveController.showHints(message);
case messages.FOLLOW_ACTIVATE:
return followSlaveController.activate(message);
case messages.FOLLOW_REMOVE_HINTS:
return followSlaveController.clear(message);
}
return undefined;
});
let keymapController = new KeymapController();
let markKeyController = new MarkKeyController();
let followKeyController = new FollowKeyController();
let inputDriver = new InputDriver(document.body);
inputDriver.onKey(key => followKeyController.press(key));
inputDriver.onKey(key => markKeyController.press(key));
inputDriver.onKey(key => keymapController.press(key));
let settingController = new SettingController();
settingController.initSettings();
listener.onBackgroundMessage((message: messages.Message): any => {
let addonEnabledUseCase = new AddonEnabledUseCase();
switch (message.type) {
case messages.SETTINGS_CHANGED:
return settingController.reloadSettings(message);
case messages.ADDON_TOGGLE_ENABLED:
return addonEnabledUseCase.toggle();
}
});
};
export const routeMasterComponents = () => {
let listener = new MessageListener();
let findController = new FindController();
let followMasterController = new FollowMasterController();
let markController = new MarkController();
let addonEnabledController = new AddonEnabledController();
let consoleFrameController = new ConsoleFrameController();
listener.onWebMessage((message: messages.Message, sender: Window) => {
switch (message.type) {
case messages.CONSOLE_ENTER_FIND:
return findController.start(message);
case messages.FIND_NEXT:
return findController.next(message);
case messages.FIND_PREV:
return findController.prev(message);
case messages.CONSOLE_UNFOCUS:
return consoleFrameController.unfocus(message);
case messages.FOLLOW_START:
return followMasterController.followStart(message);
case messages.FOLLOW_RESPONSE_COUNT_TARGETS:
return followMasterController.responseCountTargets(message, sender);
case messages.FOLLOW_KEY_PRESS:
return followMasterController.keyPress(message);
}
return undefined;
});
listener.onBackgroundMessage((message: messages.Message) => {
switch (message.type) {
case messages.ADDON_ENABLED_QUERY:
return addonEnabledController.getAddonEnabled(message);
case messages.TAB_SCROLL_TO:
return markController.scrollTo(message);
}
return undefined;
});
};

@ -1,19 +1,17 @@
import AddonIndicatorClient, { AddonIndicatorClientImpl } import { injectable, inject } from 'tsyringe';
from '../client/AddonIndicatorClient'; import AddonIndicatorClient from '../client/AddonIndicatorClient';
import AddonEnabledRepository, { AddonEnabledRepositoryImpl } import AddonEnabledRepository from '../repositories/AddonEnabledRepository';
from '../repositories/AddonEnabledRepository';
@injectable()
export default class AddonEnabledUseCase { export default class AddonEnabledUseCase {
private indicator: AddonIndicatorClient;
private repository: AddonEnabledRepository; constructor(
@inject('AddonIndicatorClient')
private indicator: AddonIndicatorClient,
constructor({ @inject('AddonEnabledRepository')
indicator = new AddonIndicatorClientImpl(), private repository: AddonEnabledRepository,
repository = new AddonEnabledRepositoryImpl(), ) {
} = {}) {
this.indicator = indicator;
this.repository = repository;
} }
async enable(): Promise<void> { async enable(): Promise<void> {

@ -1,31 +1,18 @@
import { injectable, inject } from 'tsyringe';
import * as urls from '../../shared/urls'; import * as urls from '../../shared/urls';
import ClipboardRepository, { ClipboardRepositoryImpl } import ClipboardRepository from '../repositories/ClipboardRepository';
from '../repositories/ClipboardRepository'; import SettingRepository from '../repositories/SettingRepository';
import SettingRepository, { SettingRepositoryImpl } import TabsClient from '../client/TabsClient';
from '../repositories/SettingRepository'; import ConsoleClient from '../client/ConsoleClient';
import TabsClient, { TabsClientImpl }
from '../client/TabsClient';
import ConsoleClient, { ConsoleClientImpl } from '../client/ConsoleClient';
@injectable()
export default class ClipboardUseCase { export default class ClipboardUseCase {
private repository: ClipboardRepository; constructor(
@inject('ClipboardRepository') private repository: ClipboardRepository,
private settingRepository: SettingRepository; @inject('SettingRepository') private settingRepository: SettingRepository,
@inject('TabsClient') private client: TabsClient,
private client: TabsClient; @inject('ConsoleClient') private consoleClient: ConsoleClient,
) {
private consoleClient: ConsoleClient;
constructor({
repository = new ClipboardRepositoryImpl(),
settingRepository = new SettingRepositoryImpl(),
client = new TabsClientImpl(),
consoleClient = new ConsoleClientImpl(),
} = {}) {
this.repository = repository;
this.settingRepository = settingRepository;
this.client = client;
this.consoleClient = consoleClient;
} }
async yankCurrentURL(): Promise<string> { async yankCurrentURL(): Promise<string> {

@ -1,13 +1,12 @@
import ConsoleFramePresenter, { ConsoleFramePresenterImpl } import { injectable, inject } from 'tsyringe';
from '../presenters/ConsoleFramePresenter'; import ConsoleFramePresenter from '../presenters/ConsoleFramePresenter';
@injectable()
export default class ConsoleFrameUseCase { export default class ConsoleFrameUseCase {
private consoleFramePresenter: ConsoleFramePresenter; constructor(
@inject('ConsoleFramePresenter')
constructor({ private consoleFramePresenter: ConsoleFramePresenter,
consoleFramePresenter = new ConsoleFramePresenterImpl(), ) {
} = {}) {
this.consoleFramePresenter = consoleFramePresenter;
} }
unfocus() { unfocus() {

@ -1,13 +1,11 @@
import FindMasterClient, { FindMasterClientImpl } import { injectable, inject } from 'tsyringe';
from '../client/FindMasterClient'; import FindMasterClient from '../client/FindMasterClient';
@injectable()
export default class FindSlaveUseCase { export default class FindSlaveUseCase {
private findMasterClient: FindMasterClient; constructor(
@inject('FindMasterClient') private findMasterClient: FindMasterClient,
constructor({ ) {
findMasterClient = new FindMasterClientImpl(),
} = {}) {
this.findMasterClient = findMasterClient;
} }
findNext() { findNext() {

@ -1,28 +1,17 @@
import FindPresenter, { FindPresenterImpl } from '../presenters/FindPresenter'; import { injectable, inject } from 'tsyringe';
import FindRepository, { FindRepositoryImpl } import FindPresenter from '../presenters/FindPresenter';
from '../repositories/FindRepository'; import FindRepository from '../repositories/FindRepository';
import FindClient, { FindClientImpl } from '../client/FindClient'; import FindClient from '../client/FindClient';
import ConsoleClient, { ConsoleClientImpl } from '../client/ConsoleClient'; import ConsoleClient from '../client/ConsoleClient';
@injectable()
export default class FindUseCase { export default class FindUseCase {
private presenter: FindPresenter; constructor(
@inject('FindPresenter') private presenter: FindPresenter,
private repository: FindRepository; @inject('FindRepository') private repository: FindRepository,
@inject('FindClient') private client: FindClient,
private client: FindClient; @inject('ConsoleClient') private consoleClient: ConsoleClient,
) {
private consoleClient: ConsoleClient;
constructor({
presenter = new FindPresenterImpl() as FindPresenter,
repository = new FindRepositoryImpl(),
client = new FindClientImpl(),
consoleClient = new ConsoleClientImpl(),
} = {}) {
this.presenter = presenter;
this.repository = repository;
this.client = client;
this.consoleClient = consoleClient;
} }
async startFind(keyword?: string): Promise<void> { async startFind(keyword?: string): Promise<void> {

@ -1,13 +1,11 @@
import FocusPresenter, { FocusPresenterImpl } import { injectable, inject } from 'tsyringe';
from '../presenters/FocusPresenter'; import FocusPresenter from '../presenters/FocusPresenter';
@injectable()
export default class FocusUseCases { export default class FocusUseCases {
private presenter: FocusPresenter; constructor(
@inject('FocusPresenter') private presenter: FocusPresenter,
constructor({ ) {
presenter = new FocusPresenterImpl(),
} = {}) {
this.presenter = presenter;
} }
focusFirstInput() { focusFirstInput() {

@ -1,31 +1,26 @@
import FollowKeyRepository, { FollowKeyRepositoryImpl } import { injectable, inject } from 'tsyringe';
from '../repositories/FollowKeyRepository'; import FollowKeyRepository from '../repositories/FollowKeyRepository';
import FollowMasterRepository, { FollowMasterRepositoryImpl } import FollowMasterRepository from '../repositories/FollowMasterRepository';
from '../repositories/FollowMasterRepository';
import FollowSlaveClient, { FollowSlaveClientImpl } import FollowSlaveClient, { FollowSlaveClientImpl }
from '../client/FollowSlaveClient'; from '../client/FollowSlaveClient';
import SettingRepository from '../repositories/SettingRepository';
import HintKeyProducer from './HintKeyProducer'; import HintKeyProducer from './HintKeyProducer';
import SettingRepository, { SettingRepositoryImpl }
from '../repositories/SettingRepository';
@injectable()
export default class FollowMasterUseCase { export default class FollowMasterUseCase {
private followKeyRepository: FollowKeyRepository;
private followMasterRepository: FollowMasterRepository;
private settingRepository: SettingRepository;
// TODO Make repository // TODO Make repository
private producer: HintKeyProducer | null; private producer: HintKeyProducer | null;
constructor({ constructor(
followKeyRepository = new FollowKeyRepositoryImpl(), @inject('FollowKeyRepository')
followMasterRepository = new FollowMasterRepositoryImpl(), private followKeyRepository: FollowKeyRepository,
settingRepository = new SettingRepositoryImpl(),
} = {}) { @inject('FollowMasterRepository')
this.followKeyRepository = followKeyRepository; private followMasterRepository: FollowMasterRepository,
this.followMasterRepository = followMasterRepository;
this.settingRepository = settingRepository; @inject('SettingRepository')
private settingRepository: SettingRepository,
) {
this.producer = null; this.producer = null;
} }

@ -1,11 +1,9 @@
import FollowSlaveRepository, { FollowSlaveRepositoryImpl } import { injectable, inject } from 'tsyringe';
from '../repositories/FollowSlaveRepository'; import FollowSlaveRepository from '../repositories/FollowSlaveRepository';
import FollowPresenter, { FollowPresenterImpl } import FollowPresenter from '../presenters/FollowPresenter';
from '../presenters/FollowPresenter'; import TabsClient from '../client/TabsClient';
import TabsClient, { TabsClientImpl } from '../client/TabsClient'; import FollowMasterClient from '../client/FollowMasterClient';
import { LinkHint, InputHint } from '../presenters/Hint'; import { LinkHint, InputHint } from '../presenters/Hint';
import FollowMasterClient, { FollowMasterClientImpl }
from '../client/FollowMasterClient';
import Key from '../domains/Key'; import Key from '../domains/Key';
interface Size { interface Size {
@ -18,25 +16,21 @@ interface Point {
y: number; y: number;
} }
@injectable()
export default class FollowSlaveUseCase { export default class FollowSlaveUseCase {
private presenter: FollowPresenter; constructor(
@inject('FollowPresenter')
private presenter: FollowPresenter,
private tabsClient: TabsClient; @inject('TabsClient')
private tabsClient: TabsClient,
private followMasterClient: FollowMasterClient; @inject('FollowMasterClient')
private followMasterClient: FollowMasterClient,
private followSlaveRepository: FollowSlaveRepository; @inject('FollowSlaveRepository')
private followSlaveRepository: FollowSlaveRepository,
constructor({ ) {
presenter = new FollowPresenterImpl(),
tabsClient = new TabsClientImpl(),
followMasterClient = new FollowMasterClientImpl(window.top),
followSlaveRepository = new FollowSlaveRepositoryImpl(),
} = {}) {
this.presenter = presenter;
this.tabsClient = tabsClient;
this.followMasterClient = followMasterClient;
this.followSlaveRepository = followSlaveRepository;
} }
countTargets(viewSize: Size, framePosition: Point): void { countTargets(viewSize: Size, framePosition: Point): void {

@ -1,10 +1,7 @@
import KeymapRepository, { KeymapRepositoryImpl } import { injectable, inject } from 'tsyringe';
from '../repositories/KeymapRepository'; import KeymapRepository from '../repositories/KeymapRepository';
import SettingRepository, { SettingRepositoryImpl } import SettingRepository from '../repositories/SettingRepository';
from '../repositories/SettingRepository'; import AddonEnabledRepository from '../repositories/AddonEnabledRepository';
import AddonEnabledRepository, { AddonEnabledRepositoryImpl }
from '../repositories/AddonEnabledRepository';
import * as operations from '../../shared/operations'; import * as operations from '../../shared/operations';
import { Keymaps } from '../../shared/Settings'; import { Keymaps } from '../../shared/Settings';
import Key from '../domains/Key'; import Key from '../domains/Key';
@ -17,22 +14,18 @@ const reservedKeymaps: Keymaps = {
'<C-[>': { type: operations.CANCEL }, '<C-[>': { type: operations.CANCEL },
}; };
@injectable()
export default class KeymapUseCase { export default class KeymapUseCase {
private repository: KeymapRepository; constructor(
@inject('KeymapRepository')
private settingRepository: SettingRepository; private repository: KeymapRepository,
private addonEnabledRepository: AddonEnabledRepository; @inject('SettingRepository')
private settingRepository: SettingRepository,
constructor({ @inject('AddonEnabledRepository')
repository = new KeymapRepositoryImpl(), private addonEnabledRepository: AddonEnabledRepository,
settingRepository = new SettingRepositoryImpl(), ) {
addonEnabledRepository = new AddonEnabledRepositoryImpl(),
} = {}) {
this.repository = repository;
this.settingRepository = settingRepository;
this.addonEnabledRepository = addonEnabledRepository;
} }
nextOp(key: Key): operations.Operation | null { nextOp(key: Key): operations.Operation | null {

@ -1,13 +1,11 @@
import MarkKeyRepository, { MarkKeyRepositoryImpl } import { injectable, inject } from 'tsyringe';
from '../repositories/MarkKeyRepository'; import MarkKeyRepository from '../repositories/MarkKeyRepository';
@injectable()
export default class MarkKeyUseCase { export default class MarkKeyUseCase {
private repository: MarkKeyRepository; constructor(
@inject('MarkKeyRepository') private repository: MarkKeyRepository,
constructor({ ) {
repository = new MarkKeyRepositoryImpl()
} = {}) {
this.repository = repository;
} }
isSetMode(): boolean { isSetMode(): boolean {

@ -1,35 +1,19 @@
import ScrollPresenter, { ScrollPresenterImpl } import { injectable, inject } from 'tsyringe';
from '../presenters/ScrollPresenter'; import ScrollPresenter from '../presenters/ScrollPresenter';
import MarkClient, { MarkClientImpl } from '../client/MarkClient'; import MarkClient from '../client/MarkClient';
import MarkRepository, { MarkRepositoryImpl } import MarkRepository from '../repositories/MarkRepository';
from '../repositories/MarkRepository'; import SettingRepository from '../repositories/SettingRepository';
import SettingRepository, { SettingRepositoryImpl } import ConsoleClient from '../client/ConsoleClient';
from '../repositories/SettingRepository';
import ConsoleClient, { ConsoleClientImpl } from '../client/ConsoleClient'; @injectable()
export default class MarkUseCase { export default class MarkUseCase {
private scrollPresenter: ScrollPresenter; constructor(
@inject('ScrollPresenter') private scrollPresenter: ScrollPresenter,
private client: MarkClient; @inject('MarkClient') private client: MarkClient,
@inject('MarkRepository') private repository: MarkRepository,
private repository: MarkRepository; @inject('SettingRepository') private settingRepository: SettingRepository,
@inject('ConsoleClient') private consoleClient: ConsoleClient,
private settingRepository: SettingRepository; ) {
private consoleClient: ConsoleClient;
constructor({
scrollPresenter = new ScrollPresenterImpl(),
client = new MarkClientImpl(),
repository = new MarkRepositoryImpl(),
settingRepository = new SettingRepositoryImpl(),
consoleClient = new ConsoleClientImpl(),
} = {}) {
this.scrollPresenter = scrollPresenter;
this.client = client;
this.repository = repository;
this.settingRepository = settingRepository;
this.consoleClient = consoleClient;
} }
async set(key: string): Promise<void> { async set(key: string): Promise<void> {

@ -1,13 +1,12 @@
import NavigationPresenter, { NavigationPresenterImpl } import { injectable, inject } from 'tsyringe';
from '../presenters/NavigationPresenter'; import NavigationPresenter from '../presenters/NavigationPresenter';
@injectable()
export default class NavigateUseCase { export default class NavigateUseCase {
private navigationPresenter: NavigationPresenter; constructor(
@inject('NavigationPresenter')
constructor({ private navigationPresenter: NavigationPresenter,
navigationPresenter = new NavigationPresenterImpl(), ) {
} = {}) {
this.navigationPresenter = navigationPresenter;
} }
openHistoryPrev(): void { openHistoryPrev(): void {

@ -1,19 +1,13 @@
import ScrollPresenter, { ScrollPresenterImpl } import { injectable, inject } from 'tsyringe';
from '../presenters/ScrollPresenter'; import ScrollPresenter from '../presenters/ScrollPresenter';
import SettingRepository, { SettingRepositoryImpl } import SettingRepository from '../repositories/SettingRepository';
from '../repositories/SettingRepository';
@injectable()
export default class ScrollUseCase { export default class ScrollUseCase {
private presenter: ScrollPresenter; constructor(
@inject('ScrollPresenter') private presenter: ScrollPresenter,
private settingRepository: SettingRepository; @inject('SettingRepository') private settingRepository: SettingRepository,
) {
constructor({
presenter = new ScrollPresenterImpl(),
settingRepository = new SettingRepositoryImpl(),
} = {}) {
this.presenter = presenter;
this.settingRepository = settingRepository;
} }
scrollVertically(count: number): void { scrollVertically(count: number): void {

@ -1,19 +1,14 @@
import SettingRepository, { SettingRepositoryImpl } import { injectable, inject } from 'tsyringe';
from '../repositories/SettingRepository'; import SettingRepository from '../repositories/SettingRepository';
import SettingClient, { SettingClientImpl } from '../client/SettingClient'; import SettingClient from '../client/SettingClient';
import Settings from '../../shared/Settings'; import Settings from '../../shared/Settings';
@injectable()
export default class SettingUseCase { export default class SettingUseCase {
private repository: SettingRepository; constructor(
@inject('SettingRepository') private repository: SettingRepository,
private client: SettingClient; @inject('SettingClient') private client: SettingClient,
) {
constructor({
repository = new SettingRepositoryImpl(),
client = new SettingClientImpl(),
} = {}) {
this.repository = repository;
this.client = client;
} }
async reload(): Promise<Settings> { async reload(): Promise<Settings> {

@ -40,7 +40,7 @@ describe('AddonEnabledUseCase', () => {
beforeEach(() => { beforeEach(() => {
repository = new MockAddonEnabledRepository(true); repository = new MockAddonEnabledRepository(true);
indicator = new MockAddonIndicatorClient(false); indicator = new MockAddonIndicatorClient(false);
sut = new AddonEnabledUseCase({ repository, indicator }); sut = new AddonEnabledUseCase(indicator, repository);
}); });
describe('#enable', () => { describe('#enable', () => {

@ -1,4 +1,5 @@
import ClipboardRepository from '../../../src/content/repositories/ClipboardRepository'; import ClipboardRepository from '../../../src/content/repositories/ClipboardRepository';
import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository';
import TabsClient from '../../../src/content/client/TabsClient'; import TabsClient from '../../../src/content/client/TabsClient';
import MockConsoleClient from '../mock/MockConsoleClient'; import MockConsoleClient from '../mock/MockConsoleClient';
import ClipboardUseCase from '../../../src/content/usecases/ClipboardUseCase'; import ClipboardUseCase from '../../../src/content/usecases/ClipboardUseCase';
@ -43,7 +44,12 @@ describe('ClipboardUseCase', () => {
repository = new MockClipboardRepository(); repository = new MockClipboardRepository();
client = new MockTabsClient(); client = new MockTabsClient();
consoleClient = new MockConsoleClient(); consoleClient = new MockConsoleClient();
sut = new ClipboardUseCase({ repository, client: client, consoleClient }); sut = new ClipboardUseCase(
repository,
new SettingRepositoryImpl(),
client,
consoleClient
);
}); });
describe('#yankCurrentURL', () => { describe('#yankCurrentURL', () => {

@ -71,7 +71,7 @@ describe('FindUseCase', () => {
presenter = new MockFindPresenter(); presenter = new MockFindPresenter();
client = new MockFindClient(); client = new MockFindClient();
consoleClient = new MockConsoleClient(); consoleClient = new MockConsoleClient();
sut = new FindUseCase({ repository, presenter, client, consoleClient }); sut = new FindUseCase(presenter, repository, client, consoleClient);
}); });
describe('#startFind', () => { describe('#startFind', () => {

@ -1,4 +1,5 @@
import MarkRepository from '../../../src/content/repositories/MarkRepository'; import MarkRepository from '../../../src/content/repositories/MarkRepository';
import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository';
import MarkUseCase from '../../../src/content/usecases/MarkUseCase'; import MarkUseCase from '../../../src/content/usecases/MarkUseCase';
import MarkClient from '../../../src/content/client/MarkClient'; import MarkClient from '../../../src/content/client/MarkClient';
import MockConsoleClient from '../mock/MockConsoleClient'; import MockConsoleClient from '../mock/MockConsoleClient';
@ -54,9 +55,13 @@ describe('MarkUseCase', () => {
client = new MockMarkClient(); client = new MockMarkClient();
consoleClient = new MockConsoleClient(); consoleClient = new MockConsoleClient();
scrollPresenter = new MockScrollPresenter(); scrollPresenter = new MockScrollPresenter();
sut = new MarkUseCase({ sut = new MarkUseCase(
repository, client, consoleClient, scrollPresenter, scrollPresenter,
}); client,
repository,
new SettingRepositoryImpl(),
consoleClient,
);
}); });
describe('#set', () => { describe('#set', () => {

@ -56,7 +56,7 @@ describe('AddonEnabledUseCase', () => {
repository = new MockSettingRepository(); repository = new MockSettingRepository();
client = new MockSettingClient(testSettings); client = new MockSettingClient(testSettings);
sut = new SettingUseCase({ repository, client }); sut = new SettingUseCase(repository, client);
}); });
describe('#reload', () => { describe('#reload', () => {