diff options
Diffstat (limited to 'src/background/controllers')
-rw-r--r-- | src/background/controllers/addon-enabled.js | 11 | ||||
-rw-r--r-- | src/background/controllers/command.js | 94 | ||||
-rw-r--r-- | src/background/controllers/find.js | 15 | ||||
-rw-r--r-- | src/background/controllers/link.js | 15 | ||||
-rw-r--r-- | src/background/controllers/operation.js | 65 | ||||
-rw-r--r-- | src/background/controllers/setting.js | 18 | ||||
-rw-r--r-- | src/background/controllers/version.js | 11 |
7 files changed, 229 insertions, 0 deletions
diff --git a/src/background/controllers/addon-enabled.js b/src/background/controllers/addon-enabled.js new file mode 100644 index 0000000..6a9b776 --- /dev/null +++ b/src/background/controllers/addon-enabled.js @@ -0,0 +1,11 @@ +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 new file mode 100644 index 0000000..befab42 --- /dev/null +++ b/src/background/controllers/command.js @@ -0,0 +1,94 @@ +import CompletionsInteractor from '../usecases/completions'; +import CommandInteractor from '../usecases/command'; +import Completions from '../domains/completions'; + +export default class CommandController { + constructor() { + this.completionsInteractor = new CompletionsInteractor(); + this.commandIndicator = new CommandInteractor(); + } + + getCompletions(line) { + let trimmed = line.trimStart(); + let words = trimmed.split(/ +/); + let name = words[0]; + if (words.length === 1) { + return this.completionsInteractor.queryConsoleCommand(name); + } + let keywords = trimmed.slice(name.length).trimStart(); + 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 = line.trimStart(); + let words = trimmed.split(/ +/); + let name = words[0]; + if (words[0].length === 0) { + return Promise.resolve(); + } + + let keywords = trimmed.slice(name.length).trimStart(); + 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 new file mode 100644 index 0000000..7096014 --- /dev/null +++ b/src/background/controllers/find.js @@ -0,0 +1,15 @@ +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 new file mode 100644 index 0000000..7ebbb34 --- /dev/null +++ b/src/background/controllers/link.js @@ -0,0 +1,15 @@ +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/operation.js b/src/background/controllers/operation.js new file mode 100644 index 0000000..1339006 --- /dev/null +++ b/src/background/controllers/operation.js @@ -0,0 +1,65 @@ +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_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.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 new file mode 100644 index 0000000..9e6019e --- /dev/null +++ b/src/background/controllers/setting.js @@ -0,0 +1,18 @@ +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 new file mode 100644 index 0000000..04d99fe --- /dev/null +++ b/src/background/controllers/version.js @@ -0,0 +1,11 @@ +import VersionInteractor from '../usecases/version'; + +export default class VersionController { + constructor() { + this.versionInteractor = new VersionInteractor(); + } + + notifyIfUpdated() { + this.versionInteractor.notifyIfUpdated(); + } +} |