diff --git a/webextension/js/background/backgroundLogic.js b/webextension/js/background/backgroundLogic.js index cb62e06..da59c33 100644 --- a/webextension/js/background/backgroundLogic.js +++ b/webextension/js/background/backgroundLogic.js @@ -318,6 +318,35 @@ const backgroundLogic = { return Promise.all(promises); }, + async showOnly(options) { + if (!("windowId" in options) || !("cookieStoreId" in options)) { + return Promise.reject("showOnly needs both a windowId and a cookieStoreId"); + } + + const [identities, state] = await Promise.all([ + browser.contextualIdentities.query({}), + backgroundLogic.queryIdentitiesState(options.windowId) + ]); + + const promises = []; + identities + .filter(identity => { + const stateObject = state[identity.cookieStoreId]; + const filt = identity.cookieStoreId !== options.cookieStoreId && + stateObject && stateObject.hasOpenTabs; + return filt; + }).map(identity => identity.cookieStoreId) + .forEach(cookieStoreId => { + promises.push(backgroundLogic.hideTabs({cookieStoreId, windowId: options.windowId})); + }); + + // We need to call unhideContainer in messageHandler to prevent it from + // unhiding multiple times + promises.push(messageHandler.unhideContainer(options.cookieStoreId)); + + return Promise.all(promises); + }, + cookieStoreId(userContextId) { return `firefox-container-${userContextId}`; } diff --git a/webextension/js/background/messageHandler.js b/webextension/js/background/messageHandler.js index 7648c9a..96e3628 100644 --- a/webextension/js/background/messageHandler.js +++ b/webextension/js/background/messageHandler.js @@ -71,6 +71,12 @@ const messageHandler = { case "unhideAllTabs": response = backgroundLogic.unhideAllTabs(m.message.windowId); break; + case "showOnly": + response = backgroundLogic.showOnly({ + windowId: m.windowId, + cookieStoreId: m.cookieStoreId + }); + break; } return response; }); diff --git a/webextension/js/popup.js b/webextension/js/popup.js index 3b8c399..59f032a 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -719,6 +719,19 @@ Logic.registerPanel(P_CONTAINER_INFO, { } }); + Logic.addEnterHandler(document.querySelector("#container-info-hideothers"), async function () { + try { + browser.runtime.sendMessage({ + method: "showOnly", + windowId: browser.windows.WINDOW_ID_CURRENT, + cookieStoreId: Logic.currentCookieStoreId() + }); + window.close(); + } catch (e) { + window.close(); + } + }); + // Check if the user has incompatible add-ons installed try { const incompatible = await browser.runtime.sendMessage({ @@ -775,6 +788,9 @@ Logic.registerPanel(P_CONTAINER_INFO, { const hideShowLabel = document.getElementById("container-info-hideorshow-label"); hideShowLabel.textContent = identity.hasHiddenTabs ? "Show this container" : "Hide this container"; + const hideOthersLabel = document.getElementById("container-info-hideothers"); + hideOthersLabel.textContent = identity.hasHiddenTabs ? "Show only this container" : "Hide other containers"; + // Let's remove all the previous tabs. const table = document.getElementById("container-info-table"); while (table.firstChild) { diff --git a/webextension/popup.html b/webextension/popup.html index 68c2d86..1634f4b 100644 --- a/webextension/popup.html +++ b/webextension/popup.html @@ -1,3 +1,4 @@ +
@@ -141,6 +142,7 @@