cherry pick sync fix from main

This commit is contained in:
eric@ericjung.net 2023-12-05 09:33:49 -07:00
parent 90a8e76025
commit 3204e15c54
1 changed files with 8 additions and 4 deletions

View File

@ -35,16 +35,20 @@ export class Sync {
await this.getSync(pref); // check storage.sync await this.getSync(pref); // check storage.sync
} }
static hasOldData(obj) {
// FP v3 OR FP v7
return Object.hasOwn(obj, 'settings') || Object.hasOwn(obj, 'foxyProxyEdition');
}
static async getSync(pref) { static async getSync(pref) {
if (!pref.sync) { return; } if (!pref.sync) { return; }
const syncPref = await browser.storage.sync.get(); const syncPref = await browser.storage.sync.get();
// check sync from old version 3-7 // check sync from old version 3-7
if (!Object.keys(pref)[0] && if ((!Object.keys(pref)[0] || this.hasOldData(pref)) && this.hasOldData(syncPref)) { // (local has no data OR has old data) AND sync has old data
(Object.hasOwn(syncPref, 'settings') || Object.hasOwn(syncPref, 'foxyProxyEdition'))) { Object.keys(syncPref).forEach(i => pref[i] = syncPref[i]); // set sync data to pref to migrate next in background.js
Object.keys(syncPref).forEach(i => pref[i] = syncPref[i]); return;
return;
} }
// convert object to array & filter proxies // convert object to array & filter proxies