aboutsummaryrefslogtreecommitdiff
path: root/src/background/actions/command.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-07-13 22:36:56 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-07-13 22:36:56 +0900
commit944dea59199fa03f77e0e7c0d3c02acf8ccb458f (patch)
tree5f44471cdb32376a8c93e6f6eba738180f08c96f /src/background/actions/command.js
parent77b4e807e2a8b3e7ddb5f042719a34962a31b1c4 (diff)
parent28bfa3ac8124d3453cd539db26da4f4703e783df (diff)
Merge remote-tracking branch 'origin/master' into greenkeeper/css-loader-1.0.0
Diffstat (limited to 'src/background/actions/command.js')
-rw-r--r--src/background/actions/command.js68
1 files changed, 41 insertions, 27 deletions
diff --git a/src/background/actions/command.js b/src/background/actions/command.js
index fb8ff98..a7f619b 100644
--- a/src/background/actions/command.js
+++ b/src/background/actions/command.js
@@ -1,5 +1,5 @@
-import messages from 'shared/messages';
import actions from '../actions';
+import * as consoleActions from './console';
import * as tabs from '../shared/tabs';
import * as bookmarks from '../shared/bookmarks';
import * as parsers from 'shared/commands/parsers';
@@ -39,7 +39,7 @@ const winopenCommand = (url) => {
const bufferCommand = async(keywords) => {
if (keywords.length === 0) {
- return Promise.resolve([]);
+ return;
}
let keywordsStr = keywords.join(' ');
let got = await browser.tabs.query({
@@ -57,24 +57,18 @@ const bufferCommand = async(keywords) => {
const addbookmarkCommand = async(tab, args) => {
if (!args[0]) {
- return;
+ return { type: '' };
}
let item = await bookmarks.create(args.join(' '), tab.url);
if (!item) {
- return browser.tabs.sendMessage(tab.id, {
- type: messages.CONSOLE_SHOW_ERROR,
- text: 'Could not create a bookmark',
- });
+ return consoleActions.error(tab, 'Could not create a bookmark');
}
- return browser.tabs.sendMessage(tab.id, {
- type: messages.CONSOLE_SHOW_INFO,
- text: 'Saved current page: ' + item.url,
- });
+ return consoleActions.info(tab, 'Saved current page: ' + item.url);
};
const setCommand = (args) => {
if (!args[0]) {
- return Promise.resolve();
+ return { type: '' };
}
let [name, value] = parsers.parseSetOption(args[0], properties.types);
@@ -85,49 +79,69 @@ const setCommand = (args) => {
};
};
-// eslint-disable-next-line complexity
-const exec = (tab, line, settings) => {
+// eslint-disable-next-line complexity, max-lines-per-function
+const doExec = async(tab, line, settings) => {
let [name, args] = parsers.parseCommandLine(line);
switch (name) {
case 'o':
case 'open':
- return openCommand(parsers.normalizeUrl(args, settings.search));
+ await openCommand(parsers.normalizeUrl(args, settings.search));
+ break;
case 't':
case 'tabopen':
- return tabopenCommand(parsers.normalizeUrl(args, settings.search));
+ await tabopenCommand(parsers.normalizeUrl(args, settings.search));
+ break;
case 'w':
case 'winopen':
- return winopenCommand(parsers.normalizeUrl(args, settings.search));
+ await winopenCommand(parsers.normalizeUrl(args, settings.search));
+ break;
case 'b':
case 'buffer':
- return bufferCommand(args);
+ await bufferCommand(args);
+ break;
case 'bd':
case 'bdel':
case 'bdelete':
- return tabs.closeTabByKeywords(args.join(' '));
+ await tabs.closeTabByKeywords(args.join(' '));
+ break;
case 'bd!':
case 'bdel!':
case 'bdelete!':
- return tabs.closeTabByKeywordsForce(args.join(' '));
+ await tabs.closeTabByKeywordsForce(args.join(' '));
+ break;
case 'bdeletes':
- return tabs.closeTabsByKeywords(args.join(' '));
+ await tabs.closeTabsByKeywords(args.join(' '));
+ break;
case 'bdeletes!':
- return tabs.closeTabsByKeywordsForce(args.join(' '));
+ await tabs.closeTabsByKeywordsForce(args.join(' '));
+ break;
case 'addbookmark':
return addbookmarkCommand(tab, args);
case 'set':
return setCommand(args);
case 'q':
case 'quit':
- return tabcloseCommand();
+ await tabcloseCommand();
+ break;
case 'qa':
case 'quitall':
- return tabcloseAllCommand()
- case '':
- return Promise.resolve();
+ await tabcloseAllCommand();
+ break;
+ default:
+ return consoleActions.error(tab, name + ' command is not defined');
+ }
+ return { type: '' };
+};
+
+// eslint-disable-next-line complexity
+const exec = async(tab, line, settings) => {
+ try {
+ let action = await doExec(tab, line, settings);
+ return action;
+ } catch (e) {
+ return consoleActions.error(tab, e.toString());
}
- throw new Error(name + ' command is not defined');
};
export { exec };