adds an ability to reopen current tab in the specific container with a shortcut
This commit is contained in:
committed by
Anton Dudakov
parent
02f9ea8ec9
commit
b4d0115d22
@@ -13,9 +13,9 @@ const backgroundLogic = {
|
||||
]),
|
||||
NUMBER_OF_KEYBOARD_SHORTCUTS: 10,
|
||||
unhideQueue: [],
|
||||
init() {
|
||||
|
||||
browser.commands.onCommand.addListener(function (command) {
|
||||
async init() {
|
||||
browser.commands.onCommand.addListener(async function (command) {
|
||||
if (command === "sort_tabs") {
|
||||
backgroundLogic.sortTabs();
|
||||
return;
|
||||
@@ -23,10 +23,33 @@ const backgroundLogic = {
|
||||
|
||||
for (let i=0; i < backgroundLogic.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
|
||||
const key = "open_container_" + i;
|
||||
const reopenKey = "reopen_in_container_" + i;
|
||||
const cookieStoreId = identityState.keyboardShortcut[key];
|
||||
|
||||
if (cookieStoreId === "none") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (command === key) {
|
||||
if (cookieStoreId === "none") return;
|
||||
browser.tabs.create({cookieStoreId});
|
||||
return;
|
||||
}
|
||||
|
||||
if (command === reopenKey) {
|
||||
const currentTab = await browser.tabs.query({active: true, currentWindow: true});
|
||||
if (currentTab.length > 0) {
|
||||
const tab = currentTab[0];
|
||||
|
||||
await browser.tabs.create({
|
||||
url: tab.url,
|
||||
cookieStoreId: cookieStoreId,
|
||||
index: tab.index + 1,
|
||||
active: tab.active
|
||||
});
|
||||
|
||||
await browser.tabs.remove(tab.id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -85,10 +108,14 @@ const backgroundLogic = {
|
||||
|
||||
updateTranslationInManifest() {
|
||||
for (let index = 0; index < 10; index++) {
|
||||
const ajustedIndex = index + 1; // We want to start from 1 instead of 0 in the UI.
|
||||
const adjustedIndex = index + 1;
|
||||
browser.commands.update({
|
||||
name: `open_container_${index}`,
|
||||
description: browser.i18n.getMessage("containerShortcut", `${ajustedIndex}`)
|
||||
description: browser.i18n.getMessage("containerShortcut", `${adjustedIndex}`)
|
||||
});
|
||||
browser.commands.update({
|
||||
name: `reopen_in_container_${index}`,
|
||||
description: browser.i18n.getMessage("reopenInContainerShortcut", `${adjustedIndex}`)
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@@ -109,6 +109,66 @@
|
||||
"default": "Ctrl+Shift+0"
|
||||
},
|
||||
"description": "__MSG_containerShortcut__"
|
||||
},
|
||||
"reopen_in_container_0": {
|
||||
"suggested_key": {
|
||||
"default": "Alt+Shift+1"
|
||||
},
|
||||
"description": "__MSG_reopenInContainerShortcut__"
|
||||
},
|
||||
"reopen_in_container_1": {
|
||||
"suggested_key": {
|
||||
"default": "Alt+Shift+2"
|
||||
},
|
||||
"description": "__MSG_reopenInContainerShortcut__"
|
||||
},
|
||||
"reopen_in_container_2": {
|
||||
"suggested_key": {
|
||||
"default": "Alt+Shift+3"
|
||||
},
|
||||
"description": "__MSG_reopenInContainerShortcut__"
|
||||
},
|
||||
"reopen_in_container_3": {
|
||||
"suggested_key": {
|
||||
"default": "Alt+Shift+4"
|
||||
},
|
||||
"description": "__MSG_reopenInContainerShortcut__"
|
||||
},
|
||||
"reopen_in_container_4": {
|
||||
"suggested_key": {
|
||||
"default": "Alt+Shift+5"
|
||||
},
|
||||
"description": "__MSG_reopenInContainerShortcut__"
|
||||
},
|
||||
"reopen_in_container_5": {
|
||||
"suggested_key": {
|
||||
"default": "Alt+Shift+6"
|
||||
},
|
||||
"description": "__MSG_reopenInContainerShortcut__"
|
||||
},
|
||||
"reopen_in_container_6": {
|
||||
"suggested_key": {
|
||||
"default": "Alt+Shift+7"
|
||||
},
|
||||
"description": "__MSG_reopenInContainerShortcut__"
|
||||
},
|
||||
"reopen_in_container_7": {
|
||||
"suggested_key": {
|
||||
"default": "Alt+Shift+8"
|
||||
},
|
||||
"description": "__MSG_reopenInContainerShortcut__"
|
||||
},
|
||||
"reopen_in_container_8": {
|
||||
"suggested_key": {
|
||||
"default": "Alt+Shift+9"
|
||||
},
|
||||
"description": "__MSG_reopenInContainerShortcut__"
|
||||
},
|
||||
"reopen_in_container_9": {
|
||||
"suggested_key": {
|
||||
"default": "Alt+Shift+0"
|
||||
},
|
||||
"description": "__MSG_reopenInContainerShortcut__"
|
||||
}
|
||||
},
|
||||
"browser_action": {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
const {initializeWithTab} = require("../common");
|
||||
|
||||
describe("Reopen Shortcuts Feature", function () {
|
||||
beforeEach(async function () {
|
||||
// Initialize with a tab in the default container
|
||||
this.webExt = await initializeWithTab({
|
||||
cookieStoreId: "firefox-default",
|
||||
url: "https://example.com"
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
this.webExt.destroy();
|
||||
});
|
||||
|
||||
describe("when using keyboard shortcut to reopen in container", function () {
|
||||
beforeEach(async function () {
|
||||
// Simulate the keyboard shortcut command
|
||||
await this.webExt.background.browser.commands.onCommand.addListener.firstCall.args[0]("reopen_in_container_0");
|
||||
});
|
||||
|
||||
it("should open the page in the assigned container and close the original tab", async function () {
|
||||
this.webExt.background.browser.tabs.create.should.have.been.calledWithMatch({
|
||||
url: "https://example.com",
|
||||
cookieStoreId: "firefox-container-1",
|
||||
index: 1,
|
||||
active: true
|
||||
});
|
||||
|
||||
this.webExt.background.browser.tabs.remove.should.have.been.called;
|
||||
});
|
||||
});
|
||||
|
||||
describe("when container is set to 'none'", function () {
|
||||
beforeEach(async function () {
|
||||
await this.webExt.background.browser.commands.onCommand.addListener.firstCall.args[0]("reopen_in_container_9");
|
||||
});
|
||||
|
||||
it("should not reopen the tab", function () {
|
||||
this.webExt.background.browser.tabs.create.should.not.have.been.called;
|
||||
this.webExt.background.browser.tabs.remove.should.not.have.been.called;
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user