review fedback

This commit is contained in:
Kendall Werts 2020-01-23 13:47:19 -06:00
parent 5b8cfa14ae
commit 0447e54b1c
5 changed files with 33 additions and 36 deletions

View file

@ -78,7 +78,9 @@ const assignManager = {
[siteStoreKey]: data [siteStoreKey]: data
}); });
const syncEnabled = await this.getSyncEnabled(); const syncEnabled = await this.getSyncEnabled();
if (backup && syncEnabled) await sync.storageArea.backup({undeleteSiteStoreKey: siteStoreKey}); if (backup && syncEnabled) {
await sync.storageArea.backup({undeleteSiteStoreKey: siteStoreKey});
}
return; return;
}, },
@ -135,7 +137,7 @@ const assignManager = {
localIdentity => localIdentity.cookieStoreId === cookieStoreId localIdentity => localIdentity.cookieStoreId === cookieStoreId
); );
if (!match) { if (!match) {
await this.remove(configKey.replace(/^siteContainerMap@@_/, "https://")); await this.remove(configKey);
continue; continue;
} }
const updatedSiteAssignment = macConfigs[configKey]; const updatedSiteAssignment = macConfigs[configKey];

View file

@ -49,6 +49,12 @@ const identityState = {
*/ */
async upgradeData() { async upgradeData() {
const identitiesList = await browser.contextualIdentities.query({}); const identitiesList = await browser.contextualIdentities.query({});
for (const identity of identitiesList) {
// ensure all identities have an entry in local storage
await identityState.addUUID(identity.cookieStoreId);
}
const macConfigs = await this.area.get(); const macConfigs = await this.area.get();
for(const configKey of Object.keys(macConfigs)) { for(const configKey of Object.keys(macConfigs)) {
if (configKey.includes("identitiesState@@_")) { if (configKey.includes("identitiesState@@_")) {
@ -61,16 +67,12 @@ const identityState = {
await this.remove(cookieStoreId); await this.remove(cookieStoreId);
continue; continue;
} }
console.log(macConfigs, configKey);
if (!macConfigs[configKey].macAddonUUID) { if (!macConfigs[configKey].macAddonUUID) {
await identityState.storageArea.get(cookieStoreId); await identityState.storageArea.get(cookieStoreId);
} }
} }
} }
for (const identity of identitiesList) {
// ensure all identities have an entry in local storage
await identityState.addUUID(identity.cookieStoreId);
}
} }
}, },
@ -127,7 +129,7 @@ const identityState = {
cookieStoreId : "firefox-container-" + cookieStoreId; cookieStoreId : "firefox-container-" + cookieStoreId;
const macConfigs = await this.storageArea.area.get(); const macConfigs = await this.storageArea.area.get();
for(const configKey of Object.keys(macConfigs)) { for(const configKey of Object.keys(macConfigs)) {
if (configKey === this.getContainerStoreKey(cookieStoreIdKey)) { if (configKey === this.storageArea.getContainerStoreKey(cookieStoreIdKey)) {
return macConfigs[configKey].macAddonUUID; return macConfigs[configKey].macAddonUUID;
} }
} }

View file

@ -118,6 +118,7 @@ const sync = {
await this.deleteSite(options.siteStoreKey); await this.deleteSite(options.siteStoreKey);
if (options && options.undeleteSiteStoreKey) if (options && options.undeleteSiteStoreKey)
await removeFromDeletedSitesList(options.undeleteSiteStoreKey); await removeFromDeletedSitesList(options.undeleteSiteStoreKey);
if (SYNC_DEBUG) console.log("Backed up!"); if (SYNC_DEBUG) console.log("Backed up!");
await sync.checkForListenersMaybeAdd(); await sync.checkForListenersMaybeAdd();
@ -270,26 +271,23 @@ const sync = {
return; return;
}, },
async addContextualIdentityListeners(listenerList) { async addContextualIdentityListeners() {
if(!listenerList) listenerList = syncCIListenerList; await browser.contextualIdentities.onCreated.addListener(sync.storageArea.backup);
await browser.contextualIdentities.onCreated.addListener(listenerList[0]); await browser.contextualIdentities.onRemoved.addListener(sync.storageArea.addToDeletedList);
await browser.contextualIdentities.onRemoved.addListener(listenerList[1]); await browser.contextualIdentities.onUpdated.addListener(sync.storageArea.backup);
await browser.contextualIdentities.onUpdated.addListener(listenerList[2]);
}, },
async removeContextualIdentityListeners(listenerList) { async removeContextualIdentityListeners() {
if(!listenerList) listenerList = syncCIListenerList; await browser.contextualIdentities.onCreated.removeListener(sync.storageArea.backup);
await browser.contextualIdentities.onCreated.removeListener(listenerList[0]); await browser.contextualIdentities.onRemoved.removeListener(sync.storageArea.addToDeletedList);
await browser.contextualIdentities.onRemoved.removeListener(listenerList[1]); await browser.contextualIdentities.onUpdated.removeListener(sync.storageArea.backup);
await browser.contextualIdentities.onUpdated.removeListener(listenerList[2]);
}, },
async hasContextualIdentityListeners(listenerList) { async hasContextualIdentityListeners() {
if(!listenerList) listenerList = syncCIListenerList;
return ( return (
await browser.contextualIdentities.onCreated.hasListener(listenerList[0]) && await browser.contextualIdentities.onCreated.hasListener(sync.storageArea.backup) &&
await browser.contextualIdentities.onRemoved.hasListener(listenerList[1]) && await browser.contextualIdentities.onRemoved.hasListener(sync.storageArea.addToDeletedList) &&
await browser.contextualIdentities.onUpdated.hasListener(listenerList[2]) await browser.contextualIdentities.onUpdated.hasListener(sync.storageArea.backup)
); );
}, },
@ -360,7 +358,9 @@ async function reconcileIdentities(){
await ifNoMatch(syncIdentity); await ifNoMatch(syncIdentity);
continue; continue;
} }
await ifNamesMatch(syncIdentity, localMatch);
// Names match, so use the info from Sync
await updateIdentityWithSyncInfo(syncIdentity, localMatch);
continue; continue;
} }
// if no macAddonUUID, there is a problem with the sync info and it needs to be ignored. // if no macAddonUUID, there is a problem with the sync info and it needs to be ignored.
@ -376,7 +376,7 @@ async function reconcileIdentities(){
} }
} }
async function ifNamesMatch(syncIdentity, localMatch) { async function updateIdentityWithSyncInfo(syncIdentity, localMatch) {
// Sync is truth. if there is a match, compare data and update as needed // Sync is truth. if there is a match, compare data and update as needed
if (syncIdentity.color !== localMatch.color if (syncIdentity.color !== localMatch.color
|| syncIdentity.icon !== localMatch.icon) { || syncIdentity.icon !== localMatch.icon) {
@ -474,7 +474,7 @@ async function reconcileSiteAssignments() {
if (Object.prototype.hasOwnProperty.call(assignedSitesLocal,siteStoreKey)) { if (Object.prototype.hasOwnProperty.call(assignedSitesLocal,siteStoreKey)) {
assignManager assignManager
.storageArea .storageArea
.remove(siteStoreKey.replace(/^siteContainerMap@@_/, "https://")); .remove(siteStoreKey);
} }
} }
@ -548,7 +548,7 @@ async function setAssignmentWithUUID(assignedSite, urlKey) {
assignedSite.userContextId = cookieStoreId assignedSite.userContextId = cookieStoreId
.replace(/^firefox-container-/, ""); .replace(/^firefox-container-/, "");
await assignManager.storageArea.set( await assignManager.storageArea.set(
urlKey.replace(/^siteContainerMap@@_/, "https://"), urlKey,
assignedSite, assignedSite,
false, false,
false false
@ -557,9 +557,3 @@ async function setAssignmentWithUUID(assignedSite, urlKey) {
} }
throw new Error (`No cookieStoreId found for: ${uuid}, ${urlKey}`); throw new Error (`No cookieStoreId found for: ${uuid}, ${urlKey}`);
} }
const syncCIListenerList = [
sync.storageArea.backup,
sync.storageArea.addToDeletedList,
sync.storageArea.backup
];

View file

@ -25,7 +25,6 @@ async function enableDisableSync() {
async function restoreOptions() { async function restoreOptions() {
const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]}); const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]});
const { syncEnabled } = await browser.storage.local.get("syncEnabled"); const { syncEnabled } = await browser.storage.local.get("syncEnabled");
console.log(syncEnabled);
if (hasPermission) { if (hasPermission) {
document.querySelector("#bookmarksPermissions").checked = true; document.querySelector("#bookmarksPermissions").checked = true;
} }

View file

@ -187,7 +187,7 @@ const Logic = {
}; };
// Handle old style rejection with null and also Promise.reject new style // Handle old style rejection with null and also Promise.reject new style
try { try {
return browser.contextualIdentities.get(cookieStoreId) || defaultContainer; return await browser.contextualIdentities.get(cookieStoreId) || defaultContainer;
} catch (e) { } catch (e) {
return defaultContainer; return defaultContainer;
} }
@ -356,7 +356,7 @@ const Logic = {
}, },
getAssignmentObjectByContainer(userContextId) { getAssignmentObjectByContainer(userContextId) {
if (userContextId) { if (!userContextId) {
return {}; return {};
} }
return browser.runtime.sendMessage({ return browser.runtime.sendMessage({