Add button on container info pane to show only that container.

Adds a button, located on the info pane for each container, to show only that container.
This button will hide other containers, if they have visible tabs, and show the container the button was pressed for, if it has hidden tabs.

This is a much-needed function to effectively use containers as workspaces, and will please most people coming to multi-account-containers from Panorama tabs.
This commit is contained in:
Tobias Laundal 2017-11-16 22:00:36 +01:00
parent ce0417b9d0
commit 3d7dfba2f9
4 changed files with 53 additions and 0 deletions

View file

@ -318,6 +318,35 @@ const backgroundLogic = {
return Promise.all(promises); 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) { cookieStoreId(userContextId) {
return `firefox-container-${userContextId}`; return `firefox-container-${userContextId}`;
} }

View file

@ -71,6 +71,12 @@ const messageHandler = {
case "unhideAllTabs": case "unhideAllTabs":
response = backgroundLogic.unhideAllTabs(m.message.windowId); response = backgroundLogic.unhideAllTabs(m.message.windowId);
break; break;
case "showOnly":
response = backgroundLogic.showOnly({
windowId: m.windowId,
cookieStoreId: m.cookieStoreId
});
break;
} }
return response; return response;
}); });

View file

@ -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 // Check if the user has incompatible add-ons installed
try { try {
const incompatible = await browser.runtime.sendMessage({ const incompatible = await browser.runtime.sendMessage({
@ -775,6 +788,9 @@ Logic.registerPanel(P_CONTAINER_INFO, {
const hideShowLabel = document.getElementById("container-info-hideorshow-label"); const hideShowLabel = document.getElementById("container-info-hideorshow-label");
hideShowLabel.textContent = identity.hasHiddenTabs ? "Show this container" : "Hide this container"; 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. // Let's remove all the previous tabs.
const table = document.getElementById("container-info-table"); const table = document.getElementById("container-info-table");
while (table.firstChild) { while (table.firstChild) {

View file

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html> <html>
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta http-equiv="content-type" content="text/html; charset=utf-8">
@ -141,6 +142,7 @@
<img id="container-info-hideorshow-icon" alt="Hide Container icon" src="/img/container-hide.svg" class="icon container-info-panel-hideorshow-icon"/> <img id="container-info-hideorshow-icon" alt="Hide Container icon" src="/img/container-hide.svg" class="icon container-info-panel-hideorshow-icon"/>
<span id="container-info-hideorshow-label">Hide this container</span> <span id="container-info-hideorshow-label">Hide this container</span>
</div> </div>
<div class="select-row clickable container-info-panel-hide-others container-info-has-tabs" id="container-info-hideothers">Hide other containers</div>
<div class="select-row clickable container-info-panel-movetabs container-info-has-tabs" id="container-info-movetabs">Move tabs to a new window</div> <div class="select-row clickable container-info-panel-movetabs container-info-has-tabs" id="container-info-movetabs">Move tabs to a new window</div>
<div class="scrollable"> <div class="scrollable">
<table id="container-info-table" class="container-info-list"> <table id="container-info-table" class="container-info-list">