popupWidth setting isn't a special sync case anymore

This commit is contained in:
tophf 2017-08-13 17:33:57 +03:00
parent d49e44ddc1
commit ede1187b31

View File

@ -193,30 +193,21 @@ var prefs = new function Prefs() {
if (!BG || BG === window) { if (!BG || BG === window) {
affectsIcon.forEach(key => this.broadcast(key, values[key], {sync: false})); affectsIcon.forEach(key => this.broadcast(key, values[key], {sync: false}));
getSync().get('settings', ({settings: synced} = {}) => { const importFromSync = synced => {
if (synced) { for (const key in defaults) {
for (const key in defaults) { if (key in synced) {
if (key === 'popupWidth' && synced[key] !== values.popupWidth) { this.set(key, synced[key], {sync: false});
// this is a fix for the period when popupWidth wasn't synced
// TODO: remove it in a couple of months
continue;
}
if (key in synced) {
this.set(key, synced[key], {sync: false});
}
} }
} }
}); };
getSync().get('settings', ({settings}) => importFromSync(settings));
chrome.storage.onChanged.addListener((changes, area) => { chrome.storage.onChanged.addListener((changes, area) => {
if (area === 'sync' && 'settings' in changes) { if (area === 'sync' && 'settings' in changes) {
const synced = changes.settings.newValue; const synced = changes.settings.newValue;
if (synced) { if (synced) {
for (const key in defaults) { importFromSync(synced);
if (key in synced) {
this.set(key, synced[key], {sync: false});
}
}
} else { } else {
// user manually deleted our settings, we'll recreate them // user manually deleted our settings, we'll recreate them
getSync().set({'settings': values}); getSync().set({'settings': values});