mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-01 16:33:06 +01:00
Backup/restore only modified advanced settings
This reduces the size of the backup file and also ensures that default values can be changed.
This commit is contained in:
parent
01de814483
commit
f4aebc9390
@ -886,7 +886,7 @@ const backupUserData = async function() {
|
||||
version: vAPI.app.version,
|
||||
userSettings: µb.userSettings,
|
||||
selectedFilterLists: µb.selectedFilterLists,
|
||||
hiddenSettings: µb.hiddenSettings,
|
||||
hiddenSettings: µb.getModifiedHiddenSettings(),
|
||||
whitelist: µb.arrayFromWhitelist(µb.netWhitelist),
|
||||
// String representation eventually to be deprecated
|
||||
netWhitelist: µb.stringFromWhitelist(µb.netWhitelist),
|
||||
@ -927,12 +927,24 @@ const restoreUserData = async function(request) {
|
||||
|
||||
// Restore user data
|
||||
vAPI.storage.set(userData.userSettings);
|
||||
|
||||
// Restore advanced settings.
|
||||
let hiddenSettings = userData.hiddenSettings;
|
||||
if ( hiddenSettings instanceof Object === false ) {
|
||||
hiddenSettings = µBlock.hiddenSettingsFromString(
|
||||
userData.hiddenSettingsString || ''
|
||||
);
|
||||
}
|
||||
// Discard unknown setting or setting with default value.
|
||||
for ( const key in hiddenSettings ) {
|
||||
if (
|
||||
this.hiddenSettingsDefault.hasOwnProperty(key) === false ||
|
||||
hiddenSettings[key] === this.hiddenSettingsDefault[key]
|
||||
) {
|
||||
delete hiddenSettings[key];
|
||||
}
|
||||
}
|
||||
|
||||
// Whitelist directives can be represented as an array or as a
|
||||
// (eventually to be deprecated) string.
|
||||
let whitelist = userData.whitelist;
|
||||
@ -944,7 +956,7 @@ const restoreUserData = async function(request) {
|
||||
whitelist = userData.netWhitelist.split('\n');
|
||||
}
|
||||
vAPI.storage.set({
|
||||
hiddenSettings: hiddenSettings,
|
||||
hiddenSettings,
|
||||
netWhitelist: whitelist || [],
|
||||
dynamicFilteringString: userData.dynamicFilteringString || '',
|
||||
urlFilteringString: userData.urlFilteringString || '',
|
||||
|
@ -119,17 +119,21 @@
|
||||
// This way the new default values in the future will properly apply for those
|
||||
// which were not modified by the user.
|
||||
|
||||
µBlock.saveHiddenSettings = function() {
|
||||
const bin = { hiddenSettings: {} };
|
||||
µBlock.getModifiedHiddenSettings = function() {
|
||||
const out = {};
|
||||
for ( const prop in this.hiddenSettings ) {
|
||||
if (
|
||||
this.hiddenSettings.hasOwnProperty(prop) &&
|
||||
this.hiddenSettings[prop] !== this.hiddenSettingsDefault[prop]
|
||||
) {
|
||||
bin.hiddenSettings[prop] = this.hiddenSettings[prop];
|
||||
out[prop] = this.hiddenSettings[prop];
|
||||
}
|
||||
}
|
||||
vAPI.storage.set(bin);
|
||||
return out;
|
||||
};
|
||||
|
||||
µBlock.saveHiddenSettings = function() {
|
||||
vAPI.storage.set({ hiddenSettings: this.getModifiedHiddenSettings() });
|
||||
};
|
||||
|
||||
self.addEventListener('hiddenSettingsChanged', ( ) => {
|
||||
|
Loading…
Reference in New Issue
Block a user