duplitated-tabs: don't unhide duplicates of already opened tab

This commit is contained in:
Oksana Melnik 2019-10-19 14:43:03 +02:00
parent a4c578adde
commit 384ac486d9
2 changed files with 31 additions and 9 deletions

View file

@ -113,11 +113,12 @@ const backgroundLogic = {
return list.concat(containerState.hiddenTabs); return list.concat(containerState.hiddenTabs);
}, },
async unhideContainer(cookieStoreId) { async unhideContainer(cookieStoreId, toHide) {
if (!this.unhideQueue.includes(cookieStoreId)) { if (!this.unhideQueue.includes(cookieStoreId)) {
this.unhideQueue.push(cookieStoreId); this.unhideQueue.push(cookieStoreId);
await this.showTabs({ await this.showTabs({
cookieStoreId cookieStoreId,
toHide
}); });
this.unhideQueue.splice(this.unhideQueue.indexOf(cookieStoreId), 1); this.unhideQueue.splice(this.unhideQueue.indexOf(cookieStoreId), 1);
} }
@ -309,6 +310,8 @@ const backgroundLogic = {
const containerState = await identityState.storageArea.get(options.cookieStoreId); const containerState = await identityState.storageArea.get(options.cookieStoreId);
for (let object of containerState.hiddenTabs) { // eslint-disable-line prefer-const for (let object of containerState.hiddenTabs) { // eslint-disable-line prefer-const
// do not show already opened url
if (object.url !== options.toHide) {
promises.push(this.openNewTab({ promises.push(this.openNewTab({
userContextId: userContextId, userContextId: userContextId,
url: object.url, url: object.url,
@ -317,6 +320,8 @@ const backgroundLogic = {
})); }));
} }
}
containerState.hiddenTabs = []; containerState.hiddenTabs = [];
await Promise.all(promises); await Promise.all(promises);

View file

@ -155,7 +155,24 @@ const messageHandler = {
this.incrementCountOfContainerTabsOpened(); this.incrementCountOfContainerTabsOpened();
} }
backgroundLogic.unhideContainer(tab.cookieStoreId); this.tabUpdateHandler = (tabId, changeInfo) => {
if (tabId === tab.id && changeInfo.status === "complete") {
// get current tab's url to not open the same one from hidden tabs
browser.tabs.get(tabId).then(loadedTab => {
backgroundLogic.unhideContainer(tab.cookieStoreId, loadedTab.url);
}).catch((e) => {
throw e;
});
browser.tabs.onUpdated.removeListener(this.tabUpdateHandler);
}
};
// if it's a container tab wait for it to complete and
// unhide other tabs from this container
if (tab.cookieStoreId.startsWith("firefox-container")) {
browser.tabs.onUpdated.addListener(this.tabUpdateHandler);
}
} }
setTimeout(() => { setTimeout(() => {
this.lastCreatedTab = null; this.lastCreatedTab = null;