diff --git a/.eslintrc.js b/.eslintrc.js index eab0580..1197c64 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,6 +19,7 @@ module.exports = { "OS": true, "ADDON_UNINSTALL": true, "ADDON_DISABLE": true, + "CONTAINER_ORDER_STORAGE_KEY": true, "proxifiedContainers": true, "MozillaVPN": true, "MozillaVPN_Background": true diff --git a/src/js/background/backgroundLogic.js b/src/js/background/backgroundLogic.js index 7cf5216..1050d40 100644 --- a/src/js/background/backgroundLogic.js +++ b/src/js/background/backgroundLogic.js @@ -1,4 +1,9 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + const DEFAULT_TAB = "about:newtab"; + const backgroundLogic = { NEW_TAB_PAGES: new Set([ "about:startpage", @@ -168,7 +173,7 @@ const backgroundLogic = { if ("isIsolated" in containerState || remove) { delete containerState.isIsolated; } else { - containerState.isIsolated = "locked"; + containerState.isIsolated = "locked"; } return await identityState.storageArea.set(cookieStoreId, containerState); } catch (error) { @@ -317,19 +322,29 @@ const backgroundLogic = { continue; } - const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(tab.cookieStoreId); - if (!map.has(userContextId)) { - map.set(userContextId, []); + if (!map.has(tab.cookieStoreId)) { + const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(tab.cookieStoreId); + map.set(tab.cookieStoreId, { order: userContextId, tabs: [] }); } - map.get(userContextId).push(tab); + map.get(tab.cookieStoreId).tabs.push(tab); + } + + const containerOrderStorage = await browser.storage.local.get([CONTAINER_ORDER_STORAGE_KEY]); + const containerOrder = + containerOrderStorage && containerOrderStorage[CONTAINER_ORDER_STORAGE_KEY]; + + if (containerOrder) { + map.forEach((obj, key) => { + obj.order = (key in containerOrder) ? containerOrder[key] : -1; + }); } // Let's sort the map. - const sortMap = new Map([...map.entries()].sort((a, b) => a[0] > b[0])); + const sortMap = new Map([...map.entries()].sort((a, b) => a[1].order > b[1].order)); // Let's move tabs. - sortMap.forEach(tabs => { - for (const tab of tabs) { + sortMap.forEach(obj => { + for (const tab of obj.tabs) { ++pos; browser.tabs.move(tab.id, { windowId: windowObj.id, diff --git a/src/js/popup.js b/src/js/popup.js index 324938b..38039b9 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -10,7 +10,6 @@ const DEFAULT_ICON = "circle"; const NEW_CONTAINER_ID = "new"; const ONBOARDING_STORAGE_KEY = "onboarding-stage"; -const CONTAINER_ORDER_STORAGE_KEY = "container-order"; const CONTAINER_DRAG_DATA_TYPE = "firefox-container"; // List of panels diff --git a/src/js/utils.js b/src/js/utils.js index 2d65f45..b05dc97 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -2,6 +2,9 @@ const DEFAULT_FAVICON = "/img/blank-favicon.svg"; +// eslint-disable-next-line +const CONTAINER_ORDER_STORAGE_KEY = "container-order"; + // TODO use export here instead of globals const Utils = {