move background

jh-changes
Shin'ya Ueoka 7 years ago
parent 58123210ab
commit d886d7de29
  1. 50
      src/actions/operation.js
  2. 0
      src/background/actions/index.js
  3. 52
      src/background/actions/operation.js
  4. 0
      src/background/actions/tab.js
  5. 10
      src/background/components/background.js
  6. 4
      src/background/index.js
  7. 22
      test/settings/reducers/setting.test.js

@ -1,18 +1,9 @@
import operations from 'shared/operations';
import messages from 'shared/messages';
import * as tabs from 'background/tabs';
import * as zooms from 'background/zooms';
import * as scrolls from 'content/scrolls';
import * as navigates from 'content/navigates';
import * as followActions from 'actions/follow';
const sendConsoleShowCommand = (tab, command) => {
return browser.tabs.sendMessage(tab.id, {
type: messages.CONSOLE_SHOW_COMMAND,
command,
});
};
const exec = (operation) => {
switch (operation.type) {
case operations.SCROLL_LINES:
@ -49,43 +40,4 @@ const exec = (operation) => {
}
};
const execBackground = (operation, tab) => {
switch (operation.type) {
case operations.TAB_CLOSE:
return tabs.closeTab(tab.id);
case operations.TAB_REOPEN:
return tabs.reopenTab();
case operations.TAB_PREV:
return tabs.selectPrevTab(tab.index, operation.count);
case operations.TAB_NEXT:
return tabs.selectNextTab(tab.index, operation.count);
case operations.TAB_RELOAD:
return tabs.reload(tab, operation.cache);
case operations.ZOOM_IN:
return zooms.zoomIn();
case operations.ZOOM_OUT:
return zooms.zoomOut();
case operations.ZOOM_NEUTRAL:
return zooms.neutral();
case operations.COMMAND_SHOW:
return sendConsoleShowCommand(tab, '');
case operations.COMMAND_SHOW_OPEN:
if (operation.alter) {
// alter url
return sendConsoleShowCommand(tab, 'open ' + tab.url);
}
return sendConsoleShowCommand(tab, 'open ');
case operations.COMMAND_SHOW_TABOPEN:
if (operation.alter) {
// alter url
return sendConsoleShowCommand(tab, 'tabopen ' + tab.url);
}
return sendConsoleShowCommand(tab, 'tabopen ');
case operations.COMMAND_SHOW_BUFFER:
return sendConsoleShowCommand(tab, 'buffer ');
default:
return Promise.resolve();
}
};
export { exec, execBackground };
export { exec };

@ -0,0 +1,52 @@
import operations from 'shared/operations';
import messages from 'shared/messages';
import * as tabs from 'background/tabs';
import * as zooms from 'background/zooms';
const sendConsoleShowCommand = (tab, command) => {
return browser.tabs.sendMessage(tab.id, {
type: messages.CONSOLE_SHOW_COMMAND,
command,
});
};
const exec = (operation, tab) => {
switch (operation.type) {
case operations.TAB_CLOSE:
return tabs.closeTab(tab.id);
case operations.TAB_REOPEN:
return tabs.reopenTab();
case operations.TAB_PREV:
return tabs.selectPrevTab(tab.index, operation.count);
case operations.TAB_NEXT:
return tabs.selectNextTab(tab.index, operation.count);
case operations.TAB_RELOAD:
return tabs.reload(tab, operation.cache);
case operations.ZOOM_IN:
return zooms.zoomIn();
case operations.ZOOM_OUT:
return zooms.zoomOut();
case operations.ZOOM_NEUTRAL:
return zooms.neutral();
case operations.COMMAND_SHOW:
return sendConsoleShowCommand(tab, '');
case operations.COMMAND_SHOW_OPEN:
if (operation.alter) {
// alter url
return sendConsoleShowCommand(tab, 'open ' + tab.url);
}
return sendConsoleShowCommand(tab, 'open ');
case operations.COMMAND_SHOW_TABOPEN:
if (operation.alter) {
// alter url
return sendConsoleShowCommand(tab, 'tabopen ' + tab.url);
}
return sendConsoleShowCommand(tab, 'tabopen ');
case operations.COMMAND_SHOW_BUFFER:
return sendConsoleShowCommand(tab, 'buffer ');
default:
return Promise.resolve();
}
};
export { exec };

@ -1,7 +1,7 @@
import messages from 'shared/messages';
import * as operationActions from 'actions/operation';
import * as operationActions from 'background/actions/operation';
import * as settingsActions from 'settings/actions/setting';
import * as tabActions from 'actions/tab';
import * as tabActions from 'background/actions/tab';
import * as commands from 'shared/commands';
export default class BackgroundComponent {
@ -23,7 +23,7 @@ export default class BackgroundComponent {
update() {
let state = this.store.getState();
this.updateSettings(state.setting);
this.updateSettings(state);
}
updateSettings(setting) {
@ -37,7 +37,7 @@ export default class BackgroundComponent {
switch (message.type) {
case messages.BACKGROUND_OPERATION:
return this.store.dispatch(
operationActions.execBackground(message.operation, sender.tab),
operationActions.exec(message.operation, sender.tab),
sender);
case messages.OPEN_URL:
if (message.newTab) {
@ -58,7 +58,7 @@ export default class BackgroundComponent {
});
});
case messages.SETTINGS_QUERY:
return Promise.resolve(this.store.getState().setting.settings);
return Promise.resolve(this.store.getState().settings);
case messages.CONSOLE_QUERY_COMPLETIONS:
return commands.complete(message.text, this.settings);
case messages.SETTINGS_RELOAD:

@ -1,7 +1,7 @@
import * as settingsActions from 'settings/actions/setting';
import messages from 'shared/messages';
import BackgroundComponent from 'components/background';
import reducers from 'reducers';
import BackgroundComponent from 'background/components/background';
import reducers from 'settings/reducers/setting';
import { createStore } from 'store';
const store = createStore(reducers, (e, sender) => {

@ -0,0 +1,22 @@
import { expect } from "chai";
import actions from 'settings/actions';
import settingReducer from 'settings/reducers/setting';
describe("setting reducer", () => {
it('return the initial state', () => {
let state = settingReducer(undefined, {});
expect(state).to.have.deep.property('settings', {});
});
it('return next state for SETTING_SET_SETTINGS', () => {
let action = {
type: actions.SETTING_SET_SETTINGS,
settings: { value1: 'hello', value2: 'world' },
};
let state = settingReducer(undefined, action);
expect(state).to.have.deep.property('settings', {
value1: 'hello',
value2: 'world',
});
});
});