From 6ef3d7ec242582a0edbe0a864a17e8513ad3db9a Mon Sep 17 00:00:00 2001 From: BPower0036 <80090789+BPower0036@users.noreply.github.com> Date: Tue, 14 Jun 2022 05:49:04 +0000 Subject: [PATCH] Improved back-up option https://github.com/mozilla/multi-account-containers/pull/1533/commits/b8cf955e1f3024cca355a47bc45361583f4477e2 --- src/_locales/nl/messages.json | 2 +- src/js/background/backgroundLogic.js | 44 ++++++++++++++++++++-------- src/manifest.json | 2 +- src/update.json | 4 +-- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/_locales/nl/messages.json b/src/_locales/nl/messages.json index 3560e3d..4fbcc6a 100644 --- a/src/_locales/nl/messages.json +++ b/src/_locales/nl/messages.json @@ -417,7 +417,7 @@ "description": "(Options menu) Backup to/from a file header" }, "restoreLegend": { - "message": "Restore", + "message": "Herstellen", "description": "(Options menu) Restore containers from a file group header" }, "warningConfigOverride": { diff --git a/src/js/background/backgroundLogic.js b/src/js/background/backgroundLogic.js index 309cc1e..f658cf0 100644 --- a/src/js/background/backgroundLogic.js +++ b/src/js/background/backgroundLogic.js @@ -277,9 +277,21 @@ const backgroundLogic = { return Promise.all( identities.map(async ({ cookieStoreId, color, icon, name }) => { const userContextId = this.getUserContextIdFromCookieStoreId(cookieStoreId); - const sitesByContainer = await assignManager.storageArea.getAssignedSites(userContextId); + const [ + { isIsolated }, + sitesByContainer + ] = await Promise.all([ + identityState.storageArea.get(cookieStoreId), + assignManager.storageArea.getAssignedSites(userContextId) + ]); const sites = Object.values(sitesByContainer).map(({ neverAsk, hostname }) => ({ neverAsk, hostname })); - return ({ color, icon, name, sites }); + return ({ + color, + icon, + name, + isolated: isIsolated && true, // either `true` or `undefined` + sites + }); }) ); }, @@ -288,13 +300,19 @@ const backgroundLogic = { const backup = await browser.contextualIdentities.query({}); const incomplete = []; let allSucceed = true; - const identitiesPromise = identities.map(async ({ color, icon, name, sites }) => { + const identitiesPromise = identities.map(async ({ color, icon, name, isolated, sites }) => { try { - if (typeof color !== "string" || typeof icon !== "string" || typeof name !== "string" || !Array.isArray((sites))) + if ( + typeof color !== "string" || + typeof icon !== "string" || + typeof name !== "string" || + (isolated !== true && isolated !== undefined) || + !Array.isArray((sites)) + ) throw new Error("Corrupted container backup"); const identity = await browser.contextualIdentities.create({ color, icon, name }); try { - await identityState.storageArea.get(identity.cookieStoreId); + await identityState.storageArea.get(identity.cookieStoreId); // to create identity state const userContextId = this.getUserContextIdFromCookieStoreId(identity.cookieStoreId); for (const { neverAsk, hostname } of sites) { if (typeof neverAsk !== "boolean" || typeof hostname !== "string" || hostname === "") @@ -305,6 +323,8 @@ const backgroundLogic = { userContextId }); } + if (isolated) + await identityState.storageArea.set(identity.cookieStoreId, { isIsolated: "locked" }); } catch (err) { incomplete.push(name); // site association damaged } @@ -325,14 +345,14 @@ const backgroundLogic = { }) ); throw new Error("Some containers couldn't be created"); - } else { // Importation succeed, remove old identities - await Promise.all( - backup.map(async (identity) => { - await identityState.storageArea.remove(identity.cookieStoreId); - await browser.contextualIdentities.remove(identity.cookieStoreId); - }) - ); } + // Importation succeed, remove old identities + await Promise.all( + backup.map(async (identity) => { + await identityState.storageArea.remove(identity.cookieStoreId); + await browser.contextualIdentities.remove(identity.cookieStoreId); + }) + ); return { created: created.length, incomplete }; }, diff --git a/src/manifest.json b/src/manifest.json index 9e26f8e..fbd9fd1 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "author": "BPower0036", "name": "Multi-Account Containers (Wildcard)", - "version": "8.0.8.1a2", + "version": "8.0.8.1", "incognito": "not_allowed", "description": "__MSG_extensionDescription__", "icons": { diff --git a/src/update.json b/src/update.json index a8619a4..1494ffd 100644 --- a/src/update.json +++ b/src/update.json @@ -3,9 +3,9 @@ "@testpilot-containers-wildcard": { "updates": [ { - "version": "8.0.8.1a2", + "version": "8.0.8.1", "browser_specific_settings": { "gecko": { "strict_min_version": "91.1.0" } }, - "update_link": "https://github.com/BPower0036/multi-account-containers/releases/download/8.0.8.1a2/multi_account_containers_wildcard-8.0.8.1a2-fx.xpi" + "update_link": "https://github.com/BPower0036/multi-account-containers/releases/download/8.0.8.1/multi_account_containers_wildcard-8.0.8.1-fx.xpi" } ] }