diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-02-24 22:45:47 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-24 22:45:47 +0900 |
commit | dfeb7e75498384af5e24255ee0fe7f8af37ac489 (patch) | |
tree | 12094b3a72d20d07c4cb040c37849c4680fd222b /src/background/controllers | |
parent | 83684a78e6e54b1e15bd4280553e28eb1d21df09 (diff) | |
parent | 80a4a347ec92f3e702075e448aba191ad3627cf6 (diff) |
Merge pull request #544 from ueokande/refactor-background
Refactor background
Diffstat (limited to 'src/background/controllers')
-rw-r--r-- | src/background/controllers/AddonEnabledController.js | 11 | ||||
-rw-r--r-- | src/background/controllers/CommandController.js (renamed from src/background/controllers/command.js) | 22 | ||||
-rw-r--r-- | src/background/controllers/FindController.js | 15 | ||||
-rw-r--r-- | src/background/controllers/LinkController.js | 15 | ||||
-rw-r--r-- | src/background/controllers/MarkController.js | 15 | ||||
-rw-r--r-- | src/background/controllers/OperationController.js | 77 | ||||
-rw-r--r-- | src/background/controllers/SettingController.js | 18 | ||||
-rw-r--r-- | src/background/controllers/VersionController.js | 11 | ||||
-rw-r--r-- | src/background/controllers/addon-enabled.js | 11 | ||||
-rw-r--r-- | src/background/controllers/find.js | 15 | ||||
-rw-r--r-- | src/background/controllers/link.js | 15 | ||||
-rw-r--r-- | src/background/controllers/mark.js | 15 | ||||
-rw-r--r-- | src/background/controllers/operation.js | 69 | ||||
-rw-r--r-- | src/background/controllers/setting.js | 18 | ||||
-rw-r--r-- | src/background/controllers/version.js | 11 |
15 files changed, 173 insertions, 165 deletions
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 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..416aa9c --- /dev/null +++ b/src/background/controllers/OperationController.js @@ -0,0 +1,77 @@ +import operations from '../../shared/operations'; +import FindUseCase from '../usecases/FindUseCase'; +import ConsoleUseCase from '../usecases/ConsoleUseCase'; +import TabUseCase from '../usecases/TabUseCase'; +import TabSelectUseCase from '../usecases/TabSelectUseCase'; +import ZoomUseCase from '../usecases/ZoomUseCase'; + +export default class OperationController { + constructor() { + this.findUseCase = new FindUseCase(); + this.consoleUseCase = new ConsoleUseCase(); + this.tabUseCase = new TabUseCase(); + this.tabSelectUseCase = new TabSelectUseCase(); + this.zoomUseCase = new ZoomUseCase(); + } + + // eslint-disable-next-line complexity, max-lines-per-function + exec(operation) { + switch (operation.type) { + case operations.TAB_CLOSE: + return this.tabUseCase.close(false); + case operations.TAB_CLOSE_RIGHT: + return this.tabUseCase.closeRight(); + case operations.TAB_CLOSE_FORCE: + return this.tabUseCase.close(true); + case operations.TAB_REOPEN: + return this.tabUseCase.reopen(); + case operations.TAB_PREV: + return this.tabSelectUseCase.selectPrev(1); + case operations.TAB_NEXT: + return this.tabSelectUseCase.selectNext(1); + case operations.TAB_FIRST: + return this.tabSelectUseCase.selectFirst(); + case operations.TAB_LAST: + return this.tabSelectUseCase.selectLast(); + case operations.TAB_PREV_SEL: + return this.tabSelectUseCase.selectPrevSelected(); + case operations.TAB_RELOAD: + return this.tabUseCase.reload(operation.cache); + case operations.TAB_PIN: + return this.tabUseCase.setPinned(true); + case operations.TAB_UNPIN: + return this.tabUseCase.setPinned(false); + case operations.TAB_TOGGLE_PINNED: + return this.tabUseCase.togglePinned(); + case operations.TAB_DUPLICATE: + return this.tabUseCase.duplicate(); + case operations.PAGE_SOURCE: + return this.tabUseCase.openPageSource(); + case operations.PAGE_HOME: + return this.tabUseCase.openHome(operation.newTab); + case operations.ZOOM_IN: + return this.zoomUseCase.zoomIn(); + case operations.ZOOM_OUT: + return this.zoomUseCase.zoomOut(); + case operations.ZOOM_NEUTRAL: + return this.zoomUseCase.zoomNutoral(); + case operations.COMMAND_SHOW: + return this.consoleUseCase.showCommand(); + case operations.COMMAND_SHOW_OPEN: + return this.consoleUseCase.showOpenCommand(operation.alter); + case operations.COMMAND_SHOW_TABOPEN: + return this.consoleUseCase.showTabopenCommand(operation.alter); + case operations.COMMAND_SHOW_WINOPEN: + return this.consoleUseCase.showWinopenCommand(operation.alter); + case operations.COMMAND_SHOW_BUFFER: + return this.consoleUseCase.showBufferCommand(); + case operations.COMMAND_SHOW_ADDBOOKMARK: + return this.consoleUseCase.showAddbookmarkCommand(operation.alter); + case operations.FIND_START: + return this.findUseCase.findStart(); + case operations.CANCEL: + return this.consoleUseCase.hideConsole(); + } + } +} + 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(); - } -} |