change reload prevention to something a bit less contrived

This commit is contained in:
Tamius Han 2019-10-24 21:13:45 +02:00
parent 8fde5bb3d6
commit d5a6e8d707

View File

@ -38,11 +38,12 @@ class Settings {
if (changes['uwSettings'] && changes['uwSettings'].newValue) { if (changes['uwSettings'] && changes['uwSettings'].newValue) {
this.logger.log('info', 'settings',"[Settings::<storage/on change>] new settings object:", JSON.parse(changes.uwSettings.newValue)); this.logger.log('info', 'settings',"[Settings::<storage/on change>] new settings object:", JSON.parse(changes.uwSettings.newValue));
} }
const parsedSettings = JSON.parse(changes.uwSettings.newValue);
if(changes['uwSettings'] && changes['uwSettings'].newValue) { if(changes['uwSettings'] && changes['uwSettings'].newValue) {
ths.setActive(JSON.parse(changes.uwSettings.newValue)); ths.setActive(parsedSettings);
} }
if(this.updateCallback) { if(!parsedSettings.preventReload && this.updateCallback) {
try { try {
updateCallback(ths); updateCallback(ths);
} catch (e) { } catch (e) {
@ -289,25 +290,14 @@ class Settings {
if (Debug.debug && Debug.storage) { if (Debug.debug && Debug.storage) {
console.log("[Settings::save] Saving active settings:", this.active); console.log("[Settings::save] Saving active settings:", this.active);
} }
this.active.preventReload = undefined;
await this.set(this.active); await this.set(this.active);
} }
async saveWithoutReload() { async saveWithoutReload() {
if (currentBrowser.firefox) { this.active.preventReload = true;
browser.storage.onChanged.removeListener(this.storageChangeListener); await this.set(this.active);
} else if (currentBrowser.chrome) {
chrome.storage.onChanged.removeListener(this.storageChangeListener);
}
await this.save();
if(currentBrowser.firefox) {
browser.storage.onChanged.addListener(this.storageChangeListener);
} else if (currentBrowser.chrome) {
chrome.storage.onChanged.addListener(this.storageChangeListener);
}
} }
async rollback() { async rollback() {