Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
implement set option
Browse files Browse the repository at this point in the history
  • Loading branch information
ueokande committed Jan 11, 2018
1 parent befcff9 commit fad8f96
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/background/actions/command.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import actions from '../actions';
import * as tabs from 'background/tabs';
import * as parsers from 'shared/commands/parsers';
import * as properties from 'shared/settings/properties';

const openCommand = (url) => {
return browser.tabs.query({
Expand Down Expand Up @@ -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) => {
let [name, args] = parsers.parseCommandLine(line);

Expand All @@ -53,6 +68,8 @@ const exec = (line, settings) => {
case 'b':
case 'buffer':
return bufferCommand(args);
case 'set':
return setCommand(args);
case '':
return Promise.resolve();
}
Expand Down
11 changes: 5 additions & 6 deletions src/background/components/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ export default class BackgroundComponent {
return this.store.dispatch(
tabActions.openToTab(message.url, sender.tab), sender);
case messages.CONSOLE_ENTER_COMMAND:
return commandActions.exec(message.text, settings.value).catch((e) => {
return browser.tabs.sendMessage(sender.tab.id, {
type: messages.CONSOLE_SHOW_ERROR,
text: e.message,
});
});
this.store.dispatch(
commandActions.exec(message.text, settings.value),
sender
);
return this.broadcastSettingsChanged();
case messages.SETTINGS_QUERY:
return Promise.resolve(this.store.getState().setting.value);
case messages.CONSOLE_QUERY_COMPLETIONS:
Expand Down

0 comments on commit fad8f96

Please sign in to comment.