address feedback 02

This commit is contained in:
Anton Dudakov
2026-02-26 22:01:54 +04:00
parent eda79aaf05
commit 2f6596259b
+35 -36
View File
@@ -12,35 +12,33 @@ const backgroundLogic = {
"about:home", "about:home",
"about:blank" "about:blank"
]), ]),
// Use shared constants for counts NUMBER_OF_KEYBOARD_SHORTCUTS: MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS,
// NOTE: Keep in sync with MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS
unhideQueue: [], unhideQueue: [],
init() { init() {
browser.commands.onCommand.addListener(async function (command) { browser.commands.onCommand.addListener(async function (command) {
if (command === "sort_tabs") { if (command === "sort_tabs") {
backgroundLogic.sortTabs(); backgroundLogic.sortTabs();
} else if (command.startsWith(MAC_CONSTANTS.OPEN_CONTAINER_PREFIX)) { return;
for (let i = 0; i < MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) { }
const key = MAC_CONSTANTS.OPEN_CONTAINER_PREFIX + i;
const cookieStoreId = identityState.keyboardShortcut[key]; for (let i=0; i < backgroundLogic.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
if (command === key) { const key = MAC_CONSTANTS.OPEN_CONTAINER_PREFIX + i;
if (cookieStoreId !== "none") { const reopenKey = MAC_CONSTANTS.REOPEN_IN_CONTAINER_PREFIX + i;
browser.tabs.create({cookieStoreId}); const cookieStoreId = identityState.keyboardShortcut[key];
}
break; if (cookieStoreId === "none") {
} continue;
} }
} else if (command.startsWith(MAC_CONSTANTS.REOPEN_IN_CONTAINER_PREFIX)) {
for (let i = 0; i < MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) { if (command === key) {
const key = MAC_CONSTANTS.REOPEN_IN_CONTAINER_PREFIX + i; browser.tabs.create({cookieStoreId});
const cookieStoreId = identityState.keyboardShortcut[key]; return;
if (command === key) { }
if (cookieStoreId !== "none") {
backgroundLogic.reopenInContainer(cookieStoreId); if (command === reopenKey) {
} backgroundLogic.reopenInContainer(cookieStoreId);
break; return;
}
} }
} }
}); });
@@ -84,7 +82,7 @@ const backgroundLogic = {
}, },
async reopenInContainer(cookieStoreId) { 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) { if (currentTab.length > 0) {
const tab = currentTab[0]; const tab = currentTab[0];
@@ -234,9 +232,9 @@ const backgroundLogic = {
const protocol = new URL(url).protocol; const protocol = new URL(url).protocol;
// We can't open these we just have to throw them away // We can't open these we just have to throw them away
if (protocol === "about:" if (protocol === "about:"
|| protocol === "chrome:" || protocol === "chrome:"
|| protocol === "moz-extension:" || protocol === "moz-extension:"
|| protocol === "file:") { || protocol === "file:") {
return false; return false;
} }
return true; return true;
@@ -253,7 +251,7 @@ const backgroundLogic = {
async getTabs(options) { async getTabs(options) {
const requiredArguments = ["cookieStoreId", "windowId"]; const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "getTabs"); this.checkArgs(requiredArguments, options, "getTabs");
const {cookieStoreId, windowId} = options; const { cookieStoreId, windowId } = options;
const list = []; const list = [];
const tabs = await browser.tabs.query({ const tabs = await browser.tabs.query({
@@ -297,7 +295,7 @@ const backgroundLogic = {
async moveTabsToWindow(options) { async moveTabsToWindow(options) {
const requiredArguments = ["cookieStoreId", "windowId"]; const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "moveTabsToWindow"); this.checkArgs(requiredArguments, options, "moveTabsToWindow");
const {cookieStoreId, windowId} = options; const { cookieStoreId, windowId } = options;
const list = await browser.tabs.query({ const list = await browser.tabs.query({
cookieStoreId, cookieStoreId,
@@ -308,7 +306,7 @@ const backgroundLogic = {
// Nothing to do // Nothing to do
if (list.length === 0 && if (list.length === 0 &&
containerState.hiddenTabs.length === 0) { containerState.hiddenTabs.length === 0) {
return; return;
} }
let newWindowObj; let newWindowObj;
@@ -319,7 +317,7 @@ const backgroundLogic = {
// Pin the default tab in the new window so existing pinned tabs can be moved after it. // 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): // 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. // 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), { browser.tabs.move(list.map((tab) => tab.id), {
windowId: newWindowObj.id, windowId: newWindowObj.id,
@@ -327,7 +325,8 @@ const backgroundLogic = {
}); });
} else { } else {
// As we get a blank tab here we will need to await the tabs creation // 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; hiddenDefaultTabToClose = true;
} }
@@ -388,7 +387,7 @@ const backgroundLogic = {
const identities = await browser.contextualIdentities.query({}); const identities = await browser.contextualIdentities.query({});
const identitiesOutput = {}; const identitiesOutput = {};
const identitiesPromise = identities.map(async (identity) => { const identitiesPromise = identities.map(async (identity) => {
const {cookieStoreId} = identity; const { cookieStoreId } = identity;
const containerState = await identityState.storageArea.get(cookieStoreId); const containerState = await identityState.storageArea.get(cookieStoreId);
const openTabs = await browser.tabs.query({ const openTabs = await browser.tabs.query({
cookieStoreId, cookieStoreId,
@@ -447,7 +446,7 @@ const backgroundLogic = {
if (!map.has(tab.cookieStoreId)) { if (!map.has(tab.cookieStoreId)) {
const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(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); 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)); const sortMap = new Map([...map.entries()].sort((a, b) => a[1].order > b[1].order));
// Let's move tabs. // Let's move tabs.
for (const {tabs} of sortMap.values()) { for (const { tabs } of sortMap.values()) {
for (const tab of tabs) { for (const tab of tabs) {
++pos; ++pos;
browser.tabs.move(tab.id, { browser.tabs.move(tab.id, {
@@ -490,7 +489,7 @@ const backgroundLogic = {
async hideTabs(options) { async hideTabs(options) {
const requiredArguments = ["cookieStoreId", "windowId"]; const requiredArguments = ["cookieStoreId", "windowId"];
this.checkArgs(requiredArguments, options, "hideTabs"); this.checkArgs(requiredArguments, options, "hideTabs");
const {cookieStoreId, windowId} = options; const { cookieStoreId, windowId } = options;
const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(cookieStoreId); const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(cookieStoreId);
@@ -530,7 +529,7 @@ const backgroundLogic = {
}, },
cookieStoreId(userContextId) { cookieStoreId(userContextId) {
if (userContextId === 0) return "firefox-default"; if(userContextId === 0) return "firefox-default";
return `firefox-container-${userContextId}`; return `firefox-container-${userContextId}`;
} }
}; };