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) {
|
async backup(options) {
|
||||||
if (SYNC_DEBUG) console.log("backup");
|
|
||||||
// remove listeners to avoid an infinite loop!
|
// remove listeners to avoid an infinite loop!
|
||||||
await browser.storage.onChanged.removeListener(
|
await browser.storage.onChanged.removeListener(
|
||||||
sync.storageArea.onChangedListener);
|
sync.storageArea.onChangedListener);
|
||||||
|
|
||||||
await removeContextualIdentityListeners();
|
await removeContextualIdentityListeners();
|
||||||
|
|
||||||
await updateSyncIdentities();
|
await updateSyncIdentities();
|
||||||
|
@ -55,10 +53,10 @@ const sync = {
|
||||||
await removeFromDeletedSitesList(options.undelete);
|
await removeFromDeletedSitesList(options.undelete);
|
||||||
if (SYNC_DEBUG) {
|
if (SYNC_DEBUG) {
|
||||||
const storage = await sync.storageArea.get();
|
const storage = await sync.storageArea.get();
|
||||||
console.log("in sync: ", storage);
|
console.log("inSync: ", storage);
|
||||||
const localStorage = await browser.storage.local.get();
|
const localStorage = await browser.storage.local.get();
|
||||||
console.log("inLocal:", localStorage);
|
console.log("inLocal:", localStorage);
|
||||||
console.log("indents: ", await browser.contextualIdentities.query({}));
|
console.log("idents: ", await browser.contextualIdentities.query({}));
|
||||||
}
|
}
|
||||||
browser.storage.onChanged.addListener(
|
browser.storage.onChanged.addListener(
|
||||||
sync.storageArea.onChangedListener);
|
sync.storageArea.onChangedListener);
|
||||||
|
@ -139,7 +137,7 @@ const sync = {
|
||||||
},
|
},
|
||||||
|
|
||||||
onChangedListener(changes, areaName) {
|
onChangedListener(changes, areaName) {
|
||||||
if (areaName === "sync") runSync();
|
if (areaName === "sync") sync.runSync();
|
||||||
},
|
},
|
||||||
|
|
||||||
async addToDeletedList(changeInfo) {
|
async addToDeletedList(changeInfo) {
|
||||||
|
@ -154,54 +152,42 @@ const sync = {
|
||||||
},
|
},
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
const errorHandledInitSync = () => {
|
const errorHandledRunSync = () => {
|
||||||
this.initSync().catch((error)=> {
|
this.runSync().catch((error)=> {
|
||||||
console.error("Error from initSync", error);
|
console.error("Error from runSync", error);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
browser.runtime.onInstalled.addListener(errorHandledInitSync);
|
browser.runtime.onInstalled.addListener(errorHandledRunSync);
|
||||||
browser.runtime.onStartup.addListener(errorHandledInitSync);
|
browser.runtime.onStartup.addListener(errorHandledRunSync);
|
||||||
},
|
},
|
||||||
|
|
||||||
async initSync() {
|
async runSync() {
|
||||||
const syncInfo = await sync.storageArea.get();
|
|
||||||
const localInfo = await browser.storage.local.get();
|
|
||||||
if (SYNC_DEBUG) {
|
if (SYNC_DEBUG) {
|
||||||
|
const syncInfo = await sync.storageArea.get();
|
||||||
|
const localInfo = await browser.storage.local.get();
|
||||||
console.log("inSync: ", syncInfo);
|
console.log("inSync: ", syncInfo);
|
||||||
console.log("inLocal: ", localInfo);
|
console.log("inLocal: ", localInfo);
|
||||||
console.log("indents: ", await browser.contextualIdentities.query({}));
|
console.log("indents: ", await browser.contextualIdentities.query({}));
|
||||||
}
|
}
|
||||||
const beenSynced = await assignManager.storageArea.getSynced();
|
browser.storage.onChanged.removeListener(
|
||||||
if (beenSynced){
|
sync.storageArea.onChangedListener);
|
||||||
await runSync();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
await runFirstSync();
|
console.log("no sync storage, backing up...");
|
||||||
},
|
await sync.storageArea.backup();
|
||||||
|
return; },
|
||||||
};
|
};
|
||||||
|
|
||||||
sync.init();
|
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() {
|
async function restore() {
|
||||||
console.log("restore");
|
console.log("restore");
|
||||||
await reconcileIdentities();
|
await reconcileIdentities();
|
||||||
|
@ -209,30 +195,6 @@ async function restore() {
|
||||||
await sync.storageArea.backup();
|
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
|
* 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
|
* 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}`);
|
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 = [
|
const syncCIListenerList = [
|
||||||
sync.storageArea.backup,
|
sync.storageArea.backup,
|
||||||
sync.storageArea.addToDeletedList,
|
sync.storageArea.addToDeletedList,
|
||||||
|
|
|
@ -12,22 +12,6 @@ browser.tests = {
|
||||||
|
|
||||||
await this.setState({}, LOCAL_DATA, TEST_CONTAINERS);
|
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();
|
await identityState.storageArea.cleanup();
|
||||||
|
|
||||||
const macConfigs = await browser.storage.local.get();
|
const macConfigs = await browser.storage.local.get();
|
||||||
|
@ -50,7 +34,7 @@ browser.tests = {
|
||||||
|
|
||||||
await this.setState({}, LOCAL_DATA, TEST_CONTAINERS);
|
await this.setState({}, LOCAL_DATA, TEST_CONTAINERS);
|
||||||
|
|
||||||
await sync.initSync();
|
await sync.runSync();
|
||||||
|
|
||||||
const getSync = await browser.storage.sync.get();
|
const getSync = await browser.storage.sync.get();
|
||||||
const getAssignedSites =
|
const getAssignedSites =
|
||||||
|
@ -87,7 +71,7 @@ browser.tests = {
|
||||||
|
|
||||||
await this.setState(SYNC_DATA, LOCAL_DATA, TEST_CONTAINERS, TEST_ASSIGNMENTS);
|
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 getSync = await browser.storage.sync.get();
|
||||||
const getAssignedSites =
|
const getAssignedSites =
|
||||||
|
@ -131,7 +115,7 @@ browser.tests = {
|
||||||
DUPE_TEST_ASSIGNMENTS
|
DUPE_TEST_ASSIGNMENTS
|
||||||
);
|
);
|
||||||
|
|
||||||
await sync.initSync();
|
await sync.runSync();
|
||||||
|
|
||||||
const getSync = await browser.storage.sync.get();
|
const getSync = await browser.storage.sync.get();
|
||||||
const getAssignedSites =
|
const getAssignedSites =
|
||||||
|
|
Loading…
Add table
Reference in a new issue