console command actions without store

jh-changes
Shin'ya Ueoka 7 years ago
parent 32168a94e0
commit 10ad62e606
  1. 12
      src/components/background.js
  2. 6
      src/components/console.js
  3. 2
      src/content/messages.js
  4. 1
      src/pages/console.js
  5. 8
      src/shared/commands.js

@ -1,9 +1,9 @@
import messages from 'content/messages'; import messages from 'content/messages';
import * as commandActions from 'actions/command';
import * as consoleActions from 'actions/console'; import * as consoleActions from 'actions/console';
import * as inputActions from 'actions/input'; import * as inputActions from 'actions/input';
import * as settingsActions from 'actions/setting'; import * as settingsActions from 'actions/setting';
import * as tabActions from 'actions/tab'; import * as tabActions from 'actions/tab';
import * as commands from 'shared/commands';
export default class BackgroundComponent { export default class BackgroundComponent {
constructor(store) { constructor(store) {
@ -12,7 +12,7 @@ export default class BackgroundComponent {
browser.runtime.onMessage.addListener((message, sender) => { browser.runtime.onMessage.addListener((message, sender) => {
try { try {
this.onMessage(message, sender); return this.onMessage(message, sender);
} catch (e) { } catch (e) {
this.store.dispatch(consoleActions.showError(e.message), sender); this.store.dispatch(consoleActions.showError(e.message), sender);
} }
@ -47,11 +47,9 @@ export default class BackgroundComponent {
return this.store.dispatch( return this.store.dispatch(
consoleActions.hide(), sender); consoleActions.hide(), sender);
case messages.CONSOLE_ENTERED: case messages.CONSOLE_ENTERED:
return this.store.dispatch( return commands.exec(message.text, this.settings);
commandActions.exec(message.text, this.settings), sender); case messages.CONSOLE_QUERY_COMPLETIONS:
case messages.CONSOLE_CHANGEED: return commands.complete(message.text, this.settings);
return this.store.dispatch(
commandActions.complete(message.text, this.settings), sender);
case messages.SETTINGS_RELOAD: case messages.SETTINGS_RELOAD:
this.store.dispatch(settingsActions.load()); this.store.dispatch(settingsActions.load());
} }

@ -36,7 +36,7 @@ export default class ConsoleComponent {
return browser.runtime.sendMessage({ return browser.runtime.sendMessage({
type: messages.CONSOLE_ENTERED, type: messages.CONSOLE_ENTERED,
text: e.target.value text: e.target.value
}); }).then(this.onBlur);
case KeyboardEvent.DOM_VK_TAB: case KeyboardEvent.DOM_VK_TAB:
if (e.shiftKey) { if (e.shiftKey) {
this.store.dispatch(completionActions.selectPrev()); this.store.dispatch(completionActions.selectPrev());
@ -63,8 +63,10 @@ export default class ConsoleComponent {
this.prevValue = e.target.value; this.prevValue = e.target.value;
return browser.runtime.sendMessage({ return browser.runtime.sendMessage({
type: messages.CONSOLE_CHANGEED, type: messages.CONSOLE_QUERY_COMPLETIONS,
text: e.target.value text: e.target.value
}).then((completions) => {
this.store.dispatch(completionActions.setItems(completions));
}); });
} }

@ -4,7 +4,7 @@ export default {
CONSOLE_BLURRED: 'console.blured', CONSOLE_BLURRED: 'console.blured',
CONSOLE_ENTERED: 'console.entered', CONSOLE_ENTERED: 'console.entered',
CONSOLE_CHANGEED: 'console.changed', CONSOLE_QUERY_COMPLETIONS: 'console.query.completions',
KEYDOWN: 'keydown', KEYDOWN: 'keydown',

@ -39,6 +39,5 @@ browser.runtime.onMessage.addListener((action) => {
if (action.type === messages.STATE_UPDATE) { if (action.type === messages.STATE_UPDATE) {
let state = action.state.console; let state = action.state.console;
consoleComponent.update(state); consoleComponent.update(state);
store.dispatch(completionActions.setItems(state.completions));
} }
}); });

@ -1,6 +1,5 @@
import * as tabs from 'background/tabs'; import * as tabs from 'background/tabs';
import * as histories from 'background/histories'; import * as histories from 'background/histories';
import * as consoleActions from './console';
const normalizeUrl = (string, searchConfig) => { const normalizeUrl = (string, searchConfig) => {
try { try {
@ -132,16 +131,13 @@ const getCompletions = (command, keywords, settings) => {
const exec = (line, settings) => { const exec = (line, settings) => {
let name = line.split(' ')[0]; let name = line.split(' ')[0];
let remaining = line.replace(name + ' ', ''); let remaining = line.replace(name + ' ', '');
return doCommand(name, remaining, settings).then(() => { return doCommand(name, remaining, settings);
return consoleActions.hide();
});
}; };
const complete = (line, settings) => { const complete = (line, settings) => {
let command = line.split(' ', 1)[0]; let command = line.split(' ', 1)[0];
let keywords = line.replace(command + ' ', ''); let keywords = line.replace(command + ' ', '');
return getCompletions(command, keywords, settings) return getCompletions(command, keywords, settings);
.then(consoleActions.setCompletions);
}; };
export { exec, complete }; export { exec, complete };