Merge pull request #1540 from oksmelnik/duplicated-tabs

#950: don't unhide duplicates of already opened tab
This commit is contained in:
luke crouch 2019-10-25 13:30:24 -05:00 committed by GitHub
commit a8aafc7064
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 11 deletions

View file

@ -112,11 +112,12 @@ const backgroundLogic = {
return list.concat(containerState.hiddenTabs); return list.concat(containerState.hiddenTabs);
}, },
async unhideContainer(cookieStoreId) { async unhideContainer(cookieStoreId, alreadyShowingUrl) {
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,
alreadyShowingUrl
}); });
this.unhideQueue.splice(this.unhideQueue.indexOf(cookieStoreId), 1); this.unhideQueue.splice(this.unhideQueue.indexOf(cookieStoreId), 1);
} }
@ -308,13 +309,16 @@ 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
promises.push(this.openNewTab({ // do not show already opened url
userContextId: userContextId, if (object.url !== options.alreadyShowingUrl) {
url: object.url, promises.push(this.openNewTab({
nofocus: options.nofocus || false, userContextId: userContextId,
noload: true, url: object.url,
pinned: object.pinned, nofocus: options.nofocus || false,
})); noload: true,
pinned: object.pinned,
}));
}
} }
containerState.hiddenTabs = []; containerState.hiddenTabs = [];

View file

@ -153,9 +153,26 @@ const messageHandler = {
!tab.url.startsWith("moz-extension")) { !tab.url.startsWith("moz-extension")) {
// increment the counter of container tabs opened // increment the counter of container tabs opened
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;