aboutsummaryrefslogtreecommitdiff
path: root/src/background/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/components')
-rw-r--r--src/background/components/background.js67
-rw-r--r--src/background/components/indicator.js43
-rw-r--r--src/background/components/operation.js127
-rw-r--r--src/background/components/tab.js16
4 files changed, 0 insertions, 253 deletions
diff --git a/src/background/components/background.js b/src/background/components/background.js
deleted file mode 100644
index c7a79a1..0000000
--- a/src/background/components/background.js
+++ /dev/null
@@ -1,67 +0,0 @@
-import messages from 'shared/messages';
-import * as commandActions from 'background/actions/command';
-import * as settingActions from 'background/actions/setting';
-import * as findActions from 'background/actions/find';
-import * as tabActions from 'background/actions/tab';
-import * as completions from '../shared/completions';
-
-export default class BackgroundComponent {
- constructor(store) {
- this.store = store;
-
- browser.runtime.onMessage.addListener((message, sender) => {
- try {
- return this.onMessage(message, sender);
- } catch (e) {
- return browser.tabs.sendMessage(sender.tab.id, {
- type: messages.CONSOLE_SHOW_ERROR,
- text: e.message,
- });
- }
- });
- }
-
- onMessage(message, sender) {
- let settings = this.store.getState().setting;
- let find = this.store.getState().find;
-
- switch (message.type) {
- case messages.OPEN_URL:
- if (message.newTab) {
- let action = tabActions.openNewTab(
- message.url, sender.tab.id, message.background,
- settings.value.properties.adjacenttab);
- return this.store.dispatch(action, sender);
- }
- return this.store.dispatch(
- tabActions.openToTab(message.url, sender.tab), sender);
- case messages.CONSOLE_ENTER_COMMAND:
- this.store.dispatch(
- commandActions.exec(sender.tab, 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:
- return completions.complete(message.text, settings.value);
- case messages.SETTINGS_RELOAD:
- this.store.dispatch(settingActions.load());
- return this.broadcastSettingsChanged();
- case messages.FIND_GET_KEYWORD:
- return Promise.resolve(find.keyword);
- case messages.FIND_SET_KEYWORD:
- this.store.dispatch(findActions.setKeyword(message.keyword));
- return Promise.resolve({});
- }
- }
-
- async broadcastSettingsChanged() {
- let tabs = await browser.tabs.query({});
- for (let tab of tabs) {
- browser.tabs.sendMessage(tab.id, {
- type: messages.SETTINGS_CHANGED,
- });
- }
- }
-}
diff --git a/src/background/components/indicator.js b/src/background/components/indicator.js
deleted file mode 100644
index 1ded329..0000000
--- a/src/background/components/indicator.js
+++ /dev/null
@@ -1,43 +0,0 @@
-import * as indicators from '../shared/indicators';
-import messages from 'shared/messages';
-
-export default class IndicatorComponent {
- constructor(store) {
- this.store = store;
-
- messages.onMessage(this.onMessage.bind(this));
-
- browser.browserAction.onClicked.addListener(this.onClicked);
- browser.tabs.onActivated.addListener(async(info) => {
- await browser.tabs.query({ currentWindow: true });
- return this.onTabActivated(info);
- });
- }
-
- async onTabActivated(info) {
- let { enabled } = await browser.tabs.sendMessage(info.tabId, {
- type: messages.ADDON_ENABLED_QUERY,
- });
- return this.updateIndicator(enabled);
- }
-
- onClicked(tab) {
- browser.tabs.sendMessage(tab.id, {
- type: messages.ADDON_TOGGLE_ENABLED,
- });
- }
-
- onMessage(message) {
- switch (message.type) {
- case messages.ADDON_ENABLED_RESPONSE:
- return this.updateIndicator(message.enabled);
- }
- }
-
- updateIndicator(enabled) {
- if (enabled) {
- return indicators.enable();
- }
- return indicators.disable();
- }
-}
diff --git a/src/background/components/operation.js b/src/background/components/operation.js
deleted file mode 100644
index ce93270..0000000
--- a/src/background/components/operation.js
+++ /dev/null
@@ -1,127 +0,0 @@
-import messages from 'shared/messages';
-import operations from 'shared/operations';
-import * as tabs from '../shared//tabs';
-import * as zooms from '../shared/zooms';
-import * as consoleActions from '../actions/console';
-
-export default class BackgroundComponent {
- constructor(store) {
- this.store = store;
-
- browser.runtime.onMessage.addListener((message, sender) => {
- try {
- return this.onMessage(message, sender);
- } catch (e) {
- return browser.tabs.sendMessage(sender.tab.id, {
- type: messages.CONSOLE_SHOW_ERROR,
- text: e.message,
- });
- }
- });
- }
-
- onMessage(message, sender) {
- switch (message.type) {
- case messages.BACKGROUND_OPERATION:
- return this.store.dispatch(
- this.exec(message.operation, sender.tab));
- }
- }
-
- // eslint-disable-next-line complexity, max-lines-per-function
- async exec(operation, tab) {
- let tabState = this.store.getState().tab;
-
- switch (operation.type) {
- case operations.TAB_CLOSE:
- await tabs.closeTab(tab.id);
- break;
- case operations.TAB_CLOSE_FORCE:
- await tabs.closeTabForce(tab.id);
- break;
- case operations.TAB_REOPEN:
- await tabs.reopenTab();
- break;
- case operations.TAB_PREV:
- await tabs.selectPrevTab(tab.index, operation.count);
- break;
- case operations.TAB_NEXT:
- await tabs.selectNextTab(tab.index, operation.count);
- break;
- case operations.TAB_FIRST:
- await tabs.selectFirstTab();
- break;
- case operations.TAB_LAST:
- await tabs.selectLastTab();
- break;
- case operations.TAB_PREV_SEL:
- if (tabState.previousSelected > 0) {
- await tabs.selectTab(tabState.previousSelected);
- }
- break;
- case operations.TAB_RELOAD:
- await tabs.reload(tab, operation.cache);
- break;
- case operations.TAB_PIN:
- await tabs.updateTabPinned(tab, true);
- break;
- case operations.TAB_UNPIN:
- await tabs.updateTabPinned(tab, false);
- break;
- case operations.TAB_TOGGLE_PINNED:
- await tabs.toggleTabPinned(tab);
- break;
- case operations.TAB_DUPLICATE:
- await tabs.duplicate(tab.id);
- break;
- case operations.ZOOM_IN:
- await zooms.zoomIn();
- break;
- case operations.ZOOM_OUT:
- await zooms.zoomOut();
- break;
- case operations.ZOOM_NEUTRAL:
- await zooms.neutral();
- break;
- case operations.COMMAND_SHOW:
- return consoleActions.showCommand(tab, '');
- case operations.COMMAND_SHOW_OPEN:
- if (operation.alter) {
- // alter url
- return consoleActions.showCommand(tab, 'open ' + tab.url);
- }
- return consoleActions.showCommand(tab, 'open ');
- case operations.COMMAND_SHOW_TABOPEN:
- if (operation.alter) {
- // alter url
- return consoleActions.showCommand(tab, 'tabopen ' + tab.url);
- }
- return consoleActions.showCommand(tab, 'tabopen ');
- case operations.COMMAND_SHOW_WINOPEN:
- if (operation.alter) {
- // alter url
- return consoleActions.showCommand(tab, 'winopen ' + tab.url);
- }
- return consoleActions.showCommand(tab, 'winopen ');
- case operations.COMMAND_SHOW_BUFFER:
- return consoleActions.showCommand(tab, 'buffer ');
- case operations.COMMAND_SHOW_ADDBOOKMARK:
- if (operation.alter) {
- return consoleActions.showCommand(tab, 'addbookmark ' + tab.title);
- }
- return consoleActions.showCommand(tab, 'addbookmark ');
- case operations.FIND_START:
- return consoleActions.showFind(tab);
- case operations.CANCEL:
- return consoleActions.hide(tab);
- case operations.PAGE_SOURCE:
- await browser.tabs.create({
- url: 'view-source:' + tab.url,
- index: tab.index + 1,
- openerTabId: tab.id,
- });
- break;
- }
- return { type: '' };
- }
-}
diff --git a/src/background/components/tab.js b/src/background/components/tab.js
deleted file mode 100644
index 6af3fd7..0000000
--- a/src/background/components/tab.js
+++ /dev/null
@@ -1,16 +0,0 @@
-import * as tabActions from '../actions/tab';
-
-export default class TabComponent {
- constructor(store) {
- this.store = store;
-
- browser.tabs.onActivated.addListener(async(info) => {
- await browser.tabs.query({ currentWindow: true });
- return this.onTabActivated(info);
- });
- }
-
- onTabActivated(info) {
- return this.store.dispatch(tabActions.selected(info.tabId));
- }
-}