Hide/Show icon should be shown only if we have opened tabs

This commit is contained in:
baku 2017-01-09 11:05:13 +01:00
parent 76ad3fcb0f
commit 71725d829b
2 changed files with 47 additions and 1 deletions

View file

@ -42,7 +42,35 @@ let ContainerService =
// Map of identities.
ContextualIdentityService.getIdentities().forEach(identity => {
this._identitiesState[identity.userContextId] = {hiddenTabUrls: []};
this._identitiesState[identity.userContextId] = {
hiddenTabUrls: [],
openTabs: 0,
};
});
// It can happen that this jsm is loaded after the opening a container tab.
for (let tab of tabs) {
let xulTab = viewFor(tab);
let userContextId = parseInt(xulTab.getAttribute('usercontextid') || 0, 10);
if (userContextId) {
++this._identitiesState[userContextId].openTabs;
}
}
tabs.on("open", tab => {
let xulTab = viewFor(tab);
let userContextId = parseInt(xulTab.getAttribute('usercontextid') || 0, 10);
if (userContextId) {
++this._identitiesState[userContextId].openTabs;
}
});
tabs.on("close", tab => {
let xulTab = viewFor(tab);
let userContextId = parseInt(xulTab.getAttribute('usercontextid') || 0, 10);
if (userContextId && this._identitiesState[userContextId].openTabs) {
--this._identitiesState[userContextId].openTabs;
}
});
// WebExtension startup
@ -65,6 +93,7 @@ let ContainerService =
color: identity.color,
userContextId: identity.userContextId,
hasHiddenTabs: !!this._identitiesState[identity.userContextId].hiddenTabUrls.length,
hasOpenTabs: !!this._identitiesState[identity.userContextId].openTabs,
};
},

View file

@ -10,6 +10,17 @@ function showOrHideContainerTabs(userContextId, hasHiddenTabs) {
method: hasHiddenTabs ? 'showTabs' : 'hideTabs',
userContextId: userContextId
}).then(() => {
return browser.runtime.sendMessage({
method: 'getIdentity',
userContextId: userContextId
});
}).then((identity) => {
if (!identity.hasHiddenTabs && !identity.hasOpenTabs) {
hideorshowIcon.style.display = "none";
} else {
hideorshowIcon.style.display = "";
}
hideorshowIcon.src = hasHiddenTabs ? CONTAINER_HIDE_SRC : CONTAINER_UNHIDE_SRC;
}).then(resolve);
});
@ -79,6 +90,12 @@ browser.runtime.sendMessage({method: 'queryIdentities'}).then(identities=> {
</tr>`;
identitiesListElement.innerHTML += identityRow;
// No tabs, no icon.
if (!identity.hasHiddenTabs && !identity.hasOpenTabs) {
const hideorshowIcon = document.querySelector(`#uci-${identity.userContextId}-hideorshow-icon`);
hideorshowIcon.style.display = "none";
}
});
const rows = identitiesListElement.querySelectorAll('tr');