implement set option

jh-changes
Shin'ya Ueoka 7 years ago
parent befcff973a
commit fad8f96a66
  1. 17
      src/background/actions/command.js
  2. 11
      src/background/components/background.js

@ -1,5 +1,7 @@
import actions from '../actions';
import * as tabs from 'background/tabs'; import * as tabs from 'background/tabs';
import * as parsers from 'shared/commands/parsers'; import * as parsers from 'shared/commands/parsers';
import * as properties from 'shared/settings/properties';
const openCommand = (url) => { const openCommand = (url) => {
return browser.tabs.query({ return browser.tabs.query({
@ -37,6 +39,19 @@ const bufferCommand = (keywords) => {
}); });
}; };
const setCommand = (args) => {
if (!args[0]) {
return Promise.resolve();
}
let [name, value] = parsers.parseSetOption(args[0], properties.types);
return {
type: actions.SETTING_SET_PROPERTY,
name,
value
};
};
const exec = (line, settings) => { const exec = (line, settings) => {
let [name, args] = parsers.parseCommandLine(line); let [name, args] = parsers.parseCommandLine(line);
@ -53,6 +68,8 @@ const exec = (line, settings) => {
case 'b': case 'b':
case 'buffer': case 'buffer':
return bufferCommand(args); return bufferCommand(args);
case 'set':
return setCommand(args);
case '': case '':
return Promise.resolve(); return Promise.resolve();
} }

@ -36,12 +36,11 @@ export default class BackgroundComponent {
return this.store.dispatch( return this.store.dispatch(
tabActions.openToTab(message.url, sender.tab), sender); tabActions.openToTab(message.url, sender.tab), sender);
case messages.CONSOLE_ENTER_COMMAND: case messages.CONSOLE_ENTER_COMMAND:
return commandActions.exec(message.text, settings.value).catch((e) => { this.store.dispatch(
return browser.tabs.sendMessage(sender.tab.id, { commandActions.exec(message.text, settings.value),
type: messages.CONSOLE_SHOW_ERROR, sender
text: e.message, );
}); return this.broadcastSettingsChanged();
});
case messages.SETTINGS_QUERY: case messages.SETTINGS_QUERY:
return Promise.resolve(this.store.getState().setting.value); return Promise.resolve(this.store.getState().setting.value);
case messages.CONSOLE_QUERY_COMPLETIONS: case messages.CONSOLE_QUERY_COMPLETIONS: