wip: cleaning up storage before sync

This commit is contained in:
Kendall Werts
2019-12-20 20:03:54 -06:00
parent a7f6659204
commit 136aa3ce0e
2 changed files with 133 additions and 26 deletions
+19 -6
View File
@@ -27,9 +27,23 @@ const identityState = {
});
},
remove(cookieStoreId) {
async remove(cookieStoreId) {
const storeKey = this.getContainerStoreKey(cookieStoreId);
return this.area.remove([storeKey]);
return await this.area.remove([storeKey]);
},
async cleanup() {
const identitiesList = await browser.contextualIdentities.query({});
const macConfigs = await this.area.get();
for(const configKey of Object.keys(macConfigs)) {
if (configKey.includes("identitiesState@@_")) {
const cookieStoreId = String(configKey).replace(/^identitiesState@@_/, "");
const match = identitiesList.find(localIdentity => localIdentity.cookieStoreId === cookieStoreId);
if (!match) {
console.log("removed ", cookieStoreId, " from storage list");
this.remove(cookieStoreId);
}
}
}
}
},
@@ -83,12 +97,11 @@ const identityState = {
},
async lookupMACaddonUUID(cookieStoreId) {
console.log(cookieStoreId)
const macConfigs = await this.storageArea.area.get();
for(const configKey of Object.keys(macConfigs)) {
if (configKey.includes("identitiesState@@_")) {
if(macConfigs[configKey] === cookieStoreId) {
if (configKey == "identitiesState@@_" + cookieStoreId) {
return macConfigs[configKey].macAddonUUID;
}
}
}
return false;
@@ -119,4 +132,4 @@ function uuidv4() {
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);
}
}