From a26d8a8a1bed48a77e062914c120a23ace7bb8cf Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 24 Feb 2019 20:54:35 +0900 Subject: Capitalize background scripts --- .../controllers/AddonEnabledController.js | 11 +++ src/background/controllers/CommandController.js | 99 ++++++++++++++++++++++ src/background/controllers/FindController.js | 15 ++++ src/background/controllers/LinkController.js | 15 ++++ src/background/controllers/MarkController.js | 15 ++++ src/background/controllers/OperationController.js | 69 +++++++++++++++ src/background/controllers/SettingController.js | 18 ++++ src/background/controllers/VersionController.js | 11 +++ src/background/controllers/addon-enabled.js | 11 --- src/background/controllers/command.js | 99 ---------------------- 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 --- 16 files changed, 253 insertions(+), 253 deletions(-) create mode 100644 src/background/controllers/AddonEnabledController.js create mode 100644 src/background/controllers/CommandController.js 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/command.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 (limited to 'src/background/controllers') 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/CommandController.js b/src/background/controllers/CommandController.js new file mode 100644 index 0000000..b113709 --- /dev/null +++ b/src/background/controllers/CommandController.js @@ -0,0 +1,99 @@ +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 + return str.replace(/^\s+/, ''); +}; + +export default class CommandController { + constructor() { + this.completionsUseCase = new CompletionsUseCase(); + this.commandIndicator = new CommandUseCase(); + } + + getCompletions(line) { + let trimmed = trimStart(line); + let words = trimmed.split(/ +/); + let name = words[0]; + if (words.length === 1) { + return this.completionsUseCase.queryConsoleCommand(name); + } + let keywords = trimStart(trimmed.slice(name.length)); + switch (words[0]) { + case 'o': + case 'open': + case 't': + case 'tabopen': + case 'w': + case 'winopen': + return this.completionsUseCase.queryOpen(name, keywords); + case 'b': + case 'buffer': + return this.completionsUseCase.queryBuffer(name, keywords); + case 'bd': + case 'bdel': + case 'bdelete': + case 'bdeletes': + return this.completionsUseCase.queryBdelete(name, keywords); + case 'bd!': + case 'bdel!': + case 'bdelete!': + case 'bdeletes!': + return this.completionsUseCase.queryBdeleteForce(name, keywords); + case 'set': + return this.completionsUseCase.querySet(name, keywords); + } + return Promise.resolve(Completions.empty()); + } + + // eslint-disable-next-line complexity + exec(line) { + let trimmed = trimStart(line); + let words = trimmed.split(/ +/); + let name = words[0]; + if (words[0].length === 0) { + return Promise.resolve(); + } + + let keywords = trimStart(trimmed.slice(name.length)); + switch (words[0]) { + case 'o': + case 'open': + return this.commandIndicator.open(keywords); + case 't': + case 'tabopen': + return this.commandIndicator.tabopen(keywords); + case 'w': + case 'winopen': + return this.commandIndicator.winopen(keywords); + case 'b': + case 'buffer': + return this.commandIndicator.buffer(keywords); + case 'bd': + case 'bdel': + case 'bdelete': + return this.commandIndicator.bdelete(false, keywords); + case 'bd!': + case 'bdel!': + case 'bdelete!': + return this.commandIndicator.bdelete(true, keywords); + case 'bdeletes': + return this.commandIndicator.bdeletes(false, keywords); + case 'bdeletes!': + return this.commandIndicator.bdeletes(true, keywords); + case 'addbookmark': + return this.commandIndicator.addbookmark(keywords); + case 'q': + case 'quit': + return this.commandIndicator.quit(); + case 'qa': + case 'quitall': + return this.commandIndicator.quitAll(); + case 'set': + return this.commandIndicator.set(keywords); + } + throw new Error(words[0] + ' command is not defined'); + } +} 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/command.js b/src/background/controllers/command.js deleted file mode 100644 index 9ab1054..0000000 --- a/src/background/controllers/command.js +++ /dev/null @@ -1,99 +0,0 @@ -import CompletionsInteractor from '../usecases/completions'; -import CommandInteractor from '../usecases/command'; -import Completions from '../domains/completions'; - -const trimStart = (str) => { - // NOTE String.trimStart is available on Firefox 61 - return str.replace(/^\s+/, ''); -}; - -export default class CommandController { - constructor() { - this.completionsInteractor = new CompletionsInteractor(); - this.commandIndicator = new CommandInteractor(); - } - - getCompletions(line) { - let trimmed = trimStart(line); - let words = trimmed.split(/ +/); - let name = words[0]; - if (words.length === 1) { - return this.completionsInteractor.queryConsoleCommand(name); - } - let keywords = trimStart(trimmed.slice(name.length)); - switch (words[0]) { - case 'o': - case 'open': - case 't': - case 'tabopen': - case 'w': - case 'winopen': - return this.completionsInteractor.queryOpen(name, keywords); - case 'b': - case 'buffer': - return this.completionsInteractor.queryBuffer(name, keywords); - case 'bd': - case 'bdel': - case 'bdelete': - case 'bdeletes': - return this.completionsInteractor.queryBdelete(name, keywords); - case 'bd!': - case 'bdel!': - case 'bdelete!': - case 'bdeletes!': - return this.completionsInteractor.queryBdeleteForce(name, keywords); - case 'set': - return this.completionsInteractor.querySet(name, keywords); - } - return Promise.resolve(Completions.empty()); - } - - // eslint-disable-next-line complexity - exec(line) { - let trimmed = trimStart(line); - let words = trimmed.split(/ +/); - let name = words[0]; - if (words[0].length === 0) { - return Promise.resolve(); - } - - let keywords = trimStart(trimmed.slice(name.length)); - switch (words[0]) { - case 'o': - case 'open': - return this.commandIndicator.open(keywords); - case 't': - case 'tabopen': - return this.commandIndicator.tabopen(keywords); - case 'w': - case 'winopen': - return this.commandIndicator.winopen(keywords); - case 'b': - case 'buffer': - return this.commandIndicator.buffer(keywords); - case 'bd': - case 'bdel': - case 'bdelete': - return this.commandIndicator.bdelete(false, keywords); - case 'bd!': - case 'bdel!': - case 'bdelete!': - return this.commandIndicator.bdelete(true, keywords); - case 'bdeletes': - return this.commandIndicator.bdeletes(false, keywords); - case 'bdeletes!': - return this.commandIndicator.bdeletes(true, keywords); - case 'addbookmark': - return this.commandIndicator.addbookmark(keywords); - case 'q': - case 'quit': - return this.commandIndicator.quit(); - case 'qa': - case 'quitall': - return this.commandIndicator.quitAll(); - case 'set': - return this.commandIndicator.set(keywords); - } - throw new Error(words[0] + ' command is not defined'); - } -} 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(); - } -} -- cgit v1.2.3