1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 21:00:23 +01:00

Enabled import of older storage versions.

This commit is contained in:
kkapsner 2019-03-11 22:10:34 +01:00
parent 5f74f13de3
commit f565b8c32e
5 changed files with 29 additions and 2 deletions

View File

@ -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 {

View File

@ -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>

View File

@ -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 = {};
@ -19,6 +20,13 @@
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");
}
});
});
}());

View File

@ -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>

View File

@ -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);