From dd57158ab50affd0926bdc545700651c1bfb416f Mon Sep 17 00:00:00 2001 From: shivangikakkar Date: Thu, 20 Sep 2018 21:34:19 +0530 Subject: [PATCH 01/19] #885 disables move tab to a new window when only one tab is opened --- src/js/popup.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/js/popup.js b/src/js/popup.js index a9e3d26..141328c 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -212,6 +212,11 @@ const Logic = { return false; }, + async noOfTabs() { + const activeTabs = await browser.tabs.query({windowId: browser.windows.WINDOW_ID_CURRENT}); + return activeTabs.length; + }, + async refreshIdentities() { const [identities, state] = await Promise.all([ browser.contextualIdentities.query({}), @@ -717,13 +722,21 @@ Logic.registerPanel(P_CONTAINER_INFO, { moveTabsEl.parentNode.insertBefore(fragment, moveTabsEl.nextSibling); } else { - Logic.addEnterHandler(moveTabsEl, async function () { - await browser.runtime.sendMessage({ - method: "moveTabsToWindow", - windowId: browser.windows.WINDOW_ID_CURRENT, - cookieStoreId: Logic.currentIdentity().cookieStoreId, - }); - window.close(); + Logic.noOfTabs().then(result => { + if (result === 1) { + moveTabsEl.classList.remove("clickable"); + } else { + Logic.addEnterHandler(moveTabsEl, async function () { + await browser.runtime.sendMessage({ + method: "moveTabsToWindow", + windowId: browser.windows.WINDOW_ID_CURRENT, + cookieStoreId: Logic.currentIdentity().cookieStoreId, + }); + window.close(); + }); + } + }).catch(error => { + throw new Error(error); }); } } catch (e) { From e57c556427fdb85aef5f7ef4a856e571b19e8f24 Mon Sep 17 00:00:00 2001 From: shivangikakkar Date: Thu, 20 Sep 2018 23:40:22 +0530 Subject: [PATCH 02/19] review changes --- src/js/popup.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/js/popup.js b/src/js/popup.js index 141328c..42b00d3 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -212,7 +212,7 @@ const Logic = { return false; }, - async noOfTabs() { + async numTabs() { const activeTabs = await browser.tabs.query({windowId: browser.windows.WINDOW_ID_CURRENT}); return activeTabs.length; }, @@ -722,8 +722,9 @@ Logic.registerPanel(P_CONTAINER_INFO, { moveTabsEl.parentNode.insertBefore(fragment, moveTabsEl.nextSibling); } else { - Logic.noOfTabs().then(result => { - if (result === 1) { + try { + const numTabs = await Logic.numTabs(); + if (numTabs === 1) { moveTabsEl.classList.remove("clickable"); } else { Logic.addEnterHandler(moveTabsEl, async function () { @@ -735,9 +736,9 @@ Logic.registerPanel(P_CONTAINER_INFO, { window.close(); }); } - }).catch(error => { - throw new Error(error); - }); + } catch (e) { + throw new Error("Could not get the number of active tabs."); + } } } catch (e) { throw new Error("Could not check for incompatible add-ons."); From 7f7f221a79acbe731e232e9fdfcb1962e9d3e56c Mon Sep 17 00:00:00 2001 From: shivangikakkar Date: Fri, 21 Sep 2018 14:00:20 +0530 Subject: [PATCH 03/19] fix-#1028 resolves focus name field on opening new container sub-panel --- src/js/popup.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/js/popup.js b/src/js/popup.js index a9e3d26..419377e 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -1001,6 +1001,12 @@ Logic.registerPanel(P_CONTAINER_EDIT, { document.querySelector("#edit-container-panel-name-input").value = identity.name || ""; document.querySelector("#edit-container-panel-usercontext-input").value = userContextId || NEW_CONTAINER_ID; + const containerName = document.querySelector("#edit-container-panel-name-input"); + setTimeout(function() + { + containerName.focus(); + containerName.select(); + }, 0); [...document.querySelectorAll("[name='container-color']")].forEach(colorInput => { colorInput.checked = colorInput.value === identity.color; }); @@ -1015,7 +1021,6 @@ Logic.registerPanel(P_CONTAINER_EDIT, { // P_CONTAINER_DELETE: Delete a container. // ---------------------------------------------------------------------------- - Logic.registerPanel(P_CONTAINER_DELETE, { panelSelector: "#delete-container-panel", From e1c1ac4bd9a7a1394153e3e8866c273acce778ed Mon Sep 17 00:00:00 2001 From: shivangikakkar Date: Fri, 21 Sep 2018 14:31:54 +0530 Subject: [PATCH 04/19] adds back the unnecessarily removed new line --- src/js/popup.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/popup.js b/src/js/popup.js index 419377e..0226ddd 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -1021,6 +1021,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, { // P_CONTAINER_DELETE: Delete a container. // ---------------------------------------------------------------------------- + Logic.registerPanel(P_CONTAINER_DELETE, { panelSelector: "#delete-container-panel", From fe0810b048464888208bc51a38de6e63dc28fc52 Mon Sep 17 00:00:00 2001 From: shivangikakkar Date: Sun, 23 Sep 2018 00:42:43 +0530 Subject: [PATCH 05/19] restructuring the code acc to the review --- src/js/popup.js | 69 +++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/js/popup.js b/src/js/popup.js index 42b00d3..2964f02 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -217,6 +217,22 @@ const Logic = { return activeTabs.length; }, + _disableMoveTabs(message) { + const moveTabsEl = document.querySelector("#container-info-movetabs"); + const fragment = document.createDocumentFragment(); + const incompatEl = document.createElement("div"); + + moveTabsEl.classList.remove("clickable"); + moveTabsEl.setAttribute("title", message); + + fragment.appendChild(incompatEl); + incompatEl.setAttribute("id", "container-info-movetabs-incompat"); + incompatEl.textContent = message; + incompatEl.classList.add("container-info-tab-row"); + + moveTabsEl.parentNode.insertBefore(fragment, moveTabsEl.nextSibling); + }, + async refreshIdentities() { const [identities, state] = await Promise.all([ browser.contextualIdentities.query({}), @@ -703,46 +719,31 @@ Logic.registerPanel(P_CONTAINER_INFO, { }); // Check if the user has incompatible add-ons installed + let incompatible = false; try { - const incompatible = await browser.runtime.sendMessage({ + incompatible = await browser.runtime.sendMessage({ method: "checkIncompatibleAddons" }); - const moveTabsEl = document.querySelector("#container-info-movetabs"); - if (incompatible) { - const fragment = document.createDocumentFragment(); - const incompatEl = document.createElement("div"); - - moveTabsEl.classList.remove("clickable"); - moveTabsEl.setAttribute("title", "Moving container tabs is incompatible with Pulse, PageShot, and SnoozeTabs."); - - fragment.appendChild(incompatEl); - incompatEl.setAttribute("id", "container-info-movetabs-incompat"); - incompatEl.textContent = "Incompatible with other Experiments."; - incompatEl.classList.add("container-info-tab-row"); - - moveTabsEl.parentNode.insertBefore(fragment, moveTabsEl.nextSibling); - } else { - try { - const numTabs = await Logic.numTabs(); - if (numTabs === 1) { - moveTabsEl.classList.remove("clickable"); - } else { - Logic.addEnterHandler(moveTabsEl, async function () { - await browser.runtime.sendMessage({ - method: "moveTabsToWindow", - windowId: browser.windows.WINDOW_ID_CURRENT, - cookieStoreId: Logic.currentIdentity().cookieStoreId, - }); - window.close(); - }); - } - } catch (e) { - throw new Error("Could not get the number of active tabs."); - } - } } catch (e) { throw new Error("Could not check for incompatible add-ons."); } + const moveTabsEl = document.querySelector("#container-info-movetabs"); + const numTabs = await Logic.numTabs(); + if (incompatible) { + Logic._disableMoveTabs("Moving container tabs is incompatible with Pulse, PageShot, and SnoozeTabs."); + return; + } else if (numTabs === 1) { + Logic._disableMoveTabs("Cannot move a tab from a single-tab window."); + return; + } + Logic.addEnterHandler(moveTabsEl, async function () { + await browser.runtime.sendMessage({ + method: "moveTabsToWindow", + windowId: browser.windows.WINDOW_ID_CURRENT, + cookieStoreId: Logic.currentIdentity().cookieStoreId, + }); + window.close(); + }); }, // This method is called when the panel is shown. From aada0419eb2fb75f5d7856e3787843f7e35ea845 Mon Sep 17 00:00:00 2001 From: shivangikakkar Date: Sun, 30 Sep 2018 18:17:01 +0530 Subject: [PATCH 06/19] removing event loop and using requestAnimationFrame --- src/js/popup.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/js/popup.js b/src/js/popup.js index 0226ddd..c3503b6 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -1002,11 +1002,10 @@ Logic.registerPanel(P_CONTAINER_EDIT, { document.querySelector("#edit-container-panel-name-input").value = identity.name || ""; document.querySelector("#edit-container-panel-usercontext-input").value = userContextId || NEW_CONTAINER_ID; const containerName = document.querySelector("#edit-container-panel-name-input"); - setTimeout(function() - { - containerName.focus(); - containerName.select(); - }, 0); + window.requestAnimationFrame(() => { + containerName.select(); + containerName.focus(); + }); [...document.querySelectorAll("[name='container-color']")].forEach(colorInput => { colorInput.checked = colorInput.value === identity.color; }); From d7586dd4c26f5d96699eee80468f68f997ec53ce Mon Sep 17 00:00:00 2001 From: shivangikakkar Date: Fri, 28 Sep 2018 03:48:46 +0530 Subject: [PATCH 07/19] resolves #256 disables edit-container button when no container is present resolve lint errors review changes --- src/css/popup.css | 6 ++++++ src/js/popup.js | 7 +++++++ src/popup.html | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/css/popup.css b/src/css/popup.css index af78306..6eb6496 100644 --- a/src/css/popup.css +++ b/src/css/popup.css @@ -45,6 +45,7 @@ body { --small-text-size: 0.833rem; /* 10px */ --small-radius: 3px; --icon-button-size: calc(calc(var(--block-line-separation-size) * 2) + 1.66rem); /* 20px */ + --inactive-opacity: 0.3; } @media (min-resolution: 1dppx) { @@ -578,6 +579,11 @@ span ~ .panel-header-text { max-inline-size: 204px; } +.disable-edit-containers { + opacity: var(--inactive-opacity); + pointer-events: none; +} + .userContext-wrapper { align-items: center; display: flex; diff --git a/src/js/popup.js b/src/js/popup.js index 2964f02..649384a 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -687,6 +687,13 @@ Logic.registerPanel(P_CONTAINERS_LIST, { document.addEventListener("mousedown", () => { document.removeEventListener("focus", focusHandler); }); + /* If no container is present disable the Edit Containers button */ + const editContainer = document.querySelector("#edit-containers"); + if (Logic.identities().length === 0) { + editContainer.classList.add("disable-edit-containers"); + } else { + editContainer.classList.remove("disable-edit-containers"); + } return Promise.resolve(); }, diff --git a/src/popup.html b/src/popup.html index a28dd32..c342edd 100644 --- a/src/popup.html +++ b/src/popup.html @@ -116,7 +116,7 @@