mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Enabled import of older storage versions.
This commit is contained in:
parent
5f74f13de3
commit
f565b8c32e
@ -13,7 +13,7 @@
|
||||
window.scope.settingsMigration = {};
|
||||
scope = window.scope.settingsMigration;
|
||||
}
|
||||
scope.validVersions = [undefined, 0.1, 0.2, 0.3, 0.4];
|
||||
scope.validVersions = [undefined, 0.1, 0.2, 0.3, 0.4, 0.5];
|
||||
scope.transitions = {
|
||||
"": function(oldStorage){
|
||||
return {
|
||||
|
@ -11,6 +11,7 @@
|
||||
<script src="../lib/logging.js"></script>
|
||||
<script src="../lib/settingDefinitions.js"></script>
|
||||
<script src="../lib/settingContainers.js"></script>
|
||||
<script src="../lib/settingsMigration.js"></script>
|
||||
<script src="../lib/settings.js"></script>
|
||||
<script src="export.js"></script>
|
||||
</body>
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
const settings = require("./settings");
|
||||
const logging = require("./logging");
|
||||
const settingsMigration = require("./settingsMigration");
|
||||
const input = document.getElementById("settings");
|
||||
settings.onloaded(function(){
|
||||
var data = {};
|
||||
@ -18,7 +19,14 @@
|
||||
try {
|
||||
var newSettings = JSON.parse(this.value);
|
||||
var isValid = true;
|
||||
|
||||
|
||||
while (settingsMigration.transitions.hasOwnProperty(newSettings.storageVersion)){
|
||||
let oldVersion = newSettings.storageVersion;
|
||||
newSettings = settingsMigration.transitions[newSettings.storageVersion](newSettings);
|
||||
if (oldVersion === newSettings.storageVersion){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Object.entries(newSettings).forEach(function(entry){
|
||||
const [name, value] = entry;
|
||||
@ -53,5 +61,14 @@
|
||||
this.classList.add("invalid");
|
||||
}
|
||||
});
|
||||
input.addEventListener("blur", function(){
|
||||
if (!this.classList.contains("invalid")){
|
||||
var data = {};
|
||||
settings.forEach(function(def){
|
||||
data[def.name] = def.get();
|
||||
});
|
||||
input.value = JSON.stringify(data, null, "\t");
|
||||
}
|
||||
});
|
||||
});
|
||||
}());
|
@ -11,6 +11,7 @@
|
||||
<script src="../lib/settingDefinitions.js"></script>
|
||||
<script src="../lib/settingContainers.js"></script>
|
||||
<script src="../lib/settingStrings.js"></script>
|
||||
<script src="../lib/settingsMigration.js"></script>
|
||||
<script src="../lib/settings.js"></script>
|
||||
<script src="../lib/search.js"></script>
|
||||
<script src="optionsGui.js"></script>
|
||||
|
@ -13,6 +13,7 @@
|
||||
const search = require("./search");
|
||||
const settingStrings = require("./settingStrings");
|
||||
const searchParameters = new URLSearchParams(window.location.search);
|
||||
const settingsMigration = require("./settingsMigration");
|
||||
|
||||
var callbacks = {
|
||||
openNavigatorSettings: function(){
|
||||
@ -75,6 +76,13 @@
|
||||
}).then(function(text){
|
||||
return JSON.parse(text);
|
||||
}).then(function(json){
|
||||
while (settingsMigration.transitions.hasOwnProperty(json.storageVersion)){
|
||||
let oldVersion = json.storageVersion;
|
||||
json = settingsMigration.transitions[json.storageVersion](json);
|
||||
if (oldVersion === json.storageVersion){
|
||||
break;
|
||||
}
|
||||
}
|
||||
const keys = Object.keys(json);
|
||||
keys.forEach(function(key){
|
||||
const setting = settings.getDefinition(key);
|
||||
|
Loading…
x
Reference in New Issue
Block a user