address feedback 02

This commit is contained in:
Anton Dudakov
2026-02-26 22:01:54 +04:00
parent eda79aaf05
commit 2f6596259b
+26 -27
View File
@@ -12,35 +12,33 @@ const backgroundLogic = {
"about:home",
"about:blank"
]),
// Use shared constants for counts
// NOTE: Keep in sync with MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS
NUMBER_OF_KEYBOARD_SHORTCUTS: MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS,
unhideQueue: [],
init() {
browser.commands.onCommand.addListener(async function (command) {
if (command === "sort_tabs") {
backgroundLogic.sortTabs();
} else if (command.startsWith(MAC_CONSTANTS.OPEN_CONTAINER_PREFIX)) {
for (let i = 0; i < MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
return;
}
for (let i=0; i < backgroundLogic.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
const key = MAC_CONSTANTS.OPEN_CONTAINER_PREFIX + i;
const reopenKey = MAC_CONSTANTS.REOPEN_IN_CONTAINER_PREFIX + i;
const cookieStoreId = identityState.keyboardShortcut[key];
if (cookieStoreId === "none") {
continue;
}
if (command === key) {
if (cookieStoreId !== "none") {
browser.tabs.create({cookieStoreId});
return;
}
break;
}
}
} else if (command.startsWith(MAC_CONSTANTS.REOPEN_IN_CONTAINER_PREFIX)) {
for (let i = 0; i < MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
const key = MAC_CONSTANTS.REOPEN_IN_CONTAINER_PREFIX + i;
const cookieStoreId = identityState.keyboardShortcut[key];
if (command === key) {
if (cookieStoreId !== "none") {
if (command === reopenKey) {
backgroundLogic.reopenInContainer(cookieStoreId);
}
break;
}
return;
}
}
});
@@ -84,7 +82,7 @@ const backgroundLogic = {
},
async reopenInContainer(cookieStoreId) {
const currentTab = await browser.tabs.query({active: true, currentWindow: true});
const currentTab = await browser.tabs.query({ active: true, currentWindow: true })
if (currentTab.length > 0) {
const tab = currentTab[0];
@@ -253,7 +251,7 @@ const backgroundLogic = {
async getTabs(options) {
const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "getTabs");
const {cookieStoreId, windowId} = options;
const { cookieStoreId, windowId } = options;
const list = [];
const tabs = await browser.tabs.query({
@@ -297,7 +295,7 @@ const backgroundLogic = {
async moveTabsToWindow(options) {
const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "moveTabsToWindow");
const {cookieStoreId, windowId} = options;
const { cookieStoreId, windowId } = options;
const list = await browser.tabs.query({
cookieStoreId,
@@ -319,7 +317,7 @@ const backgroundLogic = {
// Pin the default tab in the new window so existing pinned tabs can be moved after it.
// From the docs (https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/move):
// Note that you can't move pinned tabs to a position after any unpinned tabs in a window, or move any unpinned tabs to a position before any pinned tabs.
await browser.tabs.update(newWindowObj.tabs[0].id, {pinned: true});
await browser.tabs.update(newWindowObj.tabs[0].id, { pinned: true });
browser.tabs.move(list.map((tab) => tab.id), {
windowId: newWindowObj.id,
@@ -327,7 +325,8 @@ const backgroundLogic = {
});
} else {
// As we get a blank tab here we will need to await the tabs creation
newWindowObj = await browser.windows.create({});
newWindowObj = await browser.windows.create({
});
hiddenDefaultTabToClose = true;
}
@@ -388,7 +387,7 @@ const backgroundLogic = {
const identities = await browser.contextualIdentities.query({});
const identitiesOutput = {};
const identitiesPromise = identities.map(async (identity) => {
const {cookieStoreId} = identity;
const { cookieStoreId } = identity;
const containerState = await identityState.storageArea.get(cookieStoreId);
const openTabs = await browser.tabs.query({
cookieStoreId,
@@ -447,7 +446,7 @@ const backgroundLogic = {
if (!map.has(tab.cookieStoreId)) {
const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(tab.cookieStoreId);
map.set(tab.cookieStoreId, {order: userContextId, tabs: []});
map.set(tab.cookieStoreId, { order: userContextId, tabs: [] });
}
map.get(tab.cookieStoreId).tabs.push(tab);
}
@@ -466,7 +465,7 @@ const backgroundLogic = {
const sortMap = new Map([...map.entries()].sort((a, b) => a[1].order > b[1].order));
// Let's move tabs.
for (const {tabs} of sortMap.values()) {
for (const { tabs } of sortMap.values()) {
for (const tab of tabs) {
++pos;
browser.tabs.move(tab.id, {
@@ -490,7 +489,7 @@ const backgroundLogic = {
async hideTabs(options) {
const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "hideTabs");
const {cookieStoreId, windowId} = options;
const { cookieStoreId, windowId } = options;
const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(cookieStoreId);
@@ -530,7 +529,7 @@ const backgroundLogic = {
},
cookieStoreId(userContextId) {
if (userContextId === 0) return "firefox-default";
if(userContextId === 0) return "firefox-default";
return `firefox-container-${userContextId}`;
}
};