mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-16 23:42:39 +01:00
Safari storage migration: code review
This commit is contained in:
parent
3ca6daac73
commit
63b846cf5f
@ -223,49 +223,6 @@
|
|||||||
};
|
};
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
if(!safari.extension.settings.migratedStorage) {
|
|
||||||
var migrationMap = {
|
|
||||||
"cached_asset_content://assets/user/filters.txt": "userFilters"
|
|
||||||
};
|
|
||||||
|
|
||||||
var delayed = [];
|
|
||||||
|
|
||||||
vAPI.storage.preferences = {
|
|
||||||
get: function(a, b) {
|
|
||||||
delayed.push(settingsStorage.get.bind(settingsStorage, a, b));
|
|
||||||
},
|
|
||||||
set: function(a, b) {
|
|
||||||
delayed.push(settingsStorage.set.bind(settingsStorage, a, b));
|
|
||||||
},
|
|
||||||
remove: function(a, b) {
|
|
||||||
delayed.push(settingsStorage.remove.bind(settingsStorage, a, b));
|
|
||||||
},
|
|
||||||
clear: function() {
|
|
||||||
delayed.push(settingsStorage.clear.bind(settingsStorage));
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
localforage.iterate(function(value, key) {
|
|
||||||
if(migrationMap[key]) {
|
|
||||||
safari.extension.settings[migrationMap[key]] = value;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(key.lastIndexOf("cached_asset", 0) === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
safari.extension.settings[key] = value;
|
|
||||||
localforage.removeItem(key);
|
|
||||||
}, function() {
|
|
||||||
var func;
|
|
||||||
while(func = delayed.pop()) {
|
|
||||||
func();
|
|
||||||
}
|
|
||||||
delayed = null;
|
|
||||||
vAPI.storage.preferences = settingsStorage;
|
|
||||||
});
|
|
||||||
safari.extension.settings.migratedStorage = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var settingsStorage = {
|
var settingsStorage = {
|
||||||
_storage: safari.extension.settings,
|
_storage: safari.extension.settings,
|
||||||
get: function(keys, callback) {
|
get: function(keys, callback) {
|
||||||
@ -340,6 +297,51 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
vAPI.storage.preferences = settingsStorage;
|
||||||
|
|
||||||
|
if(!safari.extension.settings.migratedStorage) { // if we haven't already migrated
|
||||||
|
var migrationMap = {
|
||||||
|
"cached_asset_content://assets/user/filters.txt": "userFilters"
|
||||||
|
};
|
||||||
|
|
||||||
|
var delayed = [];
|
||||||
|
|
||||||
|
vAPI.storage.preferences = {
|
||||||
|
get: function(a, b) {
|
||||||
|
delayed.push(settingsStorage.get.bind(settingsStorage, a, b));
|
||||||
|
},
|
||||||
|
set: function(a, b) {
|
||||||
|
delayed.push(settingsStorage.set.bind(settingsStorage, a, b));
|
||||||
|
},
|
||||||
|
remove: function(a, b) {
|
||||||
|
delayed.push(settingsStorage.remove.bind(settingsStorage, a, b));
|
||||||
|
},
|
||||||
|
clear: function() {
|
||||||
|
delayed.push(settingsStorage.clear.bind(settingsStorage));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
localforage.iterate(function(value, key) {
|
||||||
|
if(migrationMap[key]) {
|
||||||
|
safari.extension.settings[migrationMap[key]] = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(key.lastIndexOf("cached_asset", 0) === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
safari.extension.settings[key] = value;
|
||||||
|
localforage.removeItem(key);
|
||||||
|
}, function() {
|
||||||
|
var func;
|
||||||
|
while(func = delayed.pop()) {
|
||||||
|
func();
|
||||||
|
}
|
||||||
|
delayed = null;
|
||||||
|
vAPI.storage.preferences = settingsStorage;
|
||||||
|
});
|
||||||
|
safari.extension.settings.migratedStorage = true;
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.tabs = {
|
vAPI.tabs = {
|
||||||
|
Loading…
Reference in New Issue
Block a user