aboutsummaryrefslogtreecommitdiff
path: root/src/background/actions
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/actions')
-rw-r--r--src/background/actions/command.js68
-rw-r--r--src/background/actions/console.js41
-rw-r--r--src/background/actions/tab.js11
3 files changed, 89 insertions, 31 deletions
diff --git a/src/background/actions/command.js b/src/background/actions/command.js
index af7c546..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 };
diff --git a/src/background/actions/console.js b/src/background/actions/console.js
new file mode 100644
index 0000000..d385b2d
--- /dev/null
+++ b/src/background/actions/console.js
@@ -0,0 +1,41 @@
+import messages from 'shared/messages';
+
+const error = async(tab, text) => {
+ await browser.tabs.sendMessage(tab.id, {
+ type: messages.CONSOLE_SHOW_ERROR,
+ text,
+ });
+ return { type: '' };
+};
+
+const info = async(tab, text) => {
+ await browser.tabs.sendMessage(tab.id, {
+ type: messages.CONSOLE_SHOW_INFO,
+ text,
+ });
+ return { type: '' };
+};
+
+const showCommand = async(tab, command) => {
+ await browser.tabs.sendMessage(tab.id, {
+ type: messages.CONSOLE_SHOW_COMMAND,
+ command,
+ });
+ return { type: '' };
+};
+
+const showFind = async(tab) => {
+ await browser.tabs.sendMessage(tab.id, {
+ type: messages.CONSOLE_SHOW_FIND
+ });
+ return { type: '' };
+};
+
+const hide = async(tab) => {
+ await browser.tabs.sendMessage(tab.id, {
+ type: messages.CONSOLE_HIDE,
+ });
+ return { type: '' };
+};
+
+export { error, info, showCommand, showFind, hide };
diff --git a/src/background/actions/tab.js b/src/background/actions/tab.js
index 5cf1e8c..0f32a90 100644
--- a/src/background/actions/tab.js
+++ b/src/background/actions/tab.js
@@ -4,21 +4,24 @@ const openNewTab = async(
url, openerTabId, background = false, adjacent = false
) => {
if (!adjacent) {
- return browser.tabs.create({ url, active: !background });
+ await browser.tabs.create({ url, active: !background });
+ return { type: '' };
}
let tabs = await browser.tabs.query({
active: true, currentWindow: true
});
- return browser.tabs.create({
+ await browser.tabs.create({
url,
openerTabId,
active: !background,
index: tabs[0].index + 1
});
+ return { type: '' };
};
-const openToTab = (url, tab) => {
- return browser.tabs.update(tab.id, { url: url });
+const openToTab = async(url, tab) => {
+ await browser.tabs.update(tab.id, { url: url });
+ return { type: '' };
};
const selected = (tabId) => {