Improved back-up option b8cf955e1f

This commit is contained in:
BPower0036 2022-06-14 05:49:04 +00:00 committed by GitHub
parent 19ee180779
commit 6ef3d7ec24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 16 deletions

View file

@ -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": {

View file

@ -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
}
// 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 };
},

View file

@ -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": {

View file

@ -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"
}
]
}