This commit is contained in:
Raymond Hill 2018-02-21 13:29:36 -05:00
parent 6b7d8e75f4
commit a81d2a759b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 78 additions and 15 deletions

View File

@ -75,7 +75,7 @@ var µBlock = (function() { // jshint ignore:line
hiddenSettingsDefault: hiddenSettingsDefault,
hiddenSettings: (function() {
var out = objectAssign({}, hiddenSettingsDefault),
json = vAPI.localStorage.getItem('hiddenSettings');
json = vAPI.localStorage.getItem('immediateHiddenSettings');
if ( typeof json === 'string' ) {
try {
var o = JSON.parse(json);
@ -90,6 +90,8 @@ var µBlock = (function() { // jshint ignore:line
catch(ex) {
}
}
// Remove once 1.15.12+ is widespread.
vAPI.localStorage.removeItem('hiddenSettings');
return out;
})(),

View File

@ -730,7 +730,7 @@ var backupUserData = function(callback) {
version: vAPI.app.version,
userSettings: µb.userSettings,
selectedFilterLists: µb.selectedFilterLists,
hiddenSettingsString: µb.stringFromHiddenSettings(),
hiddenSettings: µb.hiddenSettings,
netWhitelist: µb.stringFromWhitelist(µb.netWhitelist),
dynamicFilteringString: µb.permanentFirewall.toString(),
urlFilteringString: µb.permanentURLFiltering.toString(),
@ -764,8 +764,14 @@ var restoreUserData = function(request) {
var onAllRemoved = function() {
µBlock.saveLocalSettings();
vAPI.storage.set(userData.userSettings);
µb.hiddenSettingsFromString(userData.hiddenSettingsString || '');
var hiddenSettings = userData.hiddenSettings;
if ( hiddenSettings instanceof Object === false ) {
hiddenSettings = µBlock.hiddenSettingsFromString(
userData.hiddenSettingsString || ''
);
}
vAPI.storage.set({
hiddenSettings: hiddenSettings,
netWhitelist: userData.netWhitelist || '',
dynamicFilteringString: userData.dynamicFilteringString || '',
urlFilteringString: userData.urlFilteringString || '',
@ -791,12 +797,13 @@ var restoreUserData = function(request) {
// storage
vAPI.cacheStorage.clear();
vAPI.storage.clear(onAllRemoved);
vAPI.localStorage.removeItem('immediateHiddenSettings');
};
var resetUserData = function() {
vAPI.cacheStorage.clear();
vAPI.storage.clear();
vAPI.localStorage.removeItem('hiddenSettings');
vAPI.localStorage.removeItem('immediateHiddenSettings');
// Keep global counts, people can become quite attached to numbers
µb.saveLocalSettings();
@ -988,7 +995,8 @@ var onMessage = function(request, sender, callback) {
break;
case 'writeHiddenSettings':
µb.hiddenSettingsFromString(request.content);
µb.hiddenSettings = µb.hiddenSettingsFromString(request.content);
µb.saveHiddenSettings();
break;
default:

View File

@ -80,7 +80,48 @@
/******************************************************************************/
// For now, only boolean type is supported.
µBlock.loadHiddenSettings = function() {
var onLoaded = function(bin) {
if ( bin instanceof Object === false ) { return; }
var µb = µBlock,
hs = bin.hiddenSettings;
// Remove following condition once 1.15.12+ is widespread.
if (
hs instanceof Object === false &&
typeof bin.hiddenSettingsString === 'string'
) {
vAPI.storage.remove('hiddenSettingsString');
hs = µBlock.hiddenSettingsFromString(bin.hiddenSettingsString);
}
if ( hs instanceof Object ) {
var hsDefault = µb.hiddenSettingsDefault;
for ( var key in hsDefault ) {
if (
hsDefault.hasOwnProperty(key) &&
hs.hasOwnProperty(key) &&
typeof hs[key] === typeof hsDefault[key]
) {
µb.hiddenSettings[key] = hs[key];
}
}
}
if ( vAPI.localStorage.getItem('immediateHiddenSettings') === null ) {
µb.saveImmediateHiddenSettings();
}
};
vAPI.storage.get(
[ 'hiddenSettings', 'hiddenSettingsString'],
onLoaded
);
};
µBlock.saveHiddenSettings = function(callback) {
vAPI.storage.set({ hiddenSettings: this.hiddenSettings, callback });
this.saveImmediateHiddenSettings();
};
/******************************************************************************/
µBlock.hiddenSettingsFromString = function(raw) {
var out = objectAssign({}, this.hiddenSettingsDefault),
@ -114,19 +155,13 @@
break;
}
}
this.hiddenSettings = out;
vAPI.localStorage.setItem('hiddenSettings', JSON.stringify(out));
vAPI.storage.set({ hiddenSettingsString: this.stringFromHiddenSettings() });
return out;
};
/******************************************************************************/
µBlock.stringFromHiddenSettings = function() {
var out = [],
keys = Object.keys(this.hiddenSettings).sort(),
key;
for ( var i = 0; i < keys.length; i++ ) {
key = keys[i];
keys = Object.keys(this.hiddenSettings).sort();
for ( var key of keys ) {
out.push(key + ' ' + this.hiddenSettings[key]);
}
return out.join('\n');
@ -134,6 +169,24 @@
/******************************************************************************/
// These settings must be available immediately on startup, without delay
// through the vAPI.localStorage. Add/remove settings as needed.
µBlock.saveImmediateHiddenSettings = function() {
vAPI.localStorage.setItem(
'immediateHiddenSettings',
JSON.stringify({
suspendTabsUntilReady: this.hiddenSettings.suspendTabsUntilReady,
userResourcesLocation: this.hiddenSettings.userResourcesLocation
})
);
};
// Do this here to have these hidden settings loaded ASAP.
µBlock.loadHiddenSettings();
/******************************************************************************/
µBlock.savePermanentFirewallRules = function() {
this.keyvalSetOne('dynamicFilteringString', this.permanentFirewall.toString());
};