diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-04-30 14:00:07 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-02 11:14:19 +0900 |
commit | c60d0e7392fc708e961614d6b756a045de74f458 (patch) | |
tree | 0b9a5fce1879e38a92d5dbb2915779aee0ad22d6 /src/background/usecases/CommandUseCase.js | |
parent | 257162e5b6b4993e1dff0d705ffa6f0d809033eb (diff) |
Rename .js/.jsx to .ts/.tsx
Diffstat (limited to 'src/background/usecases/CommandUseCase.js')
-rw-r--r-- | src/background/usecases/CommandUseCase.js | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/src/background/usecases/CommandUseCase.js b/src/background/usecases/CommandUseCase.js deleted file mode 100644 index 9ec46fe..0000000 --- a/src/background/usecases/CommandUseCase.js +++ /dev/null @@ -1,125 +0,0 @@ -import * as parsers from './parsers'; -import * as urls from '../../shared/urls'; -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 { - constructor() { - this.tabPresenter = new TabPresenter(); - this.windowPresenter = new WindowPresenter(); - this.settingRepository = new SettingRepository(); - this.bookmarkRepository = new BookmarkRepository(); - this.consoleClient = new ConsoleClient(); - - this.contentMessageClient = new ContentMessageClient(); - } - - async open(keywords) { - let url = await this.urlOrSearch(keywords); - return this.tabPresenter.open(url); - } - - async tabopen(keywords) { - let url = await this.urlOrSearch(keywords); - return this.tabPresenter.create(url); - } - - async winopen(keywords) { - let url = await this.urlOrSearch(keywords); - return this.windowPresenter.create(url); - } - - // eslint-disable-next-line max-statements - async buffer(keywords) { - if (keywords.length === 0) { - return; - } - - if (!isNaN(keywords)) { - let tabs = await this.tabPresenter.getAll(); - let index = parseInt(keywords, 10) - 1; - if (index < 0 || tabs.length <= index) { - throw new RangeError(`tab ${index + 1} does not exist`); - } - return this.tabPresenter.select(tabs[index].id); - } else if (keywords.trim() === '%') { - // Select current window - return; - } else if (keywords.trim() === '#') { - // Select last selected window - let lastId = await this.tabPresenter.getLastSelectedId(); - if (typeof lastId === 'undefined' || lastId === null) { - throw new Error('No last selected tab'); - } - return this.tabPresenter.select(lastId); - } - - let current = await this.tabPresenter.getCurrent(); - let tabs = await this.tabPresenter.getByKeyword(keywords); - if (tabs.length === 0) { - throw new RangeError('No matching buffer for ' + keywords); - } - for (let tab of tabs) { - if (tab.index > current.index) { - return this.tabPresenter.select(tab.id); - } - } - return this.tabPresenter.select(tabs[0].id); - } - - async bdelete(force, keywords) { - let excludePinned = !force; - let tabs = await this.tabPresenter.getByKeyword(keywords, excludePinned); - if (tabs.length === 0) { - throw new Error('No matching buffer for ' + keywords); - } else if (tabs.length > 1) { - throw new Error('More than one match for ' + keywords); - } - return this.tabPresenter.remove([tabs[0].id]); - } - - async bdeletes(force, keywords) { - let excludePinned = !force; - let tabs = await this.tabPresenter.getByKeyword(keywords, excludePinned); - let ids = tabs.map(tab => tab.id); - return this.tabPresenter.remove(ids); - } - - async quit() { - let tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.remove([tab.id]); - } - - async quitAll() { - let tabs = await this.tabPresenter.getAll(); - let ids = tabs.map(tab => tab.id); - this.tabPresenter.remove(ids); - } - - async addbookmark(title) { - let tab = await this.tabPresenter.getCurrent(); - let item = await this.bookmarkRepository.create(title, tab.url); - let message = 'Saved current page: ' + item.url; - return this.consoleClient.showInfo(tab.id, message); - } - - async set(keywords) { - if (keywords.length === 0) { - return; - } - let [name, value] = parsers.parseSetOption(keywords, properties.types); - await this.settingRepository.setProperty(name, value); - - return this.contentMessageClient.broadcastSettingsChanged(); - } - - async urlOrSearch(keywords) { - let settings = await this.settingRepository.get(); - return urls.searchUrl(keywords, settings.search); - } -} |