address feedback 02
This commit is contained in:
@@ -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++) {
|
}
|
||||||
|
|
||||||
|
for (let i=0; i < backgroundLogic.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
|
||||||
const key = MAC_CONSTANTS.OPEN_CONTAINER_PREFIX + i;
|
const key = MAC_CONSTANTS.OPEN_CONTAINER_PREFIX + i;
|
||||||
|
const reopenKey = MAC_CONSTANTS.REOPEN_IN_CONTAINER_PREFIX + i;
|
||||||
const cookieStoreId = identityState.keyboardShortcut[key];
|
const cookieStoreId = identityState.keyboardShortcut[key];
|
||||||
|
|
||||||
|
if (cookieStoreId === "none") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (command === key) {
|
if (command === key) {
|
||||||
if (cookieStoreId !== "none") {
|
|
||||||
browser.tabs.create({cookieStoreId});
|
browser.tabs.create({cookieStoreId});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
if (command === reopenKey) {
|
||||||
}
|
|
||||||
} 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") {
|
|
||||||
backgroundLogic.reopenInContainer(cookieStoreId);
|
backgroundLogic.reopenInContainer(cookieStoreId);
|
||||||
}
|
return;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -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];
|
||||||
@@ -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,
|
||||||
@@ -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}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user