diff --git a/package-lock.json b/package-lock.json index c9da2dcda..0ce68d9d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "testpilot-containers", - "version": "8.1.3", + "version": "8.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "testpilot-containers", - "version": "8.1.1", + "version": "8.2.0", "license": "MPL-2.0", "devDependencies": { "addons-linter": "^5.28.0", @@ -15032,8 +15032,7 @@ "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", - "dev": true, - "requires": {} + "dev": true }, "acorn-walk": { "version": "7.2.0", @@ -17246,15 +17245,13 @@ "version": "4.0.2", "resolved": "https://registry.npmjs.org/eslint-plugin-no-unsanitized/-/eslint-plugin-no-unsanitized-4.0.2.tgz", "integrity": "sha512-Pry0S9YmHoz8NCEMRQh7N0Yexh2MYCNPIlrV52hTmS7qXnTghWsjXouF08bgsrrZqaW9tt1ZiK3j5NEmPE+EjQ==", - "dev": true, - "requires": {} + "dev": true }, "eslint-plugin-promise": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-5.2.0.tgz", "integrity": "sha512-SftLb1pUG01QYq2A/hGAWfDRXqYD82zE7j7TopDOyNdU+7SvvoXREls/+PRTY17vUXzXnZA/zfnyKgRH6x4JJw==", - "dev": true, - "requires": {} + "dev": true }, "eslint-scope": { "version": "5.1.1", @@ -19763,8 +19760,7 @@ "version": "7.5.9", "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz", "integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==", - "dev": true, - "requires": {} + "dev": true } } }, @@ -21971,8 +21967,7 @@ "version": "0.36.2", "resolved": "https://registry.npmjs.org/postcss-syntax/-/postcss-syntax-0.36.2.tgz", "integrity": "sha512-nBRg/i7E3SOHWxF3PpF5WnJM/jQ1YpY9000OaVXlAQj6Zp/kIqJxEDWIZ67tAd7NLuk7zqN4yqe9nc0oNAOs1w==", - "dev": true, - "requires": {} + "dev": true }, "postcss-value-parser": { "version": "4.2.0", @@ -22826,8 +22821,7 @@ "version": "3.7.0", "resolved": "https://registry.npmjs.org/sinon-chai/-/sinon-chai-3.7.0.tgz", "integrity": "sha512-mf5NURdUaSdnatJx3uhoBOrY9dtL19fiOtAdT1Azxg3+lNJFiuN0uzaU3xX1LeAfL17kHQhTAJgpsfhbMJMY2g==", - "dev": true, - "requires": {} + "dev": true }, "slash": { "version": "3.0.0", @@ -23571,8 +23565,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-3.0.0.tgz", "integrity": "sha512-F6yTRuc06xr1h5Qw/ykb2LuFynJ2IxkKfCMf+1xqPffkxh0S09Zc902XCffcsw/XMFq/OzQ1w54fLIDtmRNHnQ==", - "dev": true, - "requires": {} + "dev": true }, "stylelint-config-standard": { "version": "20.0.0", @@ -24946,8 +24939,7 @@ "version": "8.12.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.12.0.tgz", "integrity": "sha512-kU62emKIdKVeEIOIKVegvqpXMSTAMLJozpHZaJNDYqBjzlSYXQGviYwN1osDLJ9av68qHd4a2oSjd7yD4pacig==", - "dev": true, - "requires": {} + "dev": true }, "xdg-basedir": { "version": "5.1.0", diff --git a/src/js/background/backgroundLogic.js b/src/js/background/backgroundLogic.js index 54bdd0e5e..fe7b20d20 100644 --- a/src/js/background/backgroundLogic.js +++ b/src/js/background/backgroundLogic.js @@ -4,6 +4,8 @@ const DEFAULT_TAB = "about:newtab"; +// let originalTabs = []; + const backgroundLogic = { NEW_TAB_PAGES: new Set([ "about:startpage", @@ -330,11 +332,33 @@ const backgroundLogic = { }, async sortTabs() { - const windows = await browser.windows.getAll(); - for (let windowObj of windows) { // eslint-disable-line prefer-const - // First the pinned tabs, then the normal ones. - await this._sortTabsInternal(windowObj, true); - await this._sortTabsInternal(windowObj, false); + const windowObj = await browser.windows.getCurrent(); + const tabs = await browser.tabs.query({windowId: windowObj.id}); + for (const tab of tabs){ + if(!(windowObj.id in ORIGINAL_TABS)){ + ORIGINAL_TABS[windowObj.id] = []; + } + ORIGINAL_TABS[windowObj.id].push(tab.id); + } + let jsonarray = JSON.stringify(ORIGINAL_TABS); + localStorage.setItem("originalTabs", jsonarray); + + // First the pinned tabs, then the normal ones. + await this._sortTabsInternal(windowObj, true); + await this._sortTabsInternal(windowObj, false); + + }, + + async _unsortTabsInternal(windowObj){ + let pos = 0; + let parsedOriginalTabs = JSON.parse(localStorage.getItem("originalTabs")); + let windowSpecificOriginalTabs = parsedOriginalTabs[windowObj.id]; + for (const tab of windowSpecificOriginalTabs) { + ++pos; + browser.tabs.move(tab, { + windowId: windowObj.id, + index: pos + }); } }, diff --git a/src/js/background/messageHandler.js b/src/js/background/messageHandler.js index 96dbc684b..e06c5e31d 100644 --- a/src/js/background/messageHandler.js +++ b/src/js/background/messageHandler.js @@ -54,6 +54,9 @@ const messageHandler = { case "sortTabs": backgroundLogic.sortTabs(); break; + case "unsortTabs": + backgroundLogic.unsortTabs(); + break; case "showTabs": backgroundLogic.unhideContainer(m.cookieStoreId); break; diff --git a/src/js/popup.js b/src/js/popup.js index 61a3fdaf0..6a2c0b444 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -766,6 +766,17 @@ Logic.registerPanel(P_CONTAINERS_LIST, { window.close(); } }); + Utils.addEnterHandler(document.querySelector("#unsort-containers-link"), async () => { + try { + await browser.runtime.sendMessage({ + method: "unsortTabs" + }); + window.close(); + } catch (e) { + window.close(); + } + + }); const mozillaVpnToutName = "moz-tout-main-panel"; const mozillaVpnPermissionsWarningDotName = "moz-permissions-warning-dot"; @@ -911,6 +922,16 @@ Logic.registerPanel(P_CONTAINERS_LIST, { document.addEventListener("input", Logic.filterContainerList); MozillaVPN.handleContainerList(identities); + // document.querySelector("#unsort-containers-link").setAttribute("disabled", "true"); + if (localStorage.getItem("originalTabs") == null){ + document.querySelector("#unsort-containers-link").setAttribute("disabled", "true"); + } + + else { + document.querySelector("#unsort-containers-link").removeAttribute("disabled"); + } + + // console.log(localStorage.getItem("originalTabs")); // reset path this._previousPanelPath = []; diff --git a/src/js/utils.js b/src/js/utils.js index 5745a47fe..c3f67976f 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -4,6 +4,7 @@ const DEFAULT_FAVICON = "/img/blank-favicon.svg"; // eslint-disable-next-line const CONTAINER_ORDER_STORAGE_KEY = "container-order"; +const ORIGINAL_TABS = {}; // TODO use export here instead of globals const Utils = { diff --git a/src/popup.html b/src/popup.html index ae4608079..574f57370 100644 --- a/src/popup.html +++ b/src/popup.html @@ -140,6 +140,15 @@

Firefox Multi-Account Containers

+ + + + + + + + +