From 4331a2612c38ff082d42177d40c436f216211a5f Mon Sep 17 00:00:00 2001 From: baku Date: Wed, 18 Jan 2017 17:32:56 +0100 Subject: [PATCH] Show tab list if Container is hidden but don't make the rows selectable --- index.js | 28 ++++++++++++++++++++++------ webextension/js/popup.js | 26 +++++++++++++++----------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 28fbb22..7e1a6b5 100644 --- a/index.js +++ b/index.js @@ -160,12 +160,15 @@ const ContainerService = { return parseInt(viewFor(tab).getAttribute("usercontextid") || 0, 10); }, + _createTabObject(tab) { + return { title: tab.title, url: tab.url, id: tab.id, active: true }; + }, + _getTabList(userContextId) { const list = []; for (let tab of tabs) { // eslint-disable-line prefer-const if (userContextId === this._getUserContextIdFromTab(tab)) { - const object = { title: tab.title, url: tab.url, id: tab.id }; - list.push(object); + list.push(this._createTabObject(tab)); } } @@ -186,7 +189,19 @@ const ContainerService = { continue; } - this._identitiesState[args.userContextId].hiddenTabUrls.push(tab.url); + const object = this._createTabObject(tab); + + // This tab is going to be closed. Let's mark this tabObject as + // non-active. + object.active = false; + + getFavicon(object.url).then(url => { + object.favicon = url; + }, () => { + object.favicon = ""; + }); + + this._identitiesState[args.userContextId].hiddenTabUrls.push(object); tab.close(); } @@ -201,8 +216,9 @@ const ContainerService = { const promises = []; - for (let url of this._identitiesState[args.userContextId].hiddenTabUrls) { // eslint-disable-line prefer-const - promises.push(this.openTab({ userContextId: args.userContextId, url })); + for (let object of this._identitiesState[args.userContextId].hiddenTabUrls) { // eslint-disable-line prefer-const + promises.push(this.openTab({ userContextId: args.userContextId, + url: object.url })); } this._identitiesState[args.userContextId].hiddenTabUrls = []; @@ -279,7 +295,7 @@ const ContainerService = { } Promise.all(promises).then(() => { - resolve(list); + resolve(list.concat(this._identitiesState[args.userContextId].hiddenTabUrls)); }).catch((e) => { reject(e); }); diff --git a/webextension/js/popup.js b/webextension/js/popup.js index b2ef64e..729555c 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -320,21 +320,25 @@ Logic.registerPanel(P_CONTAINER_INFO, { for (let tab of tabs) { // eslint-disable-line prefer-const const tr = document.createElement("tr"); fragment.appendChild(tr); - tr.classList.add("container-info-tab", "clickable"); + tr.classList.add("container-info-tab"); tr.innerHTML = ` ${tab.title}`; - // On click, we activate this tab. - tr.addEventListener("click", () => { - browser.runtime.sendMessage({ - method: "showTab", - tabId: tab.id, - }).then(() => { - window.close(); - }).catch(() => { - window.close(); + + // On click, we activate this tab. But only if this tab is active. + if (tab.active) { + tr.classList.add("clickable"); + tr.addEventListener("click", () => { + browser.runtime.sendMessage({ + method: "showTab", + tabId: tab.id, + }).then(() => { + window.close(); + }).catch(() => { + window.close(); + }); }); - }); + } } document.getElementById("container-info-table").appendChild(fragment);