aboutsummaryrefslogtreecommitdiff
path: root/src/background
diff options
context:
space:
mode:
Diffstat (limited to 'src/background')
-rw-r--r--src/background/actions/operation.js20
-rw-r--r--src/background/components/background.js6
-rw-r--r--src/background/tabs.js32
3 files changed, 52 insertions, 6 deletions
diff --git a/src/background/actions/operation.js b/src/background/actions/operation.js
index b94c117..1e4990c 100644
--- a/src/background/actions/operation.js
+++ b/src/background/actions/operation.js
@@ -10,6 +10,9 @@ const sendConsoleShowCommand = (tab, command) => {
});
};
+// This switch statement is only gonna get longer as more
+// features are added, so disable complexity check
+/* eslint-disable complexity */
const exec = (operation, tab) => {
switch (operation.type) {
case operations.TAB_CLOSE:
@@ -20,8 +23,20 @@ const exec = (operation, tab) => {
return tabs.selectPrevTab(tab.index, operation.count);
case operations.TAB_NEXT:
return tabs.selectNextTab(tab.index, operation.count);
+ case operations.TAB_FIRST:
+ return tabs.selectFirstTab();
+ case operations.TAB_LAST:
+ return tabs.selectLastTab();
case operations.TAB_RELOAD:
return tabs.reload(tab, operation.cache);
+ case operations.TAB_PIN:
+ return tabs.updateTabPinned(tab, true);
+ case operations.TAB_UNPIN:
+ return tabs.updateTabPinned(tab, false);
+ case operations.TAB_TOGGLE_PINNED:
+ return tabs.toggleTabPinned(tab);
+ case operations.TAB_DUPLICATE:
+ return tabs.duplicate(tab.id);
case operations.ZOOM_IN:
return zooms.zoomIn();
case operations.ZOOM_OUT:
@@ -50,9 +65,14 @@ const exec = (operation, tab) => {
return sendConsoleShowCommand(tab, 'winopen ');
case operations.COMMAND_SHOW_BUFFER:
return sendConsoleShowCommand(tab, 'buffer ');
+ case operations.FIND_START:
+ return browser.tabs.sendMessage(tab.id, {
+ type: messages.CONSOLE_SHOW_FIND
+ });
default:
return Promise.resolve();
}
};
+/* eslint-enable complexity */
export { exec };
diff --git a/src/background/components/background.js b/src/background/components/background.js
index a5f4f5f..2d94310 100644
--- a/src/background/components/background.js
+++ b/src/background/components/background.js
@@ -34,11 +34,7 @@ export default class BackgroundComponent {
}
return this.store.dispatch(
tabActions.openToTab(message.url, sender.tab), sender);
- case messages.CONSOLE_BLURRED:
- return browser.tabs.sendMessage(sender.tab.id, {
- type: messages.CONSOLE_HIDE_COMMAND,
- });
- case messages.CONSOLE_ENTERED:
+ case messages.CONSOLE_ENTER_COMMAND:
return commands.exec(message.text, settings.value).catch((e) => {
return browser.tabs.sendMessage(sender.tab.id, {
type: messages.CONSOLE_SHOW_ERROR,
diff --git a/src/background/tabs.js b/src/background/tabs.js
index eed3252..d641616 100644
--- a/src/background/tabs.js
+++ b/src/background/tabs.js
@@ -79,6 +79,20 @@ const selectNextTab = (current, count) => {
});
};
+const selectFirstTab = () => {
+ return browser.tabs.query({ currentWindow: true }).then((tabs) => {
+ let id = tabs[0].id;
+ return browser.tabs.update(id, { active: true });
+ });
+};
+
+const selectLastTab = () => {
+ return browser.tabs.query({ currentWindow: true }).then((tabs) => {
+ let id = tabs[tabs.length - 1].id;
+ return browser.tabs.update(id, { active: true });
+ });
+};
+
const reload = (current, cache) => {
return browser.tabs.reload(
current.id,
@@ -86,7 +100,23 @@ const reload = (current, cache) => {
);
};
+const updateTabPinned = (current, pinned) => {
+ return browser.tabs.query({ currentWindow: true, active: true })
+ .then(() => {
+ return browser.tabs.update(current.id, { pinned: pinned });
+ });
+};
+
+const toggleTabPinned = (current) => {
+ updateTabPinned(current, !current.pinned);
+};
+
+const duplicate = (id) => {
+ return browser.tabs.duplicate(id);
+};
+
export {
closeTab, reopenTab, selectAt, selectByKeyword, getCompletions,
- selectPrevTab, selectNextTab, reload
+ selectPrevTab, selectNextTab, selectFirstTab, selectLastTab, reload,
+ updateTabPinned, toggleTabPinned, duplicate
};