broke up restoreFristRun

This commit is contained in:
Kendall Werts 2019-12-17 16:56:32 -06:00
parent adc1f5ffe6
commit d61ea16db1

View file

@ -642,6 +642,17 @@ async function restore(inSync) {
async function restoreFirstRun(inSync) { async function restoreFirstRun(inSync) {
removeContextualIdentityListeners(backup); removeContextualIdentityListeners(backup);
await reconcileIdentitiesByName(inSync);
await reconcileSiteAssignments(inSync);
backup();
addContextualIdentityListeners(backup);
}
/*
* Checks for the container name. If it exists, they are assumed to be the same container,
* and the color and icon are overwritten from sync, if different.
*/
async function reconcileIdentitiesByName(inSync){
const browserIdentities = await browser.contextualIdentities.query({}); const browserIdentities = await browser.contextualIdentities.query({});
const syncIdentities = inSync.identities; const syncIdentities = inSync.identities;
for (const syncIdentity of inSync.identities) { for (const syncIdentity of inSync.identities) {
@ -651,7 +662,7 @@ async function restoreFirstRun(inSync) {
newIdentity = await browser.contextualIdentities.create({name: syncIdentity.name, color: syncIdentity.color, icon: syncIdentity.icon}); newIdentity = await browser.contextualIdentities.create({name: syncIdentity.name, color: syncIdentity.color, icon: syncIdentity.icon});
identityState.updateUUID(newIdentity.cookieStoreId, syncIdentity.macAddonUUID); identityState.updateUUID(newIdentity.cookieStoreId, syncIdentity.macAddonUUID);
continue; continue;
} else { }
if (syncIdentity.color === match.color && syncIdentity.icon === match.icon) { if (syncIdentity.color === match.color && syncIdentity.icon === match.icon) {
console.log("everything is the same:", syncIdentity, match); console.log("everything is the same:", syncIdentity, match);
continue; continue;
@ -659,7 +670,14 @@ async function restoreFirstRun(inSync) {
console.log("somethings are different:", syncIdentity, match); console.log("somethings are different:", syncIdentity, match);
browser.contextualIdentities.update(match.cookieStoreId, {name: syncIdentity.name, color: syncIdentity.color, icon: syncIdentity.icon}); browser.contextualIdentities.update(match.cookieStoreId, {name: syncIdentity.name, color: syncIdentity.color, icon: syncIdentity.icon});
} }
} }
/*
* Checks for site previously assigned. If it exists, and has the same container assignment,
* the assignment is kept. If it exists, but has a different assignment, the user is prompted
* (not yet implemented). If it does not exist, it is created.
*/
async function reconcileSiteAssignments(inSync) {
const assignedSitesBrowser = await assignManager.storageArea.getAssignedSites(); const assignedSitesBrowser = await assignManager.storageArea.getAssignedSites();
console.log(assignedSitesBrowser); console.log(assignedSitesBrowser);
const syncAssignedSites = inSync.assignedSites; const syncAssignedSites = inSync.assignedSites;
@ -670,10 +688,10 @@ async function restoreFirstRun(inSync) {
const browserCookieStoreId = "firefox-container-" + assignedSitesBrowser[key].userContextId; const browserCookieStoreId = "firefox-container-" + assignedSitesBrowser[key].userContextId;
if (inSync.cookieStoreIDmap[syncCookieStoreId] === identityState.storageArea.get(browserCookieStoreId).macAddonUUID) { if (inSync.cookieStoreIDmap[syncCookieStoreId] === identityState.storageArea.get(browserCookieStoreId).macAddonUUID) {
continue; continue;
} else {
// ask user
} }
} else { // TODO: if uuids are not the same, ask user where to assign the site.
continue;
}
const data = syncAssignedSites[key]; const data = syncAssignedSites[key];
console.log("data", data); console.log("data", data);
const newUUID = inSync.cookieStoreIDmap["firefox-container-" + data.userContextId]; const newUUID = inSync.cookieStoreIDmap["firefox-container-" + data.userContextId];
@ -685,9 +703,6 @@ async function restoreFirstRun(inSync) {
data data
); );
} }
}
backup();
addContextualIdentityListeners(backup);
} }
async function runSync() { async function runSync() {