commit
dfeb7e7549
59 changed files with 502 additions and 476 deletions
@ -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); |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
@ -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(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -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(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
import VersionUseCase from '../usecases/VersionUseCase'; |
||||||
|
|
||||||
|
export default class VersionController { |
||||||
|
constructor() { |
||||||
|
this.versionUseCase = new VersionUseCase(); |
||||||
|
} |
||||||
|
|
||||||
|
notifyIfUpdated() { |
||||||
|
this.versionUseCase.notifyIfUpdated(); |
||||||
|
} |
||||||
|
} |
@ -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); |
|
||||||
} |
|
||||||
} |
|
@ -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); |
|
||||||
} |
|
||||||
} |
|
@ -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); |
|
||||||
} |
|
||||||
} |
|
@ -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); |
|
||||||
} |
|
||||||
} |
|
@ -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(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
@ -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(); |
|
||||||
} |
|
||||||
} |
|
@ -1,11 +0,0 @@ |
|||||||
import VersionInteractor from '../usecases/version'; |
|
||||||
|
|
||||||
export default class VersionController { |
|
||||||
constructor() { |
|
||||||
this.versionInteractor = new VersionInteractor(); |
|
||||||
} |
|
||||||
|
|
||||||
notifyIfUpdated() { |
|
||||||
this.versionInteractor.notifyIfUpdated(); |
|
||||||
} |
|
||||||
} |
|
@ -1,11 +1,11 @@ |
|||||||
import messages from '../../shared/messages'; |
import messages from '../../shared/messages'; |
||||||
import CommandController from '../controllers/command'; |
import CommandController from '../controllers/CommandController'; |
||||||
import SettingController from '../controllers/setting'; |
import SettingController from '../controllers/SettingController'; |
||||||
import FindController from '../controllers/find'; |
import FindController from '../controllers/FindController'; |
||||||
import AddonEnabledController from '../controllers/addon-enabled'; |
import AddonEnabledController from '../controllers/AddonEnabledController'; |
||||||
import LinkController from '../controllers/link'; |
import LinkController from '../controllers/LinkController'; |
||||||
import OperationController from '../controllers/operation'; |
import OperationController from '../controllers/OperationController'; |
||||||
import MarkController from '../controllers/mark'; |
import MarkController from '../controllers/MarkController'; |
||||||
|
|
||||||
export default class ContentMessageListener { |
export default class ContentMessageListener { |
||||||
constructor() { |
constructor() { |
@ -1,4 +1,4 @@ |
|||||||
import MemoryStorage from '../infrastructures/memory-storage'; |
import MemoryStorage from '../infrastructures/MemoryStorage'; |
||||||
|
|
||||||
const CURRENT_SELECTED_KEY = 'tabs.current.selected'; |
const CURRENT_SELECTED_KEY = 'tabs.current.selected'; |
||||||
const LAST_SELECTED_KEY = 'tabs.last.selected'; |
const LAST_SELECTED_KEY = 'tabs.last.selected'; |
@ -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); |
||||||
|
} |
||||||
|
} |
@ -1,4 +1,4 @@ |
|||||||
import MemoryStorage from '../infrastructures/memory-storage'; |
import MemoryStorage from '../infrastructures/MemoryStorage'; |
||||||
|
|
||||||
const FIND_KEYWORD_KEY = 'find-keyword'; |
const FIND_KEYWORD_KEY = 'find-keyword'; |
||||||
|
|
@ -1,5 +1,5 @@ |
|||||||
import MemoryStorage from '../infrastructures/memory-storage'; |
import MemoryStorage from '../infrastructures/MemoryStorage'; |
||||||
import GlobalMark from 'background/domains/global-mark'; |
import GlobalMark from '../domains/GlobalMark'; |
||||||
|
|
||||||
const MARK_KEY = 'mark'; |
const MARK_KEY = 'mark'; |
||||||
|
|
@ -1,10 +1,6 @@ |
|||||||
import Setting from '../domains/setting'; |
import Setting from '../domains/Setting'; |
||||||
|
|
||||||
export default class SettingRepository { |
export default class SettingRepository { |
||||||
save(settings) { |
|
||||||
return browser.storage.local.set({ settings: settings.serialize() }); |
|
||||||
} |
|
||||||
|
|
||||||
async load() { |
async load() { |
||||||
let { settings } = await browser.storage.local.get('settings'); |
let { settings } = await browser.storage.local.get('settings'); |
||||||
if (!settings) { |
if (!settings) { |
@ -1,4 +1,4 @@ |
|||||||
import MemoryStorage from '../infrastructures/memory-storage'; |
import MemoryStorage from '../infrastructures/MemoryStorage'; |
||||||
|
|
||||||
const CACHED_SETTING_KEY = 'setting'; |
const CACHED_SETTING_KEY = 'setting'; |
||||||
|
|
@ -1,8 +1,8 @@ |
|||||||
import IndicatorPresenter from '../presenters/indicator'; |
import IndicatorPresenter from '../presenters/IndicatorPresenter'; |
||||||
import TabPresenter from '../presenters/tab'; |
import TabPresenter from '../presenters/TabPresenter'; |
||||||
import ContentMessageClient from '../infrastructures/content-message-client'; |
import ContentMessageClient from '../infrastructures/ContentMessageClient'; |
||||||
|
|
||||||
export default class AddonEnabledInteractor { |
export default class AddonEnabledUseCase { |
||||||
constructor() { |
constructor() { |
||||||
this.indicatorPresentor = new IndicatorPresenter(); |
this.indicatorPresentor = new IndicatorPresenter(); |
||||||
|
|
@ -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); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
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() { |
||||||
|
return this.findRepository.getKeyword(); |
||||||
|
} |
||||||
|
|
||||||
|
setKeyword(keyword) { |
||||||
|
return this.findRepository.setKeyword(keyword); |
||||||
|
} |
||||||
|
|
||||||
|
async findStart() { |
||||||
|
let tab = await this.tabPresenter.getCurrent(); |
||||||
|
return this.consoleClient.showFind(tab.id); |
||||||
|
} |
||||||
|
} |
@ -1,7 +1,7 @@ |
|||||||
import SettingRepository from '../repositories/setting'; |
import SettingRepository from '../repositories/SettingRepository'; |
||||||
import TabPresenter from '../presenters/tab'; |
import TabPresenter from '../presenters/TabPresenter'; |
||||||
|
|
||||||
export default class LinkInteractor { |
export default class LinkUseCase { |
||||||
constructor() { |
constructor() { |
||||||
this.settingRepository = new SettingRepository(); |
this.settingRepository = new SettingRepository(); |
||||||
this.tabPresenter = new TabPresenter(); |
this.tabPresenter = new TabPresenter(); |
@ -1,17 +1,14 @@ |
|||||||
import Setting from '../domains/setting'; |
import Setting from '../domains/Setting'; |
||||||
import PersistentSettingRepository from '../repositories/persistent-setting'; |
// eslint-disable-next-line max-len
|
||||||
import SettingRepository from '../repositories/setting'; |
import PersistentSettingRepository from '../repositories/PersistentSettingRepository'; |
||||||
|
import SettingRepository from '../repositories/SettingRepository'; |
||||||
|
|
||||||
export default class SettingInteractor { |
export default class SettingUseCase { |
||||||
constructor() { |
constructor() { |
||||||
this.persistentSettingRepository = new PersistentSettingRepository(); |
this.persistentSettingRepository = new PersistentSettingRepository(); |
||||||
this.settingRepository = new SettingRepository(); |
this.settingRepository = new SettingRepository(); |
||||||
} |
} |
||||||
|
|
||||||
save(settings) { |
|
||||||
this.persistentSettingRepository.save(settings); |
|
||||||
} |
|
||||||
|
|
||||||
get() { |
get() { |
||||||
return this.settingRepository.get(); |
return this.settingRepository.get(); |
||||||
} |
} |
@ -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); |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,9 +1,9 @@ |
|||||||
import manifest from '../../../manifest.json'; |
import manifest from '../../../manifest.json'; |
||||||
import VersionRepository from '../repositories/version'; |
import VersionRepository from '../repositories/VersionRepository'; |
||||||
import TabPresenter from '../presenters/tab'; |
import TabPresenter from '../presenters/TabPresenter'; |
||||||
import Notifier from '../infrastructures/notifier'; |
import Notifier from '../infrastructures/Notifier'; |
||||||
|
|
||||||
export default class VersionInteractor { |
export default class VersionUseCase { |
||||||
constructor() { |
constructor() { |
||||||
this.versionRepository = new VersionRepository(); |
this.versionRepository = new VersionRepository(); |
||||||
this.tabPresenter = new TabPresenter(); |
this.tabPresenter = new TabPresenter(); |
@ -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); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,15 +0,0 @@ |
|||||||
import FindRepository from '../repositories/find'; |
|
||||||
|
|
||||||
export default class FindInteractor { |
|
||||||
constructor() { |
|
||||||
this.findRepository = new FindRepository(); |
|
||||||
} |
|
||||||
|
|
||||||
getKeyword() { |
|
||||||
return this.findRepository.getKeyword(); |
|
||||||
} |
|
||||||
|
|
||||||
setKeyword(keyword) { |
|
||||||
return this.findRepository.setKeyword(keyword); |
|
||||||
} |
|
||||||
} |
|
@ -1,208 +0,0 @@ |
|||||||
import TabPresenter from '../presenters/tab'; |
|
||||||
import ConsolePresenter from '../presenters/console'; |
|
||||||
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 OperationInteractor { |
|
||||||
constructor() { |
|
||||||
this.tabPresenter = new TabPresenter(); |
|
||||||
this.consolePresenter = new ConsolePresenter(); |
|
||||||
} |
|
||||||
|
|
||||||
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.consolePresenter.showCommand(tab.id, ''); |
|
||||||
} |
|
||||||
|
|
||||||
async showOpenCommand(alter) { |
|
||||||
let tab = await this.tabPresenter.getCurrent(); |
|
||||||
let command = 'open '; |
|
||||||
if (alter) { |
|
||||||
command += tab.url; |
|
||||||
} |
|
||||||
return this.consolePresenter.showCommand(tab.id, command); |
|
||||||
} |
|
||||||
|
|
||||||
async showTabopenCommand(alter) { |
|
||||||
let tab = await this.tabPresenter.getCurrent(); |
|
||||||
let command = 'tabopen '; |
|
||||||
if (alter) { |
|
||||||
command += tab.url; |
|
||||||
} |
|
||||||
return this.consolePresenter.showCommand(tab.id, command); |
|
||||||
} |
|
||||||
|
|
||||||
async showWinopenCommand(alter) { |
|
||||||
let tab = await this.tabPresenter.getCurrent(); |
|
||||||
let command = 'winopen '; |
|
||||||
if (alter) { |
|
||||||
command += tab.url; |
|
||||||
} |
|
||||||
return this.consolePresenter.showCommand(tab.id, command); |
|
||||||
} |
|
||||||
|
|
||||||
async showBufferCommand() { |
|
||||||
let tab = await this.tabPresenter.getCurrent(); |
|
||||||
let command = 'buffer '; |
|
||||||
return this.consolePresenter.showCommand(tab.id, command); |
|
||||||
} |
|
||||||
|
|
||||||
async showAddbookmarkCommand(alter) { |
|
||||||
let tab = await this.tabPresenter.getCurrent(); |
|
||||||
let command = 'addbookmark '; |
|
||||||
if (alter) { |
|
||||||
command += tab.title; |
|
||||||
} |
|
||||||
return this.consolePresenter.showCommand(tab.id, command); |
|
||||||
} |
|
||||||
|
|
||||||
async findStart() { |
|
||||||
let tab = await this.tabPresenter.getCurrent(); |
|
||||||
return this.consolePresenter.showFind(tab.id); |
|
||||||
} |
|
||||||
|
|
||||||
async hideConsole() { |
|
||||||
let tab = await this.tabPresenter.getCurrent(); |
|
||||||
return this.consolePresenter.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); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
@ -1,4 +1,4 @@ |
|||||||
import GlobalMark from 'background/domains/global-mark'; |
import GlobalMark from 'background/domains/GlobalMark'; |
||||||
|
|
||||||
describe('background/domains/global-mark', () => { |
describe('background/domains/global-mark', () => { |
||||||
describe('constructor and getter', () => { |
describe('constructor and getter', () => { |
@ -1,4 +1,4 @@ |
|||||||
import MemoryStorage from 'background/infrastructures/memory-storage'; |
import MemoryStorage from 'background/infrastructures/MemoryStorage'; |
||||||
|
|
||||||
describe("background/infrastructures/memory-storage", () => { |
describe("background/infrastructures/memory-storage", () => { |
||||||
it('stores values', () => { |
it('stores values', () => { |
@ -1,5 +1,5 @@ |
|||||||
import MarkRepository from 'background/repositories/mark'; |
import MarkRepository from 'background/repositories/MarkRepository'; |
||||||
import GlobalMark from 'background/domains/global-mark'; |
import GlobalMark from 'background/domains/GlobalMark'; |
||||||
|
|
||||||
describe('background/repositories/mark', () => { |
describe('background/repositories/mark', () => { |
||||||
let repository; |
let repository; |
@ -1,4 +1,4 @@ |
|||||||
import VersionRepository from 'background/repositories/version'; |
import VersionRepository from 'background/repositories/Version'; |
||||||
|
|
||||||
describe("background/repositories/version", () => { |
describe("background/repositories/version", () => { |
||||||
let versionRepository; |
let versionRepository; |
Reference in new issue