From fe0810b048464888208bc51a38de6e63dc28fc52 Mon Sep 17 00:00:00 2001 From: shivangikakkar Date: Sun, 23 Sep 2018 00:42:43 +0530 Subject: [PATCH] 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.