From dd57158ab50affd0926bdc545700651c1bfb416f Mon Sep 17 00:00:00 2001 From: shivangikakkar Date: Thu, 20 Sep 2018 21:34:19 +0530 Subject: [PATCH] #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) {