From 384ac486d9fb9a39d9df7bb4f194156c22214c38 Mon Sep 17 00:00:00 2001 From: Oksana Melnik Date: Sat, 19 Oct 2019 14:43:03 +0200 Subject: [PATCH 1/2] duplitated-tabs: don't unhide duplicates of already opened tab --- src/js/background/backgroundLogic.js | 21 +++++++++++++-------- src/js/background/messageHandler.js | 19 ++++++++++++++++++- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/js/background/backgroundLogic.js b/src/js/background/backgroundLogic.js index 52d61a2..8542d52 100644 --- a/src/js/background/backgroundLogic.js +++ b/src/js/background/backgroundLogic.js @@ -113,11 +113,12 @@ const backgroundLogic = { return list.concat(containerState.hiddenTabs); }, - async unhideContainer(cookieStoreId) { + async unhideContainer(cookieStoreId, toHide) { if (!this.unhideQueue.includes(cookieStoreId)) { this.unhideQueue.push(cookieStoreId); await this.showTabs({ - cookieStoreId + cookieStoreId, + toHide }); this.unhideQueue.splice(this.unhideQueue.indexOf(cookieStoreId), 1); } @@ -309,12 +310,16 @@ const backgroundLogic = { const containerState = await identityState.storageArea.get(options.cookieStoreId); for (let object of containerState.hiddenTabs) { // eslint-disable-line prefer-const - promises.push(this.openNewTab({ - userContextId: userContextId, - url: object.url, - nofocus: options.nofocus || false, - pinned: object.pinned, - })); + // do not show already opened url + if (object.url !== options.toHide) { + promises.push(this.openNewTab({ + userContextId: userContextId, + url: object.url, + nofocus: options.nofocus || false, + pinned: object.pinned, + })); + } + } containerState.hiddenTabs = []; diff --git a/src/js/background/messageHandler.js b/src/js/background/messageHandler.js index 9fbe88e..a1027ae 100644 --- a/src/js/background/messageHandler.js +++ b/src/js/background/messageHandler.js @@ -155,7 +155,24 @@ const messageHandler = { 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(() => { this.lastCreatedTab = null; From c3da5737229d12b7428ab44e3a0c0c54d11dc95c Mon Sep 17 00:00:00 2001 From: Oksana Melnik Date: Fri, 25 Oct 2019 08:08:04 +0200 Subject: [PATCH 2/2] cleanup --- src/js/background/backgroundLogic.js | 6 +++--- src/js/background/messageHandler.js | 32 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/js/background/backgroundLogic.js b/src/js/background/backgroundLogic.js index 8542d52..1e40a29 100644 --- a/src/js/background/backgroundLogic.js +++ b/src/js/background/backgroundLogic.js @@ -113,12 +113,12 @@ const backgroundLogic = { return list.concat(containerState.hiddenTabs); }, - async unhideContainer(cookieStoreId, toHide) { + async unhideContainer(cookieStoreId, alreadyShowingUrl) { if (!this.unhideQueue.includes(cookieStoreId)) { this.unhideQueue.push(cookieStoreId); await this.showTabs({ cookieStoreId, - toHide + alreadyShowingUrl }); this.unhideQueue.splice(this.unhideQueue.indexOf(cookieStoreId), 1); } @@ -311,7 +311,7 @@ const backgroundLogic = { for (let object of containerState.hiddenTabs) { // eslint-disable-line prefer-const // do not show already opened url - if (object.url !== options.toHide) { + if (object.url !== options.alreadyShowingUrl) { promises.push(this.openNewTab({ userContextId: userContextId, url: object.url, diff --git a/src/js/background/messageHandler.js b/src/js/background/messageHandler.js index a1027ae..a2a5e11 100644 --- a/src/js/background/messageHandler.js +++ b/src/js/background/messageHandler.js @@ -153,25 +153,25 @@ const messageHandler = { !tab.url.startsWith("moz-extension")) { // increment the counter of container tabs opened this.incrementCountOfContainerTabsOpened(); - } - 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; - }); + 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); + 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); } - }; - - // 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(() => {