From 0447e54b1c07ba1e456b44efc83feaa83853262d Mon Sep 17 00:00:00 2001 From: Kendall Werts Date: Thu, 23 Jan 2020 13:47:19 -0600 Subject: [PATCH] review fedback --- src/js/background/assignManager.js | 6 ++-- src/js/background/identityState.js | 14 ++++++---- src/js/background/sync.js | 44 +++++++++++++----------------- src/js/options.js | 1 - src/js/popup.js | 4 +-- 5 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/js/background/assignManager.js b/src/js/background/assignManager.js index a8f22e3..91ff8e6 100644 --- a/src/js/background/assignManager.js +++ b/src/js/background/assignManager.js @@ -78,7 +78,9 @@ const assignManager = { [siteStoreKey]: data }); const syncEnabled = await this.getSyncEnabled(); - if (backup && syncEnabled) await sync.storageArea.backup({undeleteSiteStoreKey: siteStoreKey}); + if (backup && syncEnabled) { + await sync.storageArea.backup({undeleteSiteStoreKey: siteStoreKey}); + } return; }, @@ -135,7 +137,7 @@ const assignManager = { localIdentity => localIdentity.cookieStoreId === cookieStoreId ); if (!match) { - await this.remove(configKey.replace(/^siteContainerMap@@_/, "https://")); + await this.remove(configKey); continue; } const updatedSiteAssignment = macConfigs[configKey]; diff --git a/src/js/background/identityState.js b/src/js/background/identityState.js index 673c0a2..9ff2bb2 100644 --- a/src/js/background/identityState.js +++ b/src/js/background/identityState.js @@ -49,6 +49,12 @@ const identityState = { */ async upgradeData() { 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(); for(const configKey of Object.keys(macConfigs)) { if (configKey.includes("identitiesState@@_")) { @@ -61,16 +67,12 @@ const identityState = { await this.remove(cookieStoreId); continue; } + console.log(macConfigs, configKey); if (!macConfigs[configKey].macAddonUUID) { 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; const macConfigs = await this.storageArea.area.get(); for(const configKey of Object.keys(macConfigs)) { - if (configKey === this.getContainerStoreKey(cookieStoreIdKey)) { + if (configKey === this.storageArea.getContainerStoreKey(cookieStoreIdKey)) { return macConfigs[configKey].macAddonUUID; } } diff --git a/src/js/background/sync.js b/src/js/background/sync.js index d79c16b..9546d7c 100644 --- a/src/js/background/sync.js +++ b/src/js/background/sync.js @@ -118,6 +118,7 @@ const sync = { await this.deleteSite(options.siteStoreKey); if (options && options.undeleteSiteStoreKey) await removeFromDeletedSitesList(options.undeleteSiteStoreKey); + if (SYNC_DEBUG) console.log("Backed up!"); await sync.checkForListenersMaybeAdd(); @@ -270,26 +271,23 @@ const sync = { return; }, - async addContextualIdentityListeners(listenerList) { - if(!listenerList) listenerList = syncCIListenerList; - await browser.contextualIdentities.onCreated.addListener(listenerList[0]); - await browser.contextualIdentities.onRemoved.addListener(listenerList[1]); - await browser.contextualIdentities.onUpdated.addListener(listenerList[2]); + async addContextualIdentityListeners() { + await browser.contextualIdentities.onCreated.addListener(sync.storageArea.backup); + await browser.contextualIdentities.onRemoved.addListener(sync.storageArea.addToDeletedList); + await browser.contextualIdentities.onUpdated.addListener(sync.storageArea.backup); }, - async removeContextualIdentityListeners(listenerList) { - if(!listenerList) listenerList = syncCIListenerList; - await browser.contextualIdentities.onCreated.removeListener(listenerList[0]); - await browser.contextualIdentities.onRemoved.removeListener(listenerList[1]); - await browser.contextualIdentities.onUpdated.removeListener(listenerList[2]); + async removeContextualIdentityListeners() { + await browser.contextualIdentities.onCreated.removeListener(sync.storageArea.backup); + await browser.contextualIdentities.onRemoved.removeListener(sync.storageArea.addToDeletedList); + await browser.contextualIdentities.onUpdated.removeListener(sync.storageArea.backup); }, - async hasContextualIdentityListeners(listenerList) { - if(!listenerList) listenerList = syncCIListenerList; + async hasContextualIdentityListeners() { return ( - await browser.contextualIdentities.onCreated.hasListener(listenerList[0]) && - await browser.contextualIdentities.onRemoved.hasListener(listenerList[1]) && - await browser.contextualIdentities.onUpdated.hasListener(listenerList[2]) + await browser.contextualIdentities.onCreated.hasListener(sync.storageArea.backup) && + await browser.contextualIdentities.onRemoved.hasListener(sync.storageArea.addToDeletedList) && + await browser.contextualIdentities.onUpdated.hasListener(sync.storageArea.backup) ); }, @@ -360,7 +358,9 @@ async function reconcileIdentities(){ await ifNoMatch(syncIdentity); continue; } - await ifNamesMatch(syncIdentity, localMatch); + + // Names match, so use the info from Sync + await updateIdentityWithSyncInfo(syncIdentity, localMatch); continue; } // 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 if (syncIdentity.color !== localMatch.color || syncIdentity.icon !== localMatch.icon) { @@ -474,7 +474,7 @@ async function reconcileSiteAssignments() { if (Object.prototype.hasOwnProperty.call(assignedSitesLocal,siteStoreKey)) { assignManager .storageArea - .remove(siteStoreKey.replace(/^siteContainerMap@@_/, "https://")); + .remove(siteStoreKey); } } @@ -548,7 +548,7 @@ async function setAssignmentWithUUID(assignedSite, urlKey) { assignedSite.userContextId = cookieStoreId .replace(/^firefox-container-/, ""); await assignManager.storageArea.set( - urlKey.replace(/^siteContainerMap@@_/, "https://"), + urlKey, assignedSite, false, false @@ -557,9 +557,3 @@ async function setAssignmentWithUUID(assignedSite, urlKey) { } throw new Error (`No cookieStoreId found for: ${uuid}, ${urlKey}`); } - -const syncCIListenerList = [ - sync.storageArea.backup, - sync.storageArea.addToDeletedList, - sync.storageArea.backup -]; diff --git a/src/js/options.js b/src/js/options.js index 2f3fa32..c225e63 100644 --- a/src/js/options.js +++ b/src/js/options.js @@ -25,7 +25,6 @@ async function enableDisableSync() { async function restoreOptions() { const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]}); const { syncEnabled } = await browser.storage.local.get("syncEnabled"); - console.log(syncEnabled); if (hasPermission) { document.querySelector("#bookmarksPermissions").checked = true; } diff --git a/src/js/popup.js b/src/js/popup.js index 09611c3..208b18b 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -187,7 +187,7 @@ const Logic = { }; // Handle old style rejection with null and also Promise.reject new style try { - return browser.contextualIdentities.get(cookieStoreId) || defaultContainer; + return await browser.contextualIdentities.get(cookieStoreId) || defaultContainer; } catch (e) { return defaultContainer; } @@ -356,7 +356,7 @@ const Logic = { }, getAssignmentObjectByContainer(userContextId) { - if (userContextId) { + if (!userContextId) { return {}; } return browser.runtime.sendMessage({