From 98bc2326eeeb5d915706dee9aadc2ac3e9af1789 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 6 May 2018 11:45:07 +0900 Subject: [PATCH] Refactor background directories --- src/background/actions/command.js | 2 +- src/background/components/background.js | 4 ++-- src/background/components/operation.js | 4 ++-- src/background/{ => shared/completions}/histories.js | 0 .../shared/completions/index.js} | 6 +++--- src/background/shared/completions/tabs.js | 10 ++++++++++ src/background/{ => shared}/tabs.js | 11 +---------- src/background/{ => shared}/zooms.js | 0 src/shared/commands/index.js | 3 --- 9 files changed, 19 insertions(+), 21 deletions(-) rename src/background/{ => shared/completions}/histories.js (100%) rename src/{shared/commands/complete.js => background/shared/completions/index.js} (94%) create mode 100644 src/background/shared/completions/tabs.js rename src/background/{ => shared}/tabs.js (91%) rename src/background/{ => shared}/zooms.js (100%) delete mode 100644 src/shared/commands/index.js diff --git a/src/background/actions/command.js b/src/background/actions/command.js index 4c52bca..2f7305a 100644 --- a/src/background/actions/command.js +++ b/src/background/actions/command.js @@ -1,5 +1,5 @@ import actions from '../actions'; -import * as tabs from 'background/tabs'; +import * as tabs from '../shared/tabs'; import * as parsers from 'shared/commands/parsers'; import * as properties from 'shared/settings/properties'; diff --git a/src/background/components/background.js b/src/background/components/background.js index 81d815b..e13424b 100644 --- a/src/background/components/background.js +++ b/src/background/components/background.js @@ -3,7 +3,7 @@ import * as commandActions from 'background/actions/command'; import * as settingActions from 'background/actions/setting'; import * as findActions from 'background/actions/find'; import * as tabActions from 'background/actions/tab'; -import * as commands from 'shared/commands'; +import * as completions from '../shared/completions'; export default class BackgroundComponent { constructor(store) { @@ -44,7 +44,7 @@ export default class BackgroundComponent { case messages.SETTINGS_QUERY: return Promise.resolve(this.store.getState().setting.value); case messages.CONSOLE_QUERY_COMPLETIONS: - return commands.complete(message.text, settings.value); + return completions.complete(message.text, settings.value); case messages.SETTINGS_RELOAD: this.store.dispatch(settingActions.load()); return this.broadcastSettingsChanged(); diff --git a/src/background/components/operation.js b/src/background/components/operation.js index e1094c5..b9581c9 100644 --- a/src/background/components/operation.js +++ b/src/background/components/operation.js @@ -1,7 +1,7 @@ import messages from 'shared/messages'; import operations from 'shared/operations'; -import * as tabs from 'background/tabs'; -import * as zooms from 'background/zooms'; +import * as tabs from '../shared//tabs'; +import * as zooms from '../shared/zooms'; export default class BackgroundComponent { constructor(store) { diff --git a/src/background/histories.js b/src/background/shared/completions/histories.js similarity index 100% rename from src/background/histories.js rename to src/background/shared/completions/histories.js diff --git a/src/shared/commands/complete.js b/src/background/shared/completions/index.js similarity index 94% rename from src/shared/commands/complete.js rename to src/background/shared/completions/index.js index 0bdbab8..73b7b27 100644 --- a/src/shared/commands/complete.js +++ b/src/background/shared/completions/index.js @@ -1,5 +1,5 @@ -import * as tabs from 'background/tabs'; -import * as histories from 'background/histories'; +import * as tabs from './tabs'; +import * as histories from './histories'; const getOpenCompletions = (command, keywords, searchConfig) => { return histories.getCompletions(keywords).then((pages) => { @@ -81,4 +81,4 @@ const complete = (line, settings) => { return getCompletions(line, settings); }; -export default complete; +export { complete }; diff --git a/src/background/shared/completions/tabs.js b/src/background/shared/completions/tabs.js new file mode 100644 index 0000000..5edddca --- /dev/null +++ b/src/background/shared/completions/tabs.js @@ -0,0 +1,10 @@ +const getCompletions = (keyword) => { + return browser.tabs.query({ currentWindow: true }).then((tabs) => { + let matched = tabs.filter((t) => { + return t.url.includes(keyword) || t.title && t.title.includes(keyword); + }); + return matched; + }); +}; + +export { getCompletions }; diff --git a/src/background/tabs.js b/src/background/shared/tabs.js similarity index 91% rename from src/background/tabs.js rename to src/background/shared/tabs.js index e939870..277afb2 100644 --- a/src/background/tabs.js +++ b/src/background/shared/tabs.js @@ -66,15 +66,6 @@ const selectByKeyword = (current, keyword) => { }); }; -const getCompletions = (keyword) => { - return browser.tabs.query({ currentWindow: true }).then((tabs) => { - let matched = tabs.filter((t) => { - return t.url.includes(keyword) || t.title && t.title.includes(keyword); - }); - return matched; - }); -}; - const selectPrevTab = (current, count) => { return browser.tabs.query({ currentWindow: true }).then((tabs) => { if (tabs.length < 2) { @@ -139,7 +130,7 @@ const duplicate = (id) => { export { closeTab, closeTabForce, reopenTab, selectAt, selectByKeyword, - getCompletions, selectPrevTab, selectNextTab, selectFirstTab, + selectPrevTab, selectNextTab, selectFirstTab, selectLastTab, selectPrevSelTab, reload, updateTabPinned, toggleTabPinned, duplicate }; diff --git a/src/background/zooms.js b/src/background/shared/zooms.js similarity index 100% rename from src/background/zooms.js rename to src/background/shared/zooms.js diff --git a/src/shared/commands/index.js b/src/shared/commands/index.js deleted file mode 100644 index 78cb4df..0000000 --- a/src/shared/commands/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import complete from './complete'; - -export { complete };