made some requested changes
This commit is contained in:
parent
e8f8123c4c
commit
adc1f5ffe6
2 changed files with 28 additions and 43 deletions
|
@ -107,21 +107,6 @@ const assignManager = {
|
||||||
};
|
};
|
||||||
return sites;
|
return sites;
|
||||||
},
|
},
|
||||||
|
|
||||||
// async getAssignedSites(userContextId = null) {
|
|
||||||
// const sites = {};
|
|
||||||
// const siteConfigs = await this.area.get();
|
|
||||||
// for(const key of Object.keys(siteConfigs)) {
|
|
||||||
// if (key.includes("siteContainerMap@@_")) {
|
|
||||||
// if(userContextId==null) {
|
|
||||||
// const site = siteConfigs[key];
|
|
||||||
// sites[key] = site;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return sites;
|
|
||||||
// }
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_neverAsk(m) {
|
_neverAsk(m) {
|
||||||
|
@ -273,8 +258,8 @@ const assignManager = {
|
||||||
this.resetBookmarksMenuItem();
|
this.resetBookmarksMenuItem();
|
||||||
|
|
||||||
// Run when installed and on startup
|
// Run when installed and on startup
|
||||||
browser.runtime.onInstalled.addListener(()=>{this.initSync()});
|
browser.runtime.onInstalled.addListener(this.initSync);
|
||||||
browser.runtime.onStartup.addListener(()=>{this.initSync()});
|
browser.runtime.onStartup.addListener(this.initSync);
|
||||||
},
|
},
|
||||||
|
|
||||||
async resetBookmarksMenuItem() {
|
async resetBookmarksMenuItem() {
|
||||||
|
@ -577,9 +562,9 @@ const assignManager = {
|
||||||
const beenSynced = await assignManager.storageArea.getSynced();
|
const beenSynced = await assignManager.storageArea.getSynced();
|
||||||
if (beenSynced){
|
if (beenSynced){
|
||||||
runSync();
|
runSync();
|
||||||
} else {
|
return;
|
||||||
runFirstSync();
|
|
||||||
}
|
}
|
||||||
|
runFirstSync();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -622,7 +607,7 @@ browser.resetMAC2 = async function () {
|
||||||
browser.storage.sync.set(syncData);
|
browser.storage.sync.set(syncData);
|
||||||
|
|
||||||
// FF2 (intial sync w/ default 4 + 1 with some changes)
|
// FF2 (intial sync w/ default 4 + 1 with some changes)
|
||||||
removeContextualIdentityListeners();
|
removeContextualIdentityListeners(backup);
|
||||||
browser.contextualIdentities.update("firefox-container-2", {color:"purple"});
|
browser.contextualIdentities.update("firefox-container-2", {color:"purple"});
|
||||||
browser.contextualIdentities.update("firefox-container-4", {icon:"pet"});
|
browser.contextualIdentities.update("firefox-container-4", {icon:"pet"});
|
||||||
browser.storage.local.clear();
|
browser.storage.local.clear();
|
||||||
|
@ -632,7 +617,7 @@ browser.resetMAC2 = async function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
async function restore(inSync) {
|
async function restore(inSync) {
|
||||||
removeContextualIdentityListeners();
|
removeContextualIdentityListeners(backup);
|
||||||
const syncIdentities = inSync.identities;
|
const syncIdentities = inSync.identities;
|
||||||
const browserIdentities = await browser.contextualIdentities.query({});
|
const browserIdentities = await browser.contextualIdentities.query({});
|
||||||
|
|
||||||
|
@ -652,11 +637,11 @@ async function restore(inSync) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
backup();
|
backup();
|
||||||
addContextualIdentityListeners();
|
addContextualIdentityListeners(backup);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function restoreFirstRun(inSync) {
|
async function restoreFirstRun(inSync) {
|
||||||
removeContextualIdentityListeners();
|
removeContextualIdentityListeners(backup);
|
||||||
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) {
|
||||||
|
@ -664,7 +649,7 @@ async function restoreFirstRun(inSync) {
|
||||||
const match = browserIdentities.find(compareNames);
|
const match = browserIdentities.find(compareNames);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
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.macUUID);
|
identityState.updateUUID(newIdentity.cookieStoreId, syncIdentity.macAddonUUID);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if (syncIdentity.color === match.color && syncIdentity.icon === match.icon) {
|
if (syncIdentity.color === match.color && syncIdentity.icon === match.icon) {
|
||||||
|
@ -683,7 +668,7 @@ async function restoreFirstRun(inSync) {
|
||||||
if (assignedSitesBrowser.hasOwnProperty(key)) {
|
if (assignedSitesBrowser.hasOwnProperty(key)) {
|
||||||
const syncCookieStoreId = "firefox-container-" + syncAssignedSites[key].userContextId;
|
const syncCookieStoreId = "firefox-container-" + syncAssignedSites[key].userContextId;
|
||||||
const browserCookieStoreId = "firefox-container-" + assignedSitesBrowser[key].userContextId;
|
const browserCookieStoreId = "firefox-container-" + assignedSitesBrowser[key].userContextId;
|
||||||
if (inSync.cookieStoreIDmap[syncCookieStoreId] === identityState.storageArea.get(browserCookieStoreId).macUUID) {
|
if (inSync.cookieStoreIDmap[syncCookieStoreId] === identityState.storageArea.get(browserCookieStoreId).macAddonUUID) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
// ask user
|
// ask user
|
||||||
|
@ -702,7 +687,7 @@ async function restoreFirstRun(inSync) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
backup();
|
backup();
|
||||||
addContextualIdentityListeners();
|
addContextualIdentityListeners(backup);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runSync() {
|
async function runSync() {
|
||||||
|
@ -711,22 +696,22 @@ async function runSync() {
|
||||||
if (Object.entries(inSync).length === 0){
|
if (Object.entries(inSync).length === 0){
|
||||||
console.log("no sync storage, backing up...");
|
console.log("no sync storage, backing up...");
|
||||||
backup();
|
backup();
|
||||||
} else {
|
return;
|
||||||
console.log("storage found, attempting to restore ...");
|
|
||||||
restore(inSync);
|
|
||||||
}
|
}
|
||||||
|
console.log("storage found, attempting to restore ...");
|
||||||
|
restore(inSync);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addContextualIdentityListeners() {
|
function addContextualIdentityListeners(listener) {
|
||||||
browser.contextualIdentities.onCreated.addListener(backup);
|
browser.contextualIdentities.onCreated.addListener(listener);
|
||||||
browser.contextualIdentities.onRemoved.addListener(backup);
|
browser.contextualIdentities.onRemoved.addListener(listener);
|
||||||
browser.contextualIdentities.onUpdated.addListener(backup);
|
browser.contextualIdentities.onUpdated.addListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeContextualIdentityListeners() {
|
function removeContextualIdentityListeners(listener) {
|
||||||
browser.contextualIdentities.onCreated.removeListener(backup);
|
browser.contextualIdentities.onCreated.removeListener(listener);
|
||||||
browser.contextualIdentities.onRemoved.removeListener(backup);
|
browser.contextualIdentities.onRemoved.removeListener(listener);
|
||||||
browser.contextualIdentities.onUpdated.removeListener(backup);
|
browser.contextualIdentities.onUpdated.removeListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runFirstSync() {
|
async function runFirstSync() {
|
||||||
|
|
|
@ -44,7 +44,7 @@ const identityState = {
|
||||||
if (key.includes("identitiesState@@_")) {
|
if (key.includes("identitiesState@@_")) {
|
||||||
const container = containerInfo[key];
|
const container = containerInfo[key];
|
||||||
const cookieStoreId = key.replace(/^identitiesState@@_/, "");
|
const cookieStoreId = key.replace(/^identitiesState@@_/, "");
|
||||||
containers[cookieStoreId] = container.macUUID;
|
containers[cookieStoreId] = container.macAddonUUID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return containers;
|
return containers;
|
||||||
|
@ -69,18 +69,18 @@ const identityState = {
|
||||||
},
|
},
|
||||||
async updateUUID(cookieStoreId, uuid) {
|
async updateUUID(cookieStoreId, uuid) {
|
||||||
const containerState = await this.storageArea.get(cookieStoreId);
|
const containerState = await this.storageArea.get(cookieStoreId);
|
||||||
containerState.macUUID = uuid;
|
containerState.macAddonUUID = uuid;
|
||||||
return this.storageArea.set(cookieStoreId, containerState);
|
return this.storageArea.set(cookieStoreId, containerState);
|
||||||
},
|
},
|
||||||
async addUUID(cookieStoreId) {
|
async addUUID(cookieStoreId) {
|
||||||
return this.updateUUID(cookieStoreId, uuidv4());
|
return this.updateUUID(cookieStoreId, uuidv4());
|
||||||
},
|
},
|
||||||
|
|
||||||
async lookupCookieStoreId(macUUID) {
|
async lookupCookieStoreId(macAddonUUID) {
|
||||||
const macConfigs = await this.storageArea.area.get();
|
const macConfigs = await this.storageArea.area.get();
|
||||||
for(const key of Object.keys(macConfigs)) {
|
for(const key of Object.keys(macConfigs)) {
|
||||||
if (key.includes("identitiesState@@_")) {
|
if (key.includes("identitiesState@@_")) {
|
||||||
if(macConfigs[key].macUUID === macUUID) {
|
if(macConfigs[key].macAddonUUID === macAddonUUID) {
|
||||||
return key.replace(/^firefox-container-@@_/, "");
|
return key.replace(/^firefox-container-@@_/, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ const identityState = {
|
||||||
_createIdentityState() {
|
_createIdentityState() {
|
||||||
return {
|
return {
|
||||||
hiddenTabs: [],
|
hiddenTabs: [],
|
||||||
macUUID: uuidv4()
|
macAddonUUID: uuidv4()
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue