From a26d8a8a1bed48a77e062914c120a23ace7bb8cf Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 24 Feb 2019 20:54:35 +0900 Subject: [PATCH 1/5] Capitalize background scripts --- .../controllers/AddonEnabledController.js | 11 +++ .../{command.js => CommandController.js} | 22 +++--- src/background/controllers/FindController.js | 15 ++++ src/background/controllers/LinkController.js | 15 ++++ src/background/controllers/MarkController.js | 15 ++++ .../controllers/OperationController.js | 69 +++++++++++++++++++ .../controllers/SettingController.js | 18 +++++ .../controllers/VersionController.js | 11 +++ src/background/controllers/addon-enabled.js | 11 --- src/background/controllers/find.js | 15 ---- src/background/controllers/link.js | 15 ---- src/background/controllers/mark.js | 15 ---- src/background/controllers/operation.js | 69 ------------------- src/background/controllers/setting.js | 18 ----- src/background/controllers/version.js | 11 --- .../{command-docs.js => CommandDocs.js} | 0 ...completion-group.js => CompletionGroup.js} | 0 .../{completion-item.js => CompletionItem.js} | 0 .../{completions.js => Completions.js} | 0 .../domains/{global-mark.js => GlobalMark.js} | 0 .../domains/{setting.js => Setting.js} | 0 src/background/index.js | 6 +- .../ConsoleClient.js} | 3 +- ...sage-client.js => ContentMessageClient.js} | 0 ...-listener.js => ContentMessageListener.js} | 14 ++-- .../{memory-storage.js => MemoryStorage.js} | 0 .../{notifier.js => Notifier.js} | 0 .../{indicator.js => IndicatorPresenter.js} | 0 .../presenters/{tab.js => TabPresenter.js} | 2 +- .../{window.js => WindowPresenter.js} | 0 .../{bookmark.js => BookmarkRepository.js} | 0 ...ompletions.js => CompletionsRepository.js} | 0 .../{find.js => FindRepository.js} | 2 +- .../{mark.js => MarkRepository.js} | 4 +- ...ting.js => PersistentSettingRepository.js} | 2 +- .../{setting.js => SettingRepository.js} | 2 +- .../{version.js => VersionRepository.js} | 0 ...ddon-enabled.js => AddonEnabledUseCase.js} | 8 +-- .../{command.js => CommandUseCase.js} | 16 ++--- .../{completions.js => CompletionsUseCase.js} | 26 +++---- .../usecases/{find.js => FindUseCase.js} | 4 +- .../usecases/{link.js => LinkUseCase.js} | 6 +- .../usecases/{mark.js => MarkUseCase.js} | 16 ++--- .../{operation.js => OperationUseCase.js} | 24 +++---- .../{setting.js => SettingUseCase.js} | 9 +-- .../{version.js => VersionUseCase.js} | 8 +-- ...global-mark.test.js => GlobalMark.test.js} | 2 +- ...-storage.test.js => MemoryStorage.test.js} | 2 +- .../{mark.test.js => Mark.test.js} | 4 +- .../repositories/{version.js => Version.js} | 2 +- 50 files changed, 247 insertions(+), 245 deletions(-) create mode 100644 src/background/controllers/AddonEnabledController.js rename src/background/controllers/{command.js => CommandController.js} (76%) create mode 100644 src/background/controllers/FindController.js create mode 100644 src/background/controllers/LinkController.js create mode 100644 src/background/controllers/MarkController.js create mode 100644 src/background/controllers/OperationController.js create mode 100644 src/background/controllers/SettingController.js create mode 100644 src/background/controllers/VersionController.js delete mode 100644 src/background/controllers/addon-enabled.js delete mode 100644 src/background/controllers/find.js delete mode 100644 src/background/controllers/link.js delete mode 100644 src/background/controllers/mark.js delete mode 100644 src/background/controllers/operation.js delete mode 100644 src/background/controllers/setting.js delete mode 100644 src/background/controllers/version.js rename src/background/domains/{command-docs.js => CommandDocs.js} (100%) rename src/background/domains/{completion-group.js => CompletionGroup.js} (100%) rename src/background/domains/{completion-item.js => CompletionItem.js} (100%) rename src/background/domains/{completions.js => Completions.js} (100%) rename src/background/domains/{global-mark.js => GlobalMark.js} (100%) rename src/background/domains/{setting.js => Setting.js} (100%) rename src/background/{presenters/console.js => infrastructures/ConsoleClient.js} (94%) rename src/background/infrastructures/{content-message-client.js => ContentMessageClient.js} (100%) rename src/background/infrastructures/{content-message-listener.js => ContentMessageListener.js} (89%) rename src/background/infrastructures/{memory-storage.js => MemoryStorage.js} (100%) rename src/background/infrastructures/{notifier.js => Notifier.js} (100%) rename src/background/presenters/{indicator.js => IndicatorPresenter.js} (100%) rename src/background/presenters/{tab.js => TabPresenter.js} (97%) rename src/background/presenters/{window.js => WindowPresenter.js} (100%) rename src/background/repositories/{bookmark.js => BookmarkRepository.js} (100%) rename src/background/repositories/{completions.js => CompletionsRepository.js} (100%) rename src/background/repositories/{find.js => FindRepository.js} (84%) rename src/background/repositories/{mark.js => MarkRepository.js} (84%) rename src/background/repositories/{persistent-setting.js => PersistentSettingRepository.js} (88%) rename src/background/repositories/{setting.js => SettingRepository.js} (87%) rename src/background/repositories/{version.js => VersionRepository.js} (100%) rename src/background/usecases/{addon-enabled.js => AddonEnabledUseCase.js} (73%) rename src/background/usecases/{command.js => CommandUseCase.js} (87%) rename src/background/usecases/{completions.js => CompletionsUseCase.js} (87%) rename src/background/usecases/{find.js => FindUseCase.js} (69%) rename src/background/usecases/{link.js => LinkUseCase.js} (68%) rename src/background/usecases/{mark.js => MarkUseCase.js} (66%) rename src/background/usecases/{operation.js => OperationUseCase.js} (88%) rename src/background/usecases/{setting.js => SettingUseCase.js} (66%) rename src/background/usecases/{version.js => VersionUseCase.js} (82%) rename test/background/domains/{global-mark.test.js => GlobalMark.test.js} (85%) rename test/background/infrastructures/{memory-storage.test.js => MemoryStorage.test.js} (94%) rename test/background/repositories/{mark.test.js => Mark.test.js} (82%) rename test/background/repositories/{version.js => Version.js} (93%) diff --git a/src/background/controllers/AddonEnabledController.js b/src/background/controllers/AddonEnabledController.js new file mode 100644 index 0000000..9a3a521 --- /dev/null +++ b/src/background/controllers/AddonEnabledController.js @@ -0,0 +1,11 @@ +import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase'; + +export default class AddonEnabledController { + constructor() { + this.addonEnabledUseCase = new AddonEnabledUseCase(); + } + + indicate(enabled) { + return this.addonEnabledUseCase.indicate(enabled); + } +} diff --git a/src/background/controllers/command.js b/src/background/controllers/CommandController.js similarity index 76% rename from src/background/controllers/command.js rename to src/background/controllers/CommandController.js index 9ab1054..b113709 100644 --- a/src/background/controllers/command.js +++ b/src/background/controllers/CommandController.js @@ -1,6 +1,6 @@ -import CompletionsInteractor from '../usecases/completions'; -import CommandInteractor from '../usecases/command'; -import Completions from '../domains/completions'; +import CompletionsUseCase from '../usecases/CompletionsUseCase'; +import CommandUseCase from '../usecases/CommandUseCase'; +import Completions from '../domains/Completions'; const trimStart = (str) => { // NOTE String.trimStart is available on Firefox 61 @@ -9,8 +9,8 @@ const trimStart = (str) => { export default class CommandController { constructor() { - this.completionsInteractor = new CompletionsInteractor(); - this.commandIndicator = new CommandInteractor(); + this.completionsUseCase = new CompletionsUseCase(); + this.commandIndicator = new CommandUseCase(); } getCompletions(line) { @@ -18,7 +18,7 @@ export default class CommandController { let words = trimmed.split(/ +/); let name = words[0]; if (words.length === 1) { - return this.completionsInteractor.queryConsoleCommand(name); + return this.completionsUseCase.queryConsoleCommand(name); } let keywords = trimStart(trimmed.slice(name.length)); switch (words[0]) { @@ -28,22 +28,22 @@ export default class CommandController { case 'tabopen': case 'w': case 'winopen': - return this.completionsInteractor.queryOpen(name, keywords); + return this.completionsUseCase.queryOpen(name, keywords); case 'b': case 'buffer': - return this.completionsInteractor.queryBuffer(name, keywords); + return this.completionsUseCase.queryBuffer(name, keywords); case 'bd': case 'bdel': case 'bdelete': case 'bdeletes': - return this.completionsInteractor.queryBdelete(name, keywords); + return this.completionsUseCase.queryBdelete(name, keywords); case 'bd!': case 'bdel!': case 'bdelete!': case 'bdeletes!': - return this.completionsInteractor.queryBdeleteForce(name, keywords); + return this.completionsUseCase.queryBdeleteForce(name, keywords); case 'set': - return this.completionsInteractor.querySet(name, keywords); + return this.completionsUseCase.querySet(name, keywords); } return Promise.resolve(Completions.empty()); } diff --git a/src/background/controllers/FindController.js b/src/background/controllers/FindController.js new file mode 100644 index 0000000..caeff98 --- /dev/null +++ b/src/background/controllers/FindController.js @@ -0,0 +1,15 @@ +import FindUseCase from '../usecases/FindUseCase'; + +export default class FindController { + constructor() { + this.findUseCase = new FindUseCase(); + } + + getKeyword() { + return this.findUseCase.getKeyword(); + } + + setKeyword(keyword) { + return this.findUseCase.setKeyword(keyword); + } +} diff --git a/src/background/controllers/LinkController.js b/src/background/controllers/LinkController.js new file mode 100644 index 0000000..7e395b1 --- /dev/null +++ b/src/background/controllers/LinkController.js @@ -0,0 +1,15 @@ +import LinkUseCase from '../usecases/LinkUseCase'; + +export default class LinkController { + constructor() { + this.linkUseCase = new LinkUseCase(); + } + + openToTab(url, tabId) { + this.linkUseCase.openToTab(url, tabId); + } + + openNewTab(url, openerId, background) { + this.linkUseCase.openNewTab(url, openerId, background); + } +} diff --git a/src/background/controllers/MarkController.js b/src/background/controllers/MarkController.js new file mode 100644 index 0000000..0478369 --- /dev/null +++ b/src/background/controllers/MarkController.js @@ -0,0 +1,15 @@ +import MarkUseCase from '../usecases/MarkUseCase'; + +export default class MarkController { + constructor() { + this.markUseCase = new MarkUseCase(); + } + + setGlobal(key, x, y) { + this.markUseCase.setGlobal(key, x, y); + } + + jumpGlobal(key) { + this.markUseCase.jumpGlobal(key); + } +} diff --git a/src/background/controllers/OperationController.js b/src/background/controllers/OperationController.js new file mode 100644 index 0000000..609599e --- /dev/null +++ b/src/background/controllers/OperationController.js @@ -0,0 +1,69 @@ +import operations from '../../shared/operations'; +import OperationUseCase from '../usecases/OperationUseCase'; + +export default class OperationController { + constructor() { + this.operationUseCase = new OperationUseCase(); + } + + // eslint-disable-next-line complexity, max-lines-per-function + exec(operation) { + switch (operation.type) { + case operations.TAB_CLOSE: + return this.operationUseCase.close(false); + case operations.TAB_CLOSE_RIGHT: + return this.operationUseCase.closeRight(); + case operations.TAB_CLOSE_FORCE: + return this.operationUseCase.close(true); + case operations.TAB_REOPEN: + return this.operationUseCase.reopen(); + case operations.TAB_PREV: + return this.operationUseCase.selectPrev(1); + case operations.TAB_NEXT: + return this.operationUseCase.selectNext(1); + case operations.TAB_FIRST: + return this.operationUseCase.selectFirst(); + case operations.TAB_LAST: + return this.operationUseCase.selectLast(); + case operations.TAB_PREV_SEL: + return this.operationUseCase.selectPrevSelected(); + case operations.TAB_RELOAD: + return this.operationUseCase.reload(operation.cache); + case operations.TAB_PIN: + return this.operationUseCase.setPinned(true); + case operations.TAB_UNPIN: + return this.operationUseCase.setPinned(false); + case operations.TAB_TOGGLE_PINNED: + return this.operationUseCase.togglePinned(); + case operations.TAB_DUPLICATE: + return this.operationUseCase.duplicate(); + case operations.PAGE_SOURCE: + return this.operationUseCase.openPageSource(); + case operations.PAGE_HOME: + return this.operationUseCase.openHome(operation.newTab); + case operations.ZOOM_IN: + return this.operationUseCase.zoomIn(); + case operations.ZOOM_OUT: + return this.operationUseCase.zoomOut(); + case operations.ZOOM_NEUTRAL: + return this.operationUseCase.zoomNutoral(); + case operations.COMMAND_SHOW: + return this.operationUseCase.showCommand(); + case operations.COMMAND_SHOW_OPEN: + return this.operationUseCase.showOpenCommand(operation.alter); + case operations.COMMAND_SHOW_TABOPEN: + return this.operationUseCase.showTabopenCommand(operation.alter); + case operations.COMMAND_SHOW_WINOPEN: + return this.operationUseCase.showWinopenCommand(operation.alter); + case operations.COMMAND_SHOW_BUFFER: + return this.operationUseCase.showBufferCommand(); + case operations.COMMAND_SHOW_ADDBOOKMARK: + return this.operationUseCase.showAddbookmarkCommand(operation.alter); + case operations.FIND_START: + return this.operationUseCase.findStart(); + case operations.CANCEL: + return this.operationUseCase.hideConsole(); + } + } +} + diff --git a/src/background/controllers/SettingController.js b/src/background/controllers/SettingController.js new file mode 100644 index 0000000..e895d72 --- /dev/null +++ b/src/background/controllers/SettingController.js @@ -0,0 +1,18 @@ +import SettingUseCase from '../usecases/SettingUseCase'; +import ContentMessageClient from '../infrastructures/ContentMessageClient'; + +export default class SettingController { + constructor() { + this.settingUseCase = new SettingUseCase(); + this.contentMessageClient = new ContentMessageClient(); + } + + getSetting() { + return this.settingUseCase.get(); + } + + async reload() { + await this.settingUseCase.reload(); + this.contentMessageClient.broadcastSettingsChanged(); + } +} diff --git a/src/background/controllers/VersionController.js b/src/background/controllers/VersionController.js new file mode 100644 index 0000000..1bcac4c --- /dev/null +++ b/src/background/controllers/VersionController.js @@ -0,0 +1,11 @@ +import VersionUseCase from '../usecases/VersionUseCase'; + +export default class VersionController { + constructor() { + this.versionUseCase = new VersionUseCase(); + } + + notifyIfUpdated() { + this.versionUseCase.notifyIfUpdated(); + } +} diff --git a/src/background/controllers/addon-enabled.js b/src/background/controllers/addon-enabled.js deleted file mode 100644 index 6a9b776..0000000 --- a/src/background/controllers/addon-enabled.js +++ /dev/null @@ -1,11 +0,0 @@ -import AddonEnabledInteractor from '../usecases/addon-enabled'; - -export default class AddonEnabledController { - constructor() { - this.addonEnabledInteractor = new AddonEnabledInteractor(); - } - - indicate(enabled) { - return this.addonEnabledInteractor.indicate(enabled); - } -} diff --git a/src/background/controllers/find.js b/src/background/controllers/find.js deleted file mode 100644 index 7096014..0000000 --- a/src/background/controllers/find.js +++ /dev/null @@ -1,15 +0,0 @@ -import FindInteractor from '../usecases/find'; - -export default class FindController { - constructor() { - this.findInteractor = new FindInteractor(); - } - - getKeyword() { - return this.findInteractor.getKeyword(); - } - - setKeyword(keyword) { - return this.findInteractor.setKeyword(keyword); - } -} diff --git a/src/background/controllers/link.js b/src/background/controllers/link.js deleted file mode 100644 index 7ebbb34..0000000 --- a/src/background/controllers/link.js +++ /dev/null @@ -1,15 +0,0 @@ -import LinkInteractor from '../usecases/link'; - -export default class LinkController { - constructor() { - this.linkInteractor = new LinkInteractor(); - } - - openToTab(url, tabId) { - this.linkInteractor.openToTab(url, tabId); - } - - openNewTab(url, openerId, background) { - this.linkInteractor.openNewTab(url, openerId, background); - } -} diff --git a/src/background/controllers/mark.js b/src/background/controllers/mark.js deleted file mode 100644 index 8d0cefd..0000000 --- a/src/background/controllers/mark.js +++ /dev/null @@ -1,15 +0,0 @@ -import MarkInteractor from '../usecases/mark'; - -export default class MarkController { - constructor() { - this.markInteractor = new MarkInteractor(); - } - - setGlobal(key, x, y) { - this.markInteractor.setGlobal(key, x, y); - } - - jumpGlobal(key) { - this.markInteractor.jumpGlobal(key); - } -} diff --git a/src/background/controllers/operation.js b/src/background/controllers/operation.js deleted file mode 100644 index 646f50e..0000000 --- a/src/background/controllers/operation.js +++ /dev/null @@ -1,69 +0,0 @@ -import operations from '../../shared/operations'; -import OperationInteractor from '../usecases/operation'; - -export default class OperationController { - constructor() { - this.operationInteractor = new OperationInteractor(); - } - - // eslint-disable-next-line complexity, max-lines-per-function - exec(operation) { - switch (operation.type) { - case operations.TAB_CLOSE: - return this.operationInteractor.close(false); - case operations.TAB_CLOSE_RIGHT: - return this.operationInteractor.closeRight(); - case operations.TAB_CLOSE_FORCE: - return this.operationInteractor.close(true); - case operations.TAB_REOPEN: - return this.operationInteractor.reopen(); - case operations.TAB_PREV: - return this.operationInteractor.selectPrev(1); - case operations.TAB_NEXT: - return this.operationInteractor.selectNext(1); - case operations.TAB_FIRST: - return this.operationInteractor.selectFirst(); - case operations.TAB_LAST: - return this.operationInteractor.selectLast(); - case operations.TAB_PREV_SEL: - return this.operationInteractor.selectPrevSelected(); - case operations.TAB_RELOAD: - return this.operationInteractor.reload(operation.cache); - case operations.TAB_PIN: - return this.operationInteractor.setPinned(true); - case operations.TAB_UNPIN: - return this.operationInteractor.setPinned(false); - case operations.TAB_TOGGLE_PINNED: - return this.operationInteractor.togglePinned(); - case operations.TAB_DUPLICATE: - return this.operationInteractor.duplicate(); - case operations.PAGE_SOURCE: - return this.operationInteractor.openPageSource(); - case operations.PAGE_HOME: - return this.operationInteractor.openHome(operation.newTab); - case operations.ZOOM_IN: - return this.operationInteractor.zoomIn(); - case operations.ZOOM_OUT: - return this.operationInteractor.zoomOut(); - case operations.ZOOM_NEUTRAL: - return this.operationInteractor.zoomNutoral(); - case operations.COMMAND_SHOW: - return this.operationInteractor.showCommand(); - case operations.COMMAND_SHOW_OPEN: - return this.operationInteractor.showOpenCommand(operation.alter); - case operations.COMMAND_SHOW_TABOPEN: - return this.operationInteractor.showTabopenCommand(operation.alter); - case operations.COMMAND_SHOW_WINOPEN: - return this.operationInteractor.showWinopenCommand(operation.alter); - case operations.COMMAND_SHOW_BUFFER: - return this.operationInteractor.showBufferCommand(); - case operations.COMMAND_SHOW_ADDBOOKMARK: - return this.operationInteractor.showAddbookmarkCommand(operation.alter); - case operations.FIND_START: - return this.operationInteractor.findStart(); - case operations.CANCEL: - return this.operationInteractor.hideConsole(); - } - } -} - diff --git a/src/background/controllers/setting.js b/src/background/controllers/setting.js deleted file mode 100644 index 9e6019e..0000000 --- a/src/background/controllers/setting.js +++ /dev/null @@ -1,18 +0,0 @@ -import SettingInteractor from '../usecases/setting'; -import ContentMessageClient from '../infrastructures/content-message-client'; - -export default class SettingController { - constructor() { - this.settingInteractor = new SettingInteractor(); - this.contentMessageClient = new ContentMessageClient(); - } - - getSetting() { - return this.settingInteractor.get(); - } - - async reload() { - await this.settingInteractor.reload(); - this.contentMessageClient.broadcastSettingsChanged(); - } -} diff --git a/src/background/controllers/version.js b/src/background/controllers/version.js deleted file mode 100644 index 04d99fe..0000000 --- a/src/background/controllers/version.js +++ /dev/null @@ -1,11 +0,0 @@ -import VersionInteractor from '../usecases/version'; - -export default class VersionController { - constructor() { - this.versionInteractor = new VersionInteractor(); - } - - notifyIfUpdated() { - this.versionInteractor.notifyIfUpdated(); - } -} diff --git a/src/background/domains/command-docs.js b/src/background/domains/CommandDocs.js similarity index 100% rename from src/background/domains/command-docs.js rename to src/background/domains/CommandDocs.js diff --git a/src/background/domains/completion-group.js b/src/background/domains/CompletionGroup.js similarity index 100% rename from src/background/domains/completion-group.js rename to src/background/domains/CompletionGroup.js diff --git a/src/background/domains/completion-item.js b/src/background/domains/CompletionItem.js similarity index 100% rename from src/background/domains/completion-item.js rename to src/background/domains/CompletionItem.js diff --git a/src/background/domains/completions.js b/src/background/domains/Completions.js similarity index 100% rename from src/background/domains/completions.js rename to src/background/domains/Completions.js diff --git a/src/background/domains/global-mark.js b/src/background/domains/GlobalMark.js similarity index 100% rename from src/background/domains/global-mark.js rename to src/background/domains/GlobalMark.js diff --git a/src/background/domains/setting.js b/src/background/domains/Setting.js similarity index 100% rename from src/background/domains/setting.js rename to src/background/domains/Setting.js diff --git a/src/background/index.js b/src/background/index.js index 30007a9..b829f99 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -1,6 +1,6 @@ -import ContentMessageListener from './infrastructures/content-message-listener'; -import SettingController from './controllers/setting'; -import VersionController from './controllers/version'; +import ContentMessageListener from './infrastructures/ContentMessageListener'; +import SettingController from './controllers/SettingController'; +import VersionController from './controllers/VersionController'; new SettingController().reload(); new VersionController().notifyIfUpdated(); diff --git a/src/background/presenters/console.js b/src/background/infrastructures/ConsoleClient.js similarity index 94% rename from src/background/presenters/console.js rename to src/background/infrastructures/ConsoleClient.js index 8259238..f691515 100644 --- a/src/background/presenters/console.js +++ b/src/background/infrastructures/ConsoleClient.js @@ -1,6 +1,6 @@ import messages from '../../shared/messages'; -export default class ConsolePresenter { +export default class ConsoleClient { showCommand(tabId, command) { return browser.tabs.sendMessage(tabId, { type: messages.CONSOLE_SHOW_COMMAND, @@ -34,3 +34,4 @@ export default class ConsolePresenter { }); } } + diff --git a/src/background/infrastructures/content-message-client.js b/src/background/infrastructures/ContentMessageClient.js similarity index 100% rename from src/background/infrastructures/content-message-client.js rename to src/background/infrastructures/ContentMessageClient.js diff --git a/src/background/infrastructures/content-message-listener.js b/src/background/infrastructures/ContentMessageListener.js similarity index 89% rename from src/background/infrastructures/content-message-listener.js rename to src/background/infrastructures/ContentMessageListener.js index aae07c0..1179a8c 100644 --- a/src/background/infrastructures/content-message-listener.js +++ b/src/background/infrastructures/ContentMessageListener.js @@ -1,11 +1,11 @@ import messages from '../../shared/messages'; -import CommandController from '../controllers/command'; -import SettingController from '../controllers/setting'; -import FindController from '../controllers/find'; -import AddonEnabledController from '../controllers/addon-enabled'; -import LinkController from '../controllers/link'; -import OperationController from '../controllers/operation'; -import MarkController from '../controllers/mark'; +import CommandController from '../controllers/CommandController'; +import SettingController from '../controllers/SettingController'; +import FindController from '../controllers/FindController'; +import AddonEnabledController from '../controllers/AddonEnabledController'; +import LinkController from '../controllers/LinkController'; +import OperationController from '../controllers/OperationController'; +import MarkController from '../controllers/MarkController'; export default class ContentMessageListener { constructor() { diff --git a/src/background/infrastructures/memory-storage.js b/src/background/infrastructures/MemoryStorage.js similarity index 100% rename from src/background/infrastructures/memory-storage.js rename to src/background/infrastructures/MemoryStorage.js diff --git a/src/background/infrastructures/notifier.js b/src/background/infrastructures/Notifier.js similarity index 100% rename from src/background/infrastructures/notifier.js rename to src/background/infrastructures/Notifier.js diff --git a/src/background/presenters/indicator.js b/src/background/presenters/IndicatorPresenter.js similarity index 100% rename from src/background/presenters/indicator.js rename to src/background/presenters/IndicatorPresenter.js diff --git a/src/background/presenters/tab.js b/src/background/presenters/TabPresenter.js similarity index 97% rename from src/background/presenters/tab.js rename to src/background/presenters/TabPresenter.js index 69cae1c..744be39 100644 --- a/src/background/presenters/tab.js +++ b/src/background/presenters/TabPresenter.js @@ -1,4 +1,4 @@ -import MemoryStorage from '../infrastructures/memory-storage'; +import MemoryStorage from '../infrastructures/MemoryStorage'; const CURRENT_SELECTED_KEY = 'tabs.current.selected'; const LAST_SELECTED_KEY = 'tabs.last.selected'; diff --git a/src/background/presenters/window.js b/src/background/presenters/WindowPresenter.js similarity index 100% rename from src/background/presenters/window.js rename to src/background/presenters/WindowPresenter.js diff --git a/src/background/repositories/bookmark.js b/src/background/repositories/BookmarkRepository.js similarity index 100% rename from src/background/repositories/bookmark.js rename to src/background/repositories/BookmarkRepository.js diff --git a/src/background/repositories/completions.js b/src/background/repositories/CompletionsRepository.js similarity index 100% rename from src/background/repositories/completions.js rename to src/background/repositories/CompletionsRepository.js diff --git a/src/background/repositories/find.js b/src/background/repositories/FindRepository.js similarity index 84% rename from src/background/repositories/find.js rename to src/background/repositories/FindRepository.js index 6656c58..74ec914 100644 --- a/src/background/repositories/find.js +++ b/src/background/repositories/FindRepository.js @@ -1,4 +1,4 @@ -import MemoryStorage from '../infrastructures/memory-storage'; +import MemoryStorage from '../infrastructures/MemoryStorage'; const FIND_KEYWORD_KEY = 'find-keyword'; diff --git a/src/background/repositories/mark.js b/src/background/repositories/MarkRepository.js similarity index 84% rename from src/background/repositories/mark.js rename to src/background/repositories/MarkRepository.js index 339a660..282c712 100644 --- a/src/background/repositories/mark.js +++ b/src/background/repositories/MarkRepository.js @@ -1,5 +1,5 @@ -import MemoryStorage from '../infrastructures/memory-storage'; -import GlobalMark from 'background/domains/global-mark'; +import MemoryStorage from '../infrastructures/MemoryStorage'; +import GlobalMark from '../domains/GlobalMark'; const MARK_KEY = 'mark'; diff --git a/src/background/repositories/persistent-setting.js b/src/background/repositories/PersistentSettingRepository.js similarity index 88% rename from src/background/repositories/persistent-setting.js rename to src/background/repositories/PersistentSettingRepository.js index 247ea6f..639bcd1 100644 --- a/src/background/repositories/persistent-setting.js +++ b/src/background/repositories/PersistentSettingRepository.js @@ -1,4 +1,4 @@ -import Setting from '../domains/setting'; +import Setting from '../domains/Setting'; export default class SettingRepository { save(settings) { diff --git a/src/background/repositories/setting.js b/src/background/repositories/SettingRepository.js similarity index 87% rename from src/background/repositories/setting.js rename to src/background/repositories/SettingRepository.js index 6d48525..c4667a9 100644 --- a/src/background/repositories/setting.js +++ b/src/background/repositories/SettingRepository.js @@ -1,4 +1,4 @@ -import MemoryStorage from '../infrastructures/memory-storage'; +import MemoryStorage from '../infrastructures/MemoryStorage'; const CACHED_SETTING_KEY = 'setting'; diff --git a/src/background/repositories/version.js b/src/background/repositories/VersionRepository.js similarity index 100% rename from src/background/repositories/version.js rename to src/background/repositories/VersionRepository.js diff --git a/src/background/usecases/addon-enabled.js b/src/background/usecases/AddonEnabledUseCase.js similarity index 73% rename from src/background/usecases/addon-enabled.js rename to src/background/usecases/AddonEnabledUseCase.js index d83192f..bb2c347 100644 --- a/src/background/usecases/addon-enabled.js +++ b/src/background/usecases/AddonEnabledUseCase.js @@ -1,8 +1,8 @@ -import IndicatorPresenter from '../presenters/indicator'; -import TabPresenter from '../presenters/tab'; -import ContentMessageClient from '../infrastructures/content-message-client'; +import IndicatorPresenter from '../presenters/IndicatorPresenter'; +import TabPresenter from '../presenters/TabPresenter'; +import ContentMessageClient from '../infrastructures/ContentMessageClient'; -export default class AddonEnabledInteractor { +export default class AddonEnabledUseCase { constructor() { this.indicatorPresentor = new IndicatorPresenter(); diff --git a/src/background/usecases/command.js b/src/background/usecases/CommandUseCase.js similarity index 87% rename from src/background/usecases/command.js rename to src/background/usecases/CommandUseCase.js index 0d21041..9ec46fe 100644 --- a/src/background/usecases/command.js +++ b/src/background/usecases/CommandUseCase.js @@ -1,11 +1,11 @@ import * as parsers from './parsers'; import * as urls from '../../shared/urls'; -import TabPresenter from '../presenters/tab'; -import WindowPresenter from '../presenters/window'; -import SettingRepository from '../repositories/setting'; -import BookmarkRepository from '../repositories/bookmark'; -import ConsolePresenter from '../presenters/console'; -import ContentMessageClient from '../infrastructures/content-message-client'; +import TabPresenter from '../presenters/TabPresenter'; +import WindowPresenter from '../presenters/WindowPresenter'; +import SettingRepository from '../repositories/SettingRepository'; +import BookmarkRepository from '../repositories/BookmarkRepository'; +import ConsoleClient from '../infrastructures/ConsoleClient'; +import ContentMessageClient from '../infrastructures/ContentMessageClient'; import * as properties from 'shared/settings/properties'; export default class CommandIndicator { @@ -14,7 +14,7 @@ export default class CommandIndicator { this.windowPresenter = new WindowPresenter(); this.settingRepository = new SettingRepository(); this.bookmarkRepository = new BookmarkRepository(); - this.consolePresenter = new ConsolePresenter(); + this.consoleClient = new ConsoleClient(); this.contentMessageClient = new ContentMessageClient(); } @@ -105,7 +105,7 @@ export default class CommandIndicator { let tab = await this.tabPresenter.getCurrent(); let item = await this.bookmarkRepository.create(title, tab.url); let message = 'Saved current page: ' + item.url; - return this.consolePresenter.showInfo(tab.id, message); + return this.consoleClient.showInfo(tab.id, message); } async set(keywords) { diff --git a/src/background/usecases/completions.js b/src/background/usecases/CompletionsUseCase.js similarity index 87% rename from src/background/usecases/completions.js rename to src/background/usecases/CompletionsUseCase.js index 21dc668..7dc30ac 100644 --- a/src/background/usecases/completions.js +++ b/src/background/usecases/CompletionsUseCase.js @@ -1,19 +1,19 @@ -import CompletionItem from '../domains/completion-item'; -import CompletionGroup from '../domains/completion-group'; -import Completions from '../domains/completions'; -import CommandDocs from '../domains/command-docs'; -import CompletionRepository from '../repositories/completions'; +import CompletionItem from '../domains/CompletionItem'; +import CompletionGroup from '../domains/CompletionGroup'; +import Completions from '../domains/Completions'; +import CommandDocs from '../domains/CommandDocs'; +import CompletionsRepository from '../repositories/CompletionsRepository'; import * as filters from './filters'; -import SettingRepository from '../repositories/setting'; -import TabPresenter from '../presenters/tab'; +import SettingRepository from '../repositories/SettingRepository'; +import TabPresenter from '../presenters/TabPresenter'; import * as properties from '../../shared/settings/properties'; const COMPLETION_ITEM_LIMIT = 10; -export default class CompletionsInteractor { +export default class CompletionsUseCase { constructor() { this.tabPresenter = new TabPresenter(); - this.completionRepository = new CompletionRepository(); + this.completionsRepository = new CompletionsRepository(); this.settingRepository = new SettingRepository(); } @@ -86,7 +86,7 @@ export default class CompletionsInteractor { tabs = [tab]; } } else { - tabs = await this.completionRepository.queryTabs(keywords, false); + tabs = await this.completionsRepository.queryTabs(keywords, false); } const flag = (tab) => { if (tab.active) { @@ -153,7 +153,7 @@ export default class CompletionsInteractor { } async queryTabs(name, excludePinned, args) { - let tabs = await this.completionRepository.queryTabs(args, excludePinned); + let tabs = await this.completionsRepository.queryTabs(args, excludePinned); let items = tabs.map(tab => new CompletionItem({ caption: tab.title, content: name + ' ' + tab.title, @@ -177,7 +177,7 @@ export default class CompletionsInteractor { } async queryHistoryItems(name, keywords) { - let histories = await this.completionRepository.queryHistories(keywords); + let histories = await this.completionsRepository.queryHistories(keywords); histories = [histories] .map(filters.filterBlankTitle) .map(filters.filterHttp) @@ -194,7 +194,7 @@ export default class CompletionsInteractor { } async queryBookmarkItems(name, keywords) { - let bookmarks = await this.completionRepository.queryBookmarks(keywords); + let bookmarks = await this.completionsRepository.queryBookmarks(keywords); return bookmarks.slice(0, COMPLETION_ITEM_LIMIT) .map(page => new CompletionItem({ caption: page.title, diff --git a/src/background/usecases/find.js b/src/background/usecases/FindUseCase.js similarity index 69% rename from src/background/usecases/find.js rename to src/background/usecases/FindUseCase.js index eae480d..d6b0323 100644 --- a/src/background/usecases/find.js +++ b/src/background/usecases/FindUseCase.js @@ -1,6 +1,6 @@ -import FindRepository from '../repositories/find'; +import FindRepository from '../repositories/FindRepository'; -export default class FindInteractor { +export default class FindUseCase { constructor() { this.findRepository = new FindRepository(); } diff --git a/src/background/usecases/link.js b/src/background/usecases/LinkUseCase.js similarity index 68% rename from src/background/usecases/link.js rename to src/background/usecases/LinkUseCase.js index b8ed719..89412c5 100644 --- a/src/background/usecases/link.js +++ b/src/background/usecases/LinkUseCase.js @@ -1,7 +1,7 @@ -import SettingRepository from '../repositories/setting'; -import TabPresenter from '../presenters/tab'; +import SettingRepository from '../repositories/SettingRepository'; +import TabPresenter from '../presenters/TabPresenter'; -export default class LinkInteractor { +export default class LinkUseCase { constructor() { this.settingRepository = new SettingRepository(); this.tabPresenter = new TabPresenter(); diff --git a/src/background/usecases/mark.js b/src/background/usecases/MarkUseCase.js similarity index 66% rename from src/background/usecases/mark.js rename to src/background/usecases/MarkUseCase.js index 34b8a74..39c796b 100644 --- a/src/background/usecases/mark.js +++ b/src/background/usecases/MarkUseCase.js @@ -1,14 +1,14 @@ -import GlobalMark from '../domains/global-mark'; -import TabPresenter from '../presenters/tab'; -import MarkRepository from '../repositories/mark'; -import ConsolePresenter from '../presenters/console'; -import ContentMessageClient from '../infrastructures/content-message-client'; +import GlobalMark from '../domains/GlobalMark'; +import TabPresenter from '../presenters/TabPresenter'; +import MarkRepository from '../repositories/MarkRepository'; +import ConsoleClient from '../infrastructures/ConsoleClient'; +import ContentMessageClient from '../infrastructures/ContentMessageClient'; -export default class MarkInteractor { +export default class MarkUseCase { constructor() { this.tabPresenter = new TabPresenter(); this.markRepository = new MarkRepository(); - this.consolePresenter = new ConsolePresenter(); + this.consoleClient = new ConsoleClient(); this.contentMessageClient = new ContentMessageClient(); } @@ -23,7 +23,7 @@ export default class MarkInteractor { let mark = await this.markRepository.getMark(key); if (!mark) { - return this.consolePresenter.showError(current.id, 'Mark is not set'); + return this.consoleClient.showError(current.id, 'Mark is not set'); } return this.contentMessageClient.scrollTo( diff --git a/src/background/usecases/operation.js b/src/background/usecases/OperationUseCase.js similarity index 88% rename from src/background/usecases/operation.js rename to src/background/usecases/OperationUseCase.js index ed64032..1d75d1a 100644 --- a/src/background/usecases/operation.js +++ b/src/background/usecases/OperationUseCase.js @@ -1,5 +1,5 @@ -import TabPresenter from '../presenters/tab'; -import ConsolePresenter from '../presenters/console'; +import TabPresenter from '../presenters/TabPresenter'; +import ConsoleClient from '../infrastructures/ConsoleClient'; import * as urls from '../../shared/urls'; const ZOOM_SETTINGS = [ @@ -7,10 +7,10 @@ const ZOOM_SETTINGS = [ 1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00 ]; -export default class OperationInteractor { +export default class OperationUseCase { constructor() { this.tabPresenter = new TabPresenter(); - this.consolePresenter = new ConsolePresenter(); + this.consoleClient = new ConsoleClient(); } async close(force) { @@ -134,7 +134,7 @@ export default class OperationInteractor { async showCommand() { let tab = await this.tabPresenter.getCurrent(); - return this.consolePresenter.showCommand(tab.id, ''); + return this.consoleClient.showCommand(tab.id, ''); } async showOpenCommand(alter) { @@ -143,7 +143,7 @@ export default class OperationInteractor { if (alter) { command += tab.url; } - return this.consolePresenter.showCommand(tab.id, command); + return this.consoleClient.showCommand(tab.id, command); } async showTabopenCommand(alter) { @@ -152,7 +152,7 @@ export default class OperationInteractor { if (alter) { command += tab.url; } - return this.consolePresenter.showCommand(tab.id, command); + return this.consoleClient.showCommand(tab.id, command); } async showWinopenCommand(alter) { @@ -161,13 +161,13 @@ export default class OperationInteractor { if (alter) { command += tab.url; } - return this.consolePresenter.showCommand(tab.id, command); + return this.consoleClient.showCommand(tab.id, command); } async showBufferCommand() { let tab = await this.tabPresenter.getCurrent(); let command = 'buffer '; - return this.consolePresenter.showCommand(tab.id, command); + return this.consoleClient.showCommand(tab.id, command); } async showAddbookmarkCommand(alter) { @@ -176,17 +176,17 @@ export default class OperationInteractor { if (alter) { command += tab.title; } - return this.consolePresenter.showCommand(tab.id, command); + return this.consoleClient.showCommand(tab.id, command); } async findStart() { let tab = await this.tabPresenter.getCurrent(); - return this.consolePresenter.showFind(tab.id); + return this.consoleClient.showFind(tab.id); } async hideConsole() { let tab = await this.tabPresenter.getCurrent(); - return this.consolePresenter.hide(tab.id); + return this.consoleClient.hide(tab.id); } async openHome(newTab) { diff --git a/src/background/usecases/setting.js b/src/background/usecases/SettingUseCase.js similarity index 66% rename from src/background/usecases/setting.js rename to src/background/usecases/SettingUseCase.js index 656fc3f..fe3ca5d 100644 --- a/src/background/usecases/setting.js +++ b/src/background/usecases/SettingUseCase.js @@ -1,8 +1,9 @@ -import Setting from '../domains/setting'; -import PersistentSettingRepository from '../repositories/persistent-setting'; -import SettingRepository from '../repositories/setting'; +import Setting from '../domains/Setting'; +// eslint-disable-next-line max-len +import PersistentSettingRepository from '../repositories/PersistentSettingRepository'; +import SettingRepository from '../repositories/SettingRepository'; -export default class SettingInteractor { +export default class SettingUseCase { constructor() { this.persistentSettingRepository = new PersistentSettingRepository(); this.settingRepository = new SettingRepository(); diff --git a/src/background/usecases/version.js b/src/background/usecases/VersionUseCase.js similarity index 82% rename from src/background/usecases/version.js rename to src/background/usecases/VersionUseCase.js index a71f90d..704c808 100644 --- a/src/background/usecases/version.js +++ b/src/background/usecases/VersionUseCase.js @@ -1,9 +1,9 @@ import manifest from '../../../manifest.json'; -import VersionRepository from '../repositories/version'; -import TabPresenter from '../presenters/tab'; -import Notifier from '../infrastructures/notifier'; +import VersionRepository from '../repositories/VersionRepository'; +import TabPresenter from '../presenters/TabPresenter'; +import Notifier from '../infrastructures/Notifier'; -export default class VersionInteractor { +export default class VersionUseCase { constructor() { this.versionRepository = new VersionRepository(); this.tabPresenter = new TabPresenter(); diff --git a/test/background/domains/global-mark.test.js b/test/background/domains/GlobalMark.test.js similarity index 85% rename from test/background/domains/global-mark.test.js rename to test/background/domains/GlobalMark.test.js index bdf1ea6..ed636e9 100644 --- a/test/background/domains/global-mark.test.js +++ b/test/background/domains/GlobalMark.test.js @@ -1,4 +1,4 @@ -import GlobalMark from 'background/domains/global-mark'; +import GlobalMark from 'background/domains/GlobalMark'; describe('background/domains/global-mark', () => { describe('constructor and getter', () => { diff --git a/test/background/infrastructures/memory-storage.test.js b/test/background/infrastructures/MemoryStorage.test.js similarity index 94% rename from test/background/infrastructures/memory-storage.test.js rename to test/background/infrastructures/MemoryStorage.test.js index 8871749..95d3780 100644 --- a/test/background/infrastructures/memory-storage.test.js +++ b/test/background/infrastructures/MemoryStorage.test.js @@ -1,4 +1,4 @@ -import MemoryStorage from 'background/infrastructures/memory-storage'; +import MemoryStorage from 'background/infrastructures/MemoryStorage'; describe("background/infrastructures/memory-storage", () => { it('stores values', () => { diff --git a/test/background/repositories/mark.test.js b/test/background/repositories/Mark.test.js similarity index 82% rename from test/background/repositories/mark.test.js rename to test/background/repositories/Mark.test.js index 4f71f62..2a5b099 100644 --- a/test/background/repositories/mark.test.js +++ b/test/background/repositories/Mark.test.js @@ -1,5 +1,5 @@ -import MarkRepository from 'background/repositories/mark'; -import GlobalMark from 'background/domains/global-mark'; +import MarkRepository from 'background/repositories/MarkRepository'; +import GlobalMark from 'background/domains/GlobalMark'; describe('background/repositories/mark', () => { let repository; diff --git a/test/background/repositories/version.js b/test/background/repositories/Version.js similarity index 93% rename from test/background/repositories/version.js rename to test/background/repositories/Version.js index 8510ae6..c7fa88b 100644 --- a/test/background/repositories/version.js +++ b/test/background/repositories/Version.js @@ -1,4 +1,4 @@ -import VersionRepository from 'background/repositories/version'; +import VersionRepository from 'background/repositories/Version'; describe("background/repositories/version", () => { let versionRepository; From a880d5684b35235436f571e5fd8e9f857bf30434 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 24 Feb 2019 21:34:55 +0900 Subject: [PATCH 2/5] Remove unused methods --- src/background/repositories/PersistentSettingRepository.js | 4 ---- src/background/usecases/SettingUseCase.js | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/background/repositories/PersistentSettingRepository.js b/src/background/repositories/PersistentSettingRepository.js index 639bcd1..4cab107 100644 --- a/src/background/repositories/PersistentSettingRepository.js +++ b/src/background/repositories/PersistentSettingRepository.js @@ -1,10 +1,6 @@ import Setting from '../domains/Setting'; export default class SettingRepository { - save(settings) { - return browser.storage.local.set({ settings: settings.serialize() }); - } - async load() { let { settings } = await browser.storage.local.get('settings'); if (!settings) { diff --git a/src/background/usecases/SettingUseCase.js b/src/background/usecases/SettingUseCase.js index fe3ca5d..9e17408 100644 --- a/src/background/usecases/SettingUseCase.js +++ b/src/background/usecases/SettingUseCase.js @@ -9,10 +9,6 @@ export default class SettingUseCase { this.settingRepository = new SettingRepository(); } - save(settings) { - this.persistentSettingRepository.save(settings); - } - get() { return this.settingRepository.get(); } From f707f4da75652b4c344df9346a34e8010a044006 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 24 Feb 2019 22:20:37 +0900 Subject: [PATCH 3/5] Clean classes and repository --- .../controllers/OperationController.js | 66 +++--- .../repositories/BrowserSettingRepository.js | 8 + src/background/usecases/ConsoleUseCase.js | 61 +++++ src/background/usecases/FindUseCase.js | 9 + src/background/usecases/OperationUseCase.js | 208 ------------------ src/background/usecases/TabSelectUseCase.js | 51 +++++ src/background/usecases/TabUseCase.js | 77 +++++++ src/background/usecases/ZoomUseCase.js | 35 +++ src/shared/urls.js | 6 +- test/shared/urls.test.js | 9 - 10 files changed, 279 insertions(+), 251 deletions(-) create mode 100644 src/background/repositories/BrowserSettingRepository.js create mode 100644 src/background/usecases/ConsoleUseCase.js delete mode 100644 src/background/usecases/OperationUseCase.js create mode 100644 src/background/usecases/TabSelectUseCase.js create mode 100644 src/background/usecases/TabUseCase.js create mode 100644 src/background/usecases/ZoomUseCase.js diff --git a/src/background/controllers/OperationController.js b/src/background/controllers/OperationController.js index 609599e..416aa9c 100644 --- a/src/background/controllers/OperationController.js +++ b/src/background/controllers/OperationController.js @@ -1,68 +1,76 @@ import operations from '../../shared/operations'; -import OperationUseCase from '../usecases/OperationUseCase'; +import FindUseCase from '../usecases/FindUseCase'; +import ConsoleUseCase from '../usecases/ConsoleUseCase'; +import TabUseCase from '../usecases/TabUseCase'; +import TabSelectUseCase from '../usecases/TabSelectUseCase'; +import ZoomUseCase from '../usecases/ZoomUseCase'; export default class OperationController { constructor() { - this.operationUseCase = new OperationUseCase(); + 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 exec(operation) { switch (operation.type) { case operations.TAB_CLOSE: - return this.operationUseCase.close(false); + return this.tabUseCase.close(false); case operations.TAB_CLOSE_RIGHT: - return this.operationUseCase.closeRight(); + return this.tabUseCase.closeRight(); case operations.TAB_CLOSE_FORCE: - return this.operationUseCase.close(true); + return this.tabUseCase.close(true); case operations.TAB_REOPEN: - return this.operationUseCase.reopen(); + return this.tabUseCase.reopen(); case operations.TAB_PREV: - return this.operationUseCase.selectPrev(1); + return this.tabSelectUseCase.selectPrev(1); case operations.TAB_NEXT: - return this.operationUseCase.selectNext(1); + return this.tabSelectUseCase.selectNext(1); case operations.TAB_FIRST: - return this.operationUseCase.selectFirst(); + return this.tabSelectUseCase.selectFirst(); case operations.TAB_LAST: - return this.operationUseCase.selectLast(); + return this.tabSelectUseCase.selectLast(); case operations.TAB_PREV_SEL: - return this.operationUseCase.selectPrevSelected(); + return this.tabSelectUseCase.selectPrevSelected(); case operations.TAB_RELOAD: - return this.operationUseCase.reload(operation.cache); + return this.tabUseCase.reload(operation.cache); case operations.TAB_PIN: - return this.operationUseCase.setPinned(true); + return this.tabUseCase.setPinned(true); case operations.TAB_UNPIN: - return this.operationUseCase.setPinned(false); + return this.tabUseCase.setPinned(false); case operations.TAB_TOGGLE_PINNED: - return this.operationUseCase.togglePinned(); + return this.tabUseCase.togglePinned(); case operations.TAB_DUPLICATE: - return this.operationUseCase.duplicate(); + return this.tabUseCase.duplicate(); case operations.PAGE_SOURCE: - return this.operationUseCase.openPageSource(); + return this.tabUseCase.openPageSource(); case operations.PAGE_HOME: - return this.operationUseCase.openHome(operation.newTab); + return this.tabUseCase.openHome(operation.newTab); case operations.ZOOM_IN: - return this.operationUseCase.zoomIn(); + return this.zoomUseCase.zoomIn(); case operations.ZOOM_OUT: - return this.operationUseCase.zoomOut(); + return this.zoomUseCase.zoomOut(); case operations.ZOOM_NEUTRAL: - return this.operationUseCase.zoomNutoral(); + return this.zoomUseCase.zoomNutoral(); case operations.COMMAND_SHOW: - return this.operationUseCase.showCommand(); + return this.consoleUseCase.showCommand(); case operations.COMMAND_SHOW_OPEN: - return this.operationUseCase.showOpenCommand(operation.alter); + return this.consoleUseCase.showOpenCommand(operation.alter); case operations.COMMAND_SHOW_TABOPEN: - return this.operationUseCase.showTabopenCommand(operation.alter); + return this.consoleUseCase.showTabopenCommand(operation.alter); case operations.COMMAND_SHOW_WINOPEN: - return this.operationUseCase.showWinopenCommand(operation.alter); + return this.consoleUseCase.showWinopenCommand(operation.alter); case operations.COMMAND_SHOW_BUFFER: - return this.operationUseCase.showBufferCommand(); + return this.consoleUseCase.showBufferCommand(); case operations.COMMAND_SHOW_ADDBOOKMARK: - return this.operationUseCase.showAddbookmarkCommand(operation.alter); + return this.consoleUseCase.showAddbookmarkCommand(operation.alter); case operations.FIND_START: - return this.operationUseCase.findStart(); + return this.findUseCase.findStart(); case operations.CANCEL: - return this.operationUseCase.hideConsole(); + return this.consoleUseCase.hideConsole(); } } } diff --git a/src/background/repositories/BrowserSettingRepository.js b/src/background/repositories/BrowserSettingRepository.js new file mode 100644 index 0000000..a9d2c06 --- /dev/null +++ b/src/background/repositories/BrowserSettingRepository.js @@ -0,0 +1,8 @@ +import * as urls from '../../shared/urls'; + +export default class BrowserSettingRepository { + async getHomepageUrls() { + let { value } = await browser.browserSettings.homepageOverride.get({}); + return value.split('|').map(urls.normalizeUrl); + } +} diff --git a/src/background/usecases/ConsoleUseCase.js b/src/background/usecases/ConsoleUseCase.js new file mode 100644 index 0000000..e8e5d4a --- /dev/null +++ b/src/background/usecases/ConsoleUseCase.js @@ -0,0 +1,61 @@ +import TabPresenter from '../presenters/TabPresenter'; +import ConsoleClient from '../infrastructures/ConsoleClient'; + +export default class ConsoleUseCase { + constructor() { + this.tabPresenter = new TabPresenter(); + this.consoleClient = new ConsoleClient(); + } + + async showCommand() { + let tab = await this.tabPresenter.getCurrent(); + return this.consoleClient.showCommand(tab.id, ''); + } + + async showOpenCommand(alter) { + let tab = await this.tabPresenter.getCurrent(); + let command = 'open '; + if (alter) { + command += tab.url; + } + return this.consoleClient.showCommand(tab.id, command); + } + + async showTabopenCommand(alter) { + let tab = await this.tabPresenter.getCurrent(); + let command = 'tabopen '; + if (alter) { + command += tab.url; + } + return this.consoleClient.showCommand(tab.id, command); + } + + async showWinopenCommand(alter) { + let tab = await this.tabPresenter.getCurrent(); + let command = 'winopen '; + if (alter) { + command += tab.url; + } + return this.consoleClient.showCommand(tab.id, command); + } + + async showBufferCommand() { + let tab = await this.tabPresenter.getCurrent(); + let command = 'buffer '; + return this.consoleClient.showCommand(tab.id, command); + } + + async showAddbookmarkCommand(alter) { + let tab = await this.tabPresenter.getCurrent(); + let command = 'addbookmark '; + if (alter) { + command += tab.title; + } + return this.consoleClient.showCommand(tab.id, command); + } + + async hideConsole() { + let tab = await this.tabPresenter.getCurrent(); + return this.consoleClient.hide(tab.id); + } +} diff --git a/src/background/usecases/FindUseCase.js b/src/background/usecases/FindUseCase.js index d6b0323..224e4a9 100644 --- a/src/background/usecases/FindUseCase.js +++ b/src/background/usecases/FindUseCase.js @@ -1,8 +1,12 @@ import FindRepository from '../repositories/FindRepository'; +import TabPresenter from '../presenters/TabPresenter'; +import ConsoleClient from '../infrastructures/ConsoleClient'; export default class FindUseCase { constructor() { + this.tabPresenter = new TabPresenter(); this.findRepository = new FindRepository(); + this.consoleClient = new ConsoleClient(); } getKeyword() { @@ -12,4 +16,9 @@ export default class FindUseCase { setKeyword(keyword) { return this.findRepository.setKeyword(keyword); } + + async findStart() { + let tab = await this.tabPresenter.getCurrent(); + return this.consoleClient.showFind(tab.id); + } } diff --git a/src/background/usecases/OperationUseCase.js b/src/background/usecases/OperationUseCase.js deleted file mode 100644 index 1d75d1a..0000000 --- a/src/background/usecases/OperationUseCase.js +++ /dev/null @@ -1,208 +0,0 @@ -import TabPresenter from '../presenters/TabPresenter'; -import ConsoleClient from '../infrastructures/ConsoleClient'; -import * as urls from '../../shared/urls'; - -const ZOOM_SETTINGS = [ - 0.33, 0.50, 0.66, 0.75, 0.80, 0.90, 1.00, - 1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00 -]; - -export default class OperationUseCase { - constructor() { - this.tabPresenter = new TabPresenter(); - this.consoleClient = new ConsoleClient(); - } - - async close(force) { - let tab = await this.tabPresenter.getCurrent(); - if (!force && tab.pinned) { - return; - } - return this.tabPresenter.remove([tab.id]); - } - - async closeRight() { - let tabs = await this.tabPresenter.getAll(); - tabs.sort((t1, t2) => t1.index - t2.index); - let index = tabs.findIndex(t => t.active); - if (index < 0) { - return; - } - for (let i = index + 1; i < tabs.length; ++i) { - let tab = tabs[i]; - if (!tab.pinned) { - this.tabPresenter.remove(tab.id); - } - } - } - - reopen() { - return this.tabPresenter.reopen(); - } - - async selectPrev(count) { - let tabs = await this.tabPresenter.getAll(); - if (tabs.length < 2) { - return; - } - let tab = tabs.find(t => t.active); - if (!tab) { - return; - } - let select = (tab.index - count + tabs.length) % tabs.length; - return this.tabPresenter.select(tabs[select].id); - } - - async selectNext(count) { - let tabs = await this.tabPresenter.getAll(); - if (tabs.length < 2) { - return; - } - let tab = tabs.find(t => t.active); - if (!tab) { - return; - } - let select = (tab.index + count) % tabs.length; - return this.tabPresenter.select(tabs[select].id); - } - - async selectFirst() { - let tabs = await this.tabPresenter.getAll(); - return this.tabPresenter.select(tabs[0].id); - } - - async selectLast() { - let tabs = await this.tabPresenter.getAll(); - return this.tabPresenter.select(tabs[tabs.length - 1].id); - } - - async selectPrevSelected() { - let tabId = await this.tabPresenter.getLastSelectedId(); - if (tabId === null || typeof tabId === 'undefined') { - return; - } - this.tabPresenter.select(tabId); - } - - async reload(cache) { - let tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.reload(tab.id, cache); - } - - async setPinned(pinned) { - let tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.setPinned(tab.id, pinned); - } - - async togglePinned() { - let tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.setPinned(tab.id, !tab.pinned); - } - - async duplicate() { - let tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.duplicate(tab.id); - } - - async openPageSource() { - let tab = await this.tabPresenter.getCurrent(); - let url = 'view-source:' + tab.url; - return this.tabPresenter.create(url); - } - - async zoomIn(tabId) { - let tab = await this.tabPresenter.getCurrent(); - let current = await this.tabPresenter.getZoom(tab.id); - let factor = ZOOM_SETTINGS.find(f => f > current); - if (factor) { - return this.tabPresenter.setZoom(tabId, factor); - } - } - - async zoomOut(tabId) { - let tab = await this.tabPresenter.getCurrent(); - let current = await this.tabPresenter.getZoom(tab.id); - let factor = [].concat(ZOOM_SETTINGS).reverse().find(f => f < current); - if (factor) { - return this.tabPresenter.setZoom(tabId, factor); - } - } - - zoomNutoral(tabId) { - return this.tabPresenter.setZoom(tabId, 1); - } - - async showCommand() { - let tab = await this.tabPresenter.getCurrent(); - return this.consoleClient.showCommand(tab.id, ''); - } - - async showOpenCommand(alter) { - let tab = await this.tabPresenter.getCurrent(); - let command = 'open '; - if (alter) { - command += tab.url; - } - return this.consoleClient.showCommand(tab.id, command); - } - - async showTabopenCommand(alter) { - let tab = await this.tabPresenter.getCurrent(); - let command = 'tabopen '; - if (alter) { - command += tab.url; - } - return this.consoleClient.showCommand(tab.id, command); - } - - async showWinopenCommand(alter) { - let tab = await this.tabPresenter.getCurrent(); - let command = 'winopen '; - if (alter) { - command += tab.url; - } - return this.consoleClient.showCommand(tab.id, command); - } - - async showBufferCommand() { - let tab = await this.tabPresenter.getCurrent(); - let command = 'buffer '; - return this.consoleClient.showCommand(tab.id, command); - } - - async showAddbookmarkCommand(alter) { - let tab = await this.tabPresenter.getCurrent(); - let command = 'addbookmark '; - if (alter) { - command += tab.title; - } - return this.consoleClient.showCommand(tab.id, command); - } - - async findStart() { - let tab = await this.tabPresenter.getCurrent(); - return this.consoleClient.showFind(tab.id); - } - - async hideConsole() { - let tab = await this.tabPresenter.getCurrent(); - return this.consoleClient.hide(tab.id); - } - - async openHome(newTab) { - let tab = await this.tabPresenter.getCurrent(); - let result = await browser.browserSettings.homepageOverride.get({}); - let us = urls.homepageUrls(result.value); - if (us.length === 1 && us[0] === 'about:home') { - // eslint-disable-next-line max-len - throw new Error('Cannot open Firefox Home (about:home) by WebExtensions, set your custom URLs'); - } - if (us.length === 1 && !newTab) { - return this.tabPresenter.open(us[0], tab.id); - } - for (let u of us) { - this.tabPresenter.create(u); - } - } -} - diff --git a/src/background/usecases/TabSelectUseCase.js b/src/background/usecases/TabSelectUseCase.js new file mode 100644 index 0000000..16b3e14 --- /dev/null +++ b/src/background/usecases/TabSelectUseCase.js @@ -0,0 +1,51 @@ +import TabPresenter from '../presenters/TabPresenter'; + +export default class TabSelectUseCase { + constructor() { + this.tabPresenter = new TabPresenter(); + } + + async selectPrev(count) { + let tabs = await this.tabPresenter.getAll(); + if (tabs.length < 2) { + return; + } + let tab = tabs.find(t => t.active); + if (!tab) { + return; + } + let select = (tab.index - count + tabs.length) % tabs.length; + return this.tabPresenter.select(tabs[select].id); + } + + async selectNext(count) { + let tabs = await this.tabPresenter.getAll(); + if (tabs.length < 2) { + return; + } + let tab = tabs.find(t => t.active); + if (!tab) { + return; + } + let select = (tab.index + count) % tabs.length; + return this.tabPresenter.select(tabs[select].id); + } + + async selectFirst() { + let tabs = await this.tabPresenter.getAll(); + return this.tabPresenter.select(tabs[0].id); + } + + async selectLast() { + let tabs = await this.tabPresenter.getAll(); + return this.tabPresenter.select(tabs[tabs.length - 1].id); + } + + async selectPrevSelected() { + let tabId = await this.tabPresenter.getLastSelectedId(); + if (tabId === null || typeof tabId === 'undefined') { + return; + } + this.tabPresenter.select(tabId); + } +} diff --git a/src/background/usecases/TabUseCase.js b/src/background/usecases/TabUseCase.js new file mode 100644 index 0000000..d930842 --- /dev/null +++ b/src/background/usecases/TabUseCase.js @@ -0,0 +1,77 @@ +import TabPresenter from '../presenters/TabPresenter'; +import BrowserSettingRepository from '../repositories/BrowserSettingRepository'; + +export default class TabUseCase { + constructor() { + this.tabPresenter = new TabPresenter(); + this.browserSettingRepository = new BrowserSettingRepository(); + } + + async close(force) { + let tab = await this.tabPresenter.getCurrent(); + if (!force && tab.pinned) { + return; + } + return this.tabPresenter.remove([tab.id]); + } + + async closeRight() { + let tabs = await this.tabPresenter.getAll(); + tabs.sort((t1, t2) => t1.index - t2.index); + let index = tabs.findIndex(t => t.active); + if (index < 0) { + return; + } + for (let i = index + 1; i < tabs.length; ++i) { + let tab = tabs[i]; + if (!tab.pinned) { + this.tabPresenter.remove(tab.id); + } + } + } + + reopen() { + return this.tabPresenter.reopen(); + } + + async reload(cache) { + let tab = await this.tabPresenter.getCurrent(); + return this.tabPresenter.reload(tab.id, cache); + } + + async setPinned(pinned) { + let tab = await this.tabPresenter.getCurrent(); + return this.tabPresenter.setPinned(tab.id, pinned); + } + + async togglePinned() { + let tab = await this.tabPresenter.getCurrent(); + return this.tabPresenter.setPinned(tab.id, !tab.pinned); + } + + async duplicate() { + let tab = await this.tabPresenter.getCurrent(); + return this.tabPresenter.duplicate(tab.id); + } + + async openPageSource() { + let tab = await this.tabPresenter.getCurrent(); + let url = 'view-source:' + tab.url; + return this.tabPresenter.create(url); + } + + async openHome(newTab) { + let tab = await this.tabPresenter.getCurrent(); + let urls = await this.browserSettingRepository.getHomepageUrls(); + if (urls.length === 1 && urls[0] === 'about:home') { + // eslint-disable-next-line max-len + throw new Error('Cannot open Firefox Home (about:home) by WebExtensions, set your custom URLs'); + } + if (urls.length === 1 && !newTab) { + return this.tabPresenter.open(urls[0], tab.id); + } + for (let url of urls) { + this.tabPresenter.create(url); + } + } +} diff --git a/src/background/usecases/ZoomUseCase.js b/src/background/usecases/ZoomUseCase.js new file mode 100644 index 0000000..692d6d9 --- /dev/null +++ b/src/background/usecases/ZoomUseCase.js @@ -0,0 +1,35 @@ +import TabPresenter from '../presenters/TabPresenter'; + +const ZOOM_SETTINGS = [ + 0.33, 0.50, 0.66, 0.75, 0.80, 0.90, 1.00, + 1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00 +]; + +export default class ZoomUseCase { + constructor() { + this.tabPresenter = new TabPresenter(); + } + + async zoomIn(tabId) { + let tab = await this.tabPresenter.getCurrent(); + let current = await this.tabPresenter.getZoom(tab.id); + let factor = ZOOM_SETTINGS.find(f => f > current); + if (factor) { + return this.tabPresenter.setZoom(tabId, factor); + } + } + + async zoomOut(tabId) { + let tab = await this.tabPresenter.getCurrent(); + let current = await this.tabPresenter.getZoom(tab.id); + let factor = [].concat(ZOOM_SETTINGS).reverse().find(f => f < current); + if (factor) { + return this.tabPresenter.setZoom(tabId, factor); + } + } + + zoomNutoral(tabId) { + return this.tabPresenter.setZoom(tabId, 1); + } + +} diff --git a/src/shared/urls.js b/src/shared/urls.js index f7e917d..94b1220 100644 --- a/src/shared/urls.js +++ b/src/shared/urls.js @@ -40,8 +40,4 @@ const normalizeUrl = (url) => { return 'http://' + url; }; -const homepageUrls = (value) => { - return value.split('|').map(normalizeUrl); -}; - -export { searchUrl, normalizeUrl, homepageUrls }; +export { searchUrl, normalizeUrl }; diff --git a/test/shared/urls.test.js b/test/shared/urls.test.js index f004b3d..f2950b6 100644 --- a/test/shared/urls.test.js +++ b/test/shared/urls.test.js @@ -44,14 +44,5 @@ describe("shared/commands/parsers", () => { .to.equal('http://google.com'); }); }); - - describe('#homepageUrls', () => { - it('split urls', () => { - expect(parsers.homepageUrls('https://google.com/')) - .to.deep.equal(['https://google.com/']); - expect(parsers.homepageUrls('yahoo.com|https://i-beam.org/')) - .to.deep.equal(['http://yahoo.com', 'https://i-beam.org/']); - }); - }); }); From 0a1aeb2342d955bd802d05993dd7d0deddeb44c9 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 24 Feb 2019 22:31:39 +0900 Subject: [PATCH 4/5] Ignore about: tabs on broadcast --- src/background/infrastructures/ContentMessageClient.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/background/infrastructures/ContentMessageClient.js b/src/background/infrastructures/ContentMessageClient.js index 7e7e602..0fab5a3 100644 --- a/src/background/infrastructures/ContentMessageClient.js +++ b/src/background/infrastructures/ContentMessageClient.js @@ -4,6 +4,9 @@ export default class ContentMessageClient { async broadcastSettingsChanged() { let tabs = await browser.tabs.query({}); for (let tab of tabs) { + if (tab.url.startsWith('about:')) { + continue; + } browser.tabs.sendMessage(tab.id, { type: messages.SETTINGS_CHANGED, }); From 80a4a347ec92f3e702075e448aba191ad3627cf6 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 24 Feb 2019 22:38:39 +0900 Subject: [PATCH 5/5] Update .eslintrc --- .eslintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc b/.eslintrc index cf11670..0f41e10 100644 --- a/.eslintrc +++ b/.eslintrc @@ -40,6 +40,7 @@ "no-alert": "off", "no-bitwise": "off", "no-console": ["error", { "allow": ["warn", "error"] }], + "no-continue": "off", "no-empty-function": "off", "no-magic-numbers": "off", "no-mixed-operators": "off",