fixed bug that was showing all assigned site in the create new container panel
This commit is contained in:
parent
34180aa2d5
commit
6184dbb656
2 changed files with 27 additions and 149 deletions
|
@ -37,11 +37,9 @@ const sync = {
|
|||
},
|
||||
|
||||
async backup(options) {
|
||||
if (SYNC_DEBUG) console.log("backup");
|
||||
// remove listeners to avoid an infinite loop!
|
||||
await browser.storage.onChanged.removeListener(
|
||||
sync.storageArea.onChangedListener);
|
||||
|
||||
await removeContextualIdentityListeners();
|
||||
|
||||
await updateSyncIdentities();
|
||||
|
@ -55,10 +53,10 @@ const sync = {
|
|||
await removeFromDeletedSitesList(options.undelete);
|
||||
if (SYNC_DEBUG) {
|
||||
const storage = await sync.storageArea.get();
|
||||
console.log("in sync: ", storage);
|
||||
console.log("inSync: ", storage);
|
||||
const localStorage = await browser.storage.local.get();
|
||||
console.log("inLocal:", localStorage);
|
||||
console.log("indents: ", await browser.contextualIdentities.query({}));
|
||||
console.log("idents: ", await browser.contextualIdentities.query({}));
|
||||
}
|
||||
browser.storage.onChanged.addListener(
|
||||
sync.storageArea.onChangedListener);
|
||||
|
@ -139,7 +137,7 @@ const sync = {
|
|||
},
|
||||
|
||||
onChangedListener(changes, areaName) {
|
||||
if (areaName === "sync") runSync();
|
||||
if (areaName === "sync") sync.runSync();
|
||||
},
|
||||
|
||||
async addToDeletedList(changeInfo) {
|
||||
|
@ -154,54 +152,42 @@ const sync = {
|
|||
},
|
||||
|
||||
init() {
|
||||
const errorHandledInitSync = () => {
|
||||
this.initSync().catch((error)=> {
|
||||
console.error("Error from initSync", error);
|
||||
const errorHandledRunSync = () => {
|
||||
this.runSync().catch((error)=> {
|
||||
console.error("Error from runSync", error);
|
||||
});
|
||||
};
|
||||
browser.runtime.onInstalled.addListener(errorHandledInitSync);
|
||||
browser.runtime.onStartup.addListener(errorHandledInitSync);
|
||||
browser.runtime.onInstalled.addListener(errorHandledRunSync);
|
||||
browser.runtime.onStartup.addListener(errorHandledRunSync);
|
||||
},
|
||||
|
||||
async initSync() {
|
||||
const syncInfo = await sync.storageArea.get();
|
||||
const localInfo = await browser.storage.local.get();
|
||||
async runSync() {
|
||||
if (SYNC_DEBUG) {
|
||||
const syncInfo = await sync.storageArea.get();
|
||||
const localInfo = await browser.storage.local.get();
|
||||
console.log("inSync: ", syncInfo);
|
||||
console.log("inLocal: ", localInfo);
|
||||
console.log("indents: ", await browser.contextualIdentities.query({}));
|
||||
}
|
||||
const beenSynced = await assignManager.storageArea.getSynced();
|
||||
if (beenSynced){
|
||||
await runSync();
|
||||
browser.storage.onChanged.removeListener(
|
||||
sync.storageArea.onChangedListener);
|
||||
removeContextualIdentityListeners();
|
||||
console.log("runSync");
|
||||
await identityState.storageArea.cleanup();
|
||||
|
||||
if (await sync.storageArea.hasSyncStorage()){
|
||||
await sync.storageArea.cleanup();
|
||||
console.log("storage found, attempting to restore ...");
|
||||
await restore();
|
||||
return;
|
||||
}
|
||||
await runFirstSync();
|
||||
},
|
||||
console.log("no sync storage, backing up...");
|
||||
await sync.storageArea.backup();
|
||||
return; },
|
||||
};
|
||||
|
||||
sync.init();
|
||||
|
||||
|
||||
async function runSync() {
|
||||
browser.storage.onChanged.removeListener(
|
||||
sync.storageArea.onChangedListener);
|
||||
removeContextualIdentityListeners();
|
||||
console.log("runSync");
|
||||
await identityState.storageArea.cleanup();
|
||||
|
||||
|
||||
if (await sync.storageArea.hasSyncStorage()){
|
||||
await sync.storageArea.cleanup();
|
||||
console.log("storage found, attempting to restore ...");
|
||||
await restore();
|
||||
return;
|
||||
}
|
||||
console.log("no sync storage, backing up...");
|
||||
await sync.storageArea.backup();
|
||||
return;
|
||||
}
|
||||
|
||||
async function restore() {
|
||||
console.log("restore");
|
||||
await reconcileIdentities();
|
||||
|
@ -209,30 +195,6 @@ async function restore() {
|
|||
await sync.storageArea.backup();
|
||||
}
|
||||
|
||||
async function runFirstSync() {
|
||||
console.log("runFirstSync");
|
||||
// looks for abandoned identities keys in local storage, and identities
|
||||
// not in localstorage (which also adds a uuid)
|
||||
await identityState.storageArea.cleanup();
|
||||
|
||||
if (await sync.storageArea.hasSyncStorage()){
|
||||
await sync.storageArea.cleanup();
|
||||
console.log("storage found, attempting to restore ...");
|
||||
await restoreFirstRun();
|
||||
}else {
|
||||
console.log("no sync storage, backing up...");
|
||||
await sync.storageArea.backup();
|
||||
}
|
||||
await assignManager.storageArea.setSynced();
|
||||
}
|
||||
|
||||
async function restoreFirstRun() {
|
||||
console.log("restoreFirstRun");
|
||||
await reconcileIdentities();
|
||||
await reconcileSiteAssignments();
|
||||
await sync.storageArea.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
|
||||
|
@ -421,74 +383,6 @@ async function setAssignmentWithUUID (newUUID, assignedSite, urlKey) {
|
|||
throw new Error (`No cookieStoreId found for: ${newUUID}, ${urlKey}`);
|
||||
}
|
||||
|
||||
/*
|
||||
* Matches uuids in sync to uuids locally, and updates containers accordingly.
|
||||
* If there is no match, it creates the new container.
|
||||
*/
|
||||
async function reconcileIdentitiesByUUID() {
|
||||
console.log("reconcileIdentitiesByUUID");
|
||||
const syncIdentities = await sync.storageArea.getStoredObject("identities");
|
||||
const cookieStoreIDmap =
|
||||
await sync.storageArea.getStoredObject("cookieStoreIDmap");
|
||||
|
||||
const deletedIdentityList =
|
||||
await sync.storageArea.getStoredArray("deletedIdentityList");
|
||||
// first remove any deleted identities
|
||||
for (const deletedUUID of deletedIdentityList) {
|
||||
const deletedCookieStoreId =
|
||||
await identityState.lookupCookieStoreId(deletedUUID);
|
||||
if (deletedCookieStoreId){
|
||||
await browser.contextualIdentities.remove(deletedCookieStoreId);
|
||||
}
|
||||
}
|
||||
|
||||
// Lookup all identities in teh cookieStoreIDmap and make sure they
|
||||
// exist locally
|
||||
for (const syncCookieStoreID of Object.keys(cookieStoreIDmap)) {
|
||||
const syncUUID = cookieStoreIDmap[syncCookieStoreID];
|
||||
//find localCookiesStoreID by looking up the syncUUID
|
||||
const localCookieStoreID =
|
||||
await identityState.lookupCookieStoreId(syncUUID);
|
||||
// get correct indentity info from sync
|
||||
const identityInfo =
|
||||
findIdentityFromSync(syncCookieStoreID, syncIdentities);
|
||||
if (localCookieStoreID) {
|
||||
if (SYNC_DEBUG) {
|
||||
const getIdent =
|
||||
await browser.contextualIdentities.get(localCookieStoreID);
|
||||
if (getIdent.name !== identityInfo.name) {
|
||||
console.log(getIdent.name, "Change name: ", identityInfo.name);
|
||||
}
|
||||
if (getIdent.color !== identityInfo.color) {
|
||||
console.log(getIdent.name, "Change color: ", identityInfo.color);
|
||||
}
|
||||
if (getIdent.icon !== identityInfo.icon) {
|
||||
console.log(getIdent.name, "Change icon: ", identityInfo.icon);
|
||||
}
|
||||
}
|
||||
|
||||
// update the local container with the sync data
|
||||
await browser.contextualIdentities
|
||||
.update(localCookieStoreID, identityInfo);
|
||||
continue;
|
||||
}
|
||||
//not found, create new with same UUID
|
||||
console.log("new Identity: ", identityInfo.name);
|
||||
const newIdentity =
|
||||
await browser.contextualIdentities.create(identityInfo);
|
||||
await identityState.updateUUID(newIdentity.cookieStoreId, syncUUID);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function findIdentityFromSync(cookieStoreId, identitiesList){
|
||||
for (const identity of identitiesList) {
|
||||
const { name, color, icon } = identity;
|
||||
if (identity.cookieStoreId === cookieStoreId)
|
||||
return { name, color, icon };
|
||||
}
|
||||
}
|
||||
|
||||
const syncCIListenerList = [
|
||||
sync.storageArea.backup,
|
||||
sync.storageArea.addToDeletedList,
|
||||
|
|
|
@ -12,22 +12,6 @@ browser.tests = {
|
|||
|
||||
await this.setState({}, LOCAL_DATA, TEST_CONTAINERS);
|
||||
|
||||
// await this.removeAllContainers();
|
||||
// const localData = {
|
||||
// "browserActionBadgesClicked": [ "6.1.1" ],
|
||||
// "containerTabsOpened": 7,
|
||||
// "identitiesState@@_firefox-default": { "hiddenTabs": [] },
|
||||
// "onboarding-stage": 5,
|
||||
// "identitiesState@@_firefox-container-7": { "hiddenTabs": [] }
|
||||
// };
|
||||
// await browser.storage.local.clear();
|
||||
// await browser.storage.local.set(localData);
|
||||
// // async function assignIdentities () {
|
||||
// for (const containerInputSet of TEST_CONTAINERS) {
|
||||
// await browser.contextualIdentities.create(containerInputSet);
|
||||
// }
|
||||
// }
|
||||
// await assignIdentities();
|
||||
await identityState.storageArea.cleanup();
|
||||
|
||||
const macConfigs = await browser.storage.local.get();
|
||||
|
@ -50,7 +34,7 @@ browser.tests = {
|
|||
|
||||
await this.setState({}, LOCAL_DATA, TEST_CONTAINERS);
|
||||
|
||||
await sync.initSync();
|
||||
await sync.runSync();
|
||||
|
||||
const getSync = await browser.storage.sync.get();
|
||||
const getAssignedSites =
|
||||
|
@ -87,7 +71,7 @@ browser.tests = {
|
|||
|
||||
await this.setState(SYNC_DATA, LOCAL_DATA, TEST_CONTAINERS, TEST_ASSIGNMENTS);
|
||||
|
||||
await sync.initSync();
|
||||
await sync.runSync();
|
||||
|
||||
const getSync = await browser.storage.sync.get();
|
||||
const getAssignedSites =
|
||||
|
@ -131,7 +115,7 @@ browser.tests = {
|
|||
DUPE_TEST_ASSIGNMENTS
|
||||
);
|
||||
|
||||
await sync.initSync();
|
||||
await sync.runSync();
|
||||
|
||||
const getSync = await browser.storage.sync.get();
|
||||
const getAssignedSites =
|
||||
|
|
Loading…
Add table
Reference in a new issue