mirror of
https://github.com/zombieFox/nightTab.git
synced 2024-12-28 09:38:50 +01:00
[refactor] improve update module
This commit is contained in:
parent
db81f16cae
commit
5fd7341b53
204
src/js/update.js
204
src/js/update.js
@ -1,25 +1,18 @@
|
|||||||
var update = (function() {
|
var update = (function() {
|
||||||
|
|
||||||
// this associative array contains all the updates. add
|
// this associative array contains all the updates. add a new entry if you need to modify data.
|
||||||
// a new entry if you need to modify data.
|
// example, this assumes the previous version is less than 3.28.0:
|
||||||
//
|
// "3.28.0": function(data) {
|
||||||
// example, this assumes the previous version is less than
|
|
||||||
// 3.28.0, so 3.27.0 would be upgraded in this case.
|
|
||||||
// _update["3.28.0"] = function(data) {
|
|
||||||
// return data;
|
// return data;
|
||||||
// };
|
// };
|
||||||
//
|
// always add the version in increasing order so the most recent version is last.
|
||||||
// always add the version in increasing order so the
|
var _update = {
|
||||||
// most recent version is last.
|
"1.0.0": function(data) {
|
||||||
var _update = {};
|
|
||||||
|
|
||||||
_update["1.0.0"] = function(data) {
|
|
||||||
data.version = "1.0.0";
|
data.version = "1.0.0";
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.0.0": function(data) {
|
||||||
_update["2.0.0"] = function(data) {
|
// major state overhaul for version 2.0.0 and up
|
||||||
// major state overhaul
|
|
||||||
data.state = {
|
data.state = {
|
||||||
header: {
|
header: {
|
||||||
date: {
|
date: {
|
||||||
@ -106,25 +99,22 @@ var update = (function() {
|
|||||||
// version 1.0.0 bookmarks are not compatible so need to be reset
|
// version 1.0.0 bookmarks are not compatible so need to be reset
|
||||||
data.bookmarks = [];
|
data.bookmarks = [];
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.1.0": function(data) {
|
||||||
_update["2.1.0"] = function(data) {
|
|
||||||
data.state.layout.theme = {
|
data.state.layout.theme = {
|
||||||
current: data.state.layout.theme.current,
|
current: data.state.layout.theme.current,
|
||||||
random: false
|
random: false
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.3.0": function(data) {
|
||||||
_update["2.3.0"] = function(data) {
|
|
||||||
data.state.layout.theme.random = {
|
data.state.layout.theme.random = {
|
||||||
active: data.state.layout.theme.random,
|
active: data.state.layout.theme.random,
|
||||||
style: "any"
|
style: "any"
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.4.0": function(data) {
|
||||||
_update["2.4.0"] = function(data) {
|
|
||||||
data.state.link.show = {
|
data.state.link.show = {
|
||||||
active: true,
|
active: true,
|
||||||
name: true,
|
name: true,
|
||||||
@ -145,14 +135,12 @@ var update = (function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.5.0": function(data) {
|
||||||
_update["2.5.0"] = function(data) {
|
|
||||||
data.state.header.search.focus = false;
|
data.state.header.search.focus = false;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.7.0": function(data) {
|
||||||
_update["2.7.0"] = function(data) {
|
|
||||||
// update date character length
|
// update date character length
|
||||||
data.state.header.date.character = {
|
data.state.header.date.character = {
|
||||||
length: data.state.header.date.characterLength
|
length: data.state.header.date.characterLength
|
||||||
@ -201,14 +189,12 @@ var update = (function() {
|
|||||||
delete data.state.menu.open;
|
delete data.state.menu.open;
|
||||||
// update version
|
// update version
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.8.0": function(data) {
|
||||||
_update["2.8.0"] = function(data) {
|
|
||||||
data.state.layout.title = "New Tab";
|
data.state.layout.title = "New Tab";
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.9.0": function(data) {
|
||||||
_update["2.9.0"] = function(data) {
|
|
||||||
data.state.header.shade = {
|
data.state.header.shade = {
|
||||||
show: true,
|
show: true,
|
||||||
padding: 4,
|
padding: 4,
|
||||||
@ -220,9 +206,8 @@ var update = (function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.10.0": function(data) {
|
||||||
_update["2.10.0"] = function(data) {
|
|
||||||
data.state.header.shade = {
|
data.state.header.shade = {
|
||||||
show: true,
|
show: true,
|
||||||
padding: 4,
|
padding: 4,
|
||||||
@ -234,27 +219,24 @@ var update = (function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.11.0": function(data) {
|
||||||
_update["2.11.0"] = function(data) {
|
|
||||||
data.state.header.greeting = {
|
data.state.header.greeting = {
|
||||||
show: false,
|
show: false,
|
||||||
type: "good",
|
type: "good",
|
||||||
name: ""
|
name: ""
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.11.0": function(data) {
|
||||||
_update["2.11.0"] = function(data) {
|
|
||||||
data.state.header.greeting = {
|
data.state.header.greeting = {
|
||||||
show: false,
|
show: false,
|
||||||
type: "good",
|
type: "good",
|
||||||
name: ""
|
name: ""
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.12.0": function(data) {
|
||||||
_update["2.12.0"] = function(data) {
|
|
||||||
data.state.bookmarks.link = {
|
data.state.bookmarks.link = {
|
||||||
show: data.state.bookmarks.show.link
|
show: data.state.bookmarks.show.link
|
||||||
};
|
};
|
||||||
@ -275,14 +257,12 @@ var update = (function() {
|
|||||||
};
|
};
|
||||||
delete data.state.layout.theme;
|
delete data.state.layout.theme;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.14.0": function(data) {
|
||||||
_update["2.14.0"] = function(data) {
|
|
||||||
data.state.layout.width = 72;
|
data.state.layout.width = 72;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.16.0": function(data) {
|
||||||
_update["2.16.0"] = function(data) {
|
|
||||||
data.state.header.shade.padding = {
|
data.state.header.shade.padding = {
|
||||||
top: data.state.header.shade.padding,
|
top: data.state.header.shade.padding,
|
||||||
bottom: data.state.header.shade.padding
|
bottom: data.state.header.shade.padding
|
||||||
@ -298,25 +278,22 @@ var update = (function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.17.0": function(data) {
|
||||||
_update["2.17.0"] = function(data) {
|
|
||||||
data.state.header.search.engine.google.name = "Google";
|
data.state.header.search.engine.google.name = "Google";
|
||||||
data.state.header.search.engine.duckduckgo.name = "Duck Duck Go";
|
data.state.header.search.engine.duckduckgo.name = "Duck Duck Go";
|
||||||
data.state.header.search.engine.giphy.name = "Giphy";
|
data.state.header.search.engine.giphy.name = "Giphy";
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.19.0": function(data) {
|
||||||
_update["2.19.0"] = function(data) {
|
|
||||||
data.state.header.search.engine.youtube = {
|
data.state.header.search.engine.youtube = {
|
||||||
url: "https://www.youtube.com/results?search_query=",
|
url: "https://www.youtube.com/results?search_query=",
|
||||||
name: "YouTube"
|
name: "YouTube"
|
||||||
};
|
};
|
||||||
data.state.header.search.engine.custom.name = "";
|
data.state.header.search.engine.custom.name = "";
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.20.0": function(data) {
|
||||||
_update["2.20.0"] = function(data) {
|
|
||||||
data.state.header.search.width = {
|
data.state.header.search.width = {
|
||||||
style: "auto",
|
style: "auto",
|
||||||
custom: 30
|
custom: 30
|
||||||
@ -326,9 +303,8 @@ var update = (function() {
|
|||||||
};
|
};
|
||||||
delete data.state.header.search.grow;
|
delete data.state.header.search.grow;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.21.0": function(data) {
|
||||||
_update["2.21.0"] = function(data) {
|
|
||||||
data.state.header.clock = {
|
data.state.header.clock = {
|
||||||
hours: {
|
hours: {
|
||||||
show: data.state.header.clock.show.hours,
|
show: data.state.header.clock.show.hours,
|
||||||
@ -384,9 +360,8 @@ var update = (function() {
|
|||||||
type: "timeanddate"
|
type: "timeanddate"
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"2.22.0": function(data) {
|
||||||
_update["2.22.0"] = function(data) {
|
|
||||||
data.bookmarks.forEach(function(item, index) {
|
data.bookmarks.forEach(function(item, index) {
|
||||||
item.accent = {
|
item.accent = {
|
||||||
override: false,
|
override: false,
|
||||||
@ -398,9 +373,8 @@ var update = (function() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.0.0": function(data) {
|
||||||
_update["3.0.0"] = function(data) {
|
|
||||||
data.bookmarks.forEach(function(item, index) {
|
data.bookmarks.forEach(function(item, index) {
|
||||||
item.display = "letter";
|
item.display = "letter";
|
||||||
item.icon = {
|
item.icon = {
|
||||||
@ -410,9 +384,8 @@ var update = (function() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.1.0": function(data) {
|
||||||
_update["3.1.0"] = function(data) {
|
|
||||||
data.state.header.area = {
|
data.state.header.area = {
|
||||||
width: 90,
|
width: 90,
|
||||||
alignment: {
|
alignment: {
|
||||||
@ -450,9 +423,8 @@ var update = (function() {
|
|||||||
data.state.edge = false;
|
data.state.edge = false;
|
||||||
data.state.autoSuggest = false;
|
data.state.autoSuggest = false;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.2.0": function(data) {
|
||||||
_update["3.2.0"] = function(data) {
|
|
||||||
data.state.link.display = {
|
data.state.link.display = {
|
||||||
show: true,
|
show: true,
|
||||||
alignment: {
|
alignment: {
|
||||||
@ -467,17 +439,15 @@ var update = (function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.4.0": function(data) {
|
||||||
_update["3.4.0"] = function(data) {
|
|
||||||
data.state.header.padding = data.state.header.shade.padding;
|
data.state.header.padding = data.state.header.shade.padding;
|
||||||
delete data.state.header.shade.padding;
|
delete data.state.header.shade.padding;
|
||||||
data.state.header.border = data.state.header.shade.border;
|
data.state.header.border = data.state.header.shade.border;
|
||||||
delete data.state.header.shade.border;
|
delete data.state.header.shade.border;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.6.0": function(data) {
|
||||||
_update["3.6.0"] = function(data) {
|
|
||||||
data.state.header.item = data.state.header.items;
|
data.state.header.item = data.state.header.items;
|
||||||
delete data.state.header.items;
|
delete data.state.header.items;
|
||||||
data.state.link.area.gap = 2;
|
data.state.link.area.gap = 2;
|
||||||
@ -493,16 +463,14 @@ var update = (function() {
|
|||||||
delete data.state.link.name;
|
delete data.state.link.name;
|
||||||
delete data.state.link.url;
|
delete data.state.link.url;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.7.0": function(data) {
|
||||||
_update["3.7.0"] = function(data) {
|
|
||||||
data.state.link.item.line = {
|
data.state.link.item.line = {
|
||||||
show: true
|
show: true
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.8.0": function(data) {
|
||||||
_update["3.8.0"] = function(data) {
|
|
||||||
data.state.header.clock.size = 1;
|
data.state.header.clock.size = 1;
|
||||||
data.state.header.date.size = 1;
|
data.state.header.date.size = 1;
|
||||||
data.state.header.greeting.size = 1;
|
data.state.header.greeting.size = 1;
|
||||||
@ -522,9 +490,8 @@ var update = (function() {
|
|||||||
delete data.state.header.editAdd;
|
delete data.state.header.editAdd;
|
||||||
data.state.theme.radius = 0.2;
|
data.state.theme.radius = 0.2;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.9.0": function(data) {
|
||||||
_update["3.9.0"] = function(data) {
|
|
||||||
delete data.state.header.padding;
|
delete data.state.header.padding;
|
||||||
data.state.header.radius = false;
|
data.state.header.radius = false;
|
||||||
data.state.header.border = {
|
data.state.header.border = {
|
||||||
@ -536,40 +503,33 @@ var update = (function() {
|
|||||||
data.state.background.image.scale = 1;
|
data.state.background.image.scale = 1;
|
||||||
delete data.state.link.area.gap;
|
delete data.state.link.area.gap;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.10.0": function(data) {
|
||||||
_update["3.10.0"] = function(data) {
|
|
||||||
data.state.header.button.style = "box";
|
data.state.header.button.style = "box";
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.11.0": function(data) {
|
||||||
_update["3.11.0"] = function(data) {
|
|
||||||
data.state.link.item.line = data.state.link.item.line.show;
|
data.state.link.item.line = data.state.link.item.line.show;
|
||||||
data.state.link.item.hoverScale = true;
|
data.state.link.item.hoverScale = true;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.15.0": function(data) {
|
||||||
_update["3.15.0"] = function(data) {
|
|
||||||
delete data.state.link.sort;
|
delete data.state.link.sort;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.18.0": function(data) {
|
||||||
_update["3.18.0"] = function(data) {
|
|
||||||
data.nighttab = true;
|
data.nighttab = true;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.20.0": function(data) {
|
||||||
_update["3.20.0"] = function(data) {
|
|
||||||
data.state.link.item.url = data.state.link.item.url.show;
|
data.state.link.item.url = data.state.link.item.url.show;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.21.0": function(data) {
|
||||||
_update["3.21.0"] = function(data) {
|
|
||||||
data.state.layout.order = "headerLink";
|
data.state.layout.order = "headerLink";
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.27.0": function(data) {
|
||||||
_update["3.27.0"] = function(data) {
|
|
||||||
// swicth to single values for alignment controls
|
// swicth to single values for alignment controls
|
||||||
// no more horizontal or vertical keys in state object
|
// no more horizontal or vertical keys in state object
|
||||||
data.state.header.area.alignment = data.state.header.area.alignment.horizontal;
|
data.state.header.area.alignment = data.state.header.area.alignment.horizontal;
|
||||||
@ -580,30 +540,31 @@ var update = (function() {
|
|||||||
data.state.link.item.display.alignment = data.state.link.item.display.alignment.vertical + data.state.link.item.display.alignment.horizontal;
|
data.state.link.item.display.alignment = data.state.link.item.display.alignment.vertical + data.state.link.item.display.alignment.horizontal;
|
||||||
data.state.layout.alignment = data.state.layout.alignment.vertical + data.state.layout.alignment.horizontal;
|
data.state.layout.alignment = data.state.layout.alignment.vertical + data.state.layout.alignment.horizontal;
|
||||||
return data;
|
return data;
|
||||||
};
|
},
|
||||||
|
"3.28.0": function(data) {
|
||||||
_update["3.28.0"] = function(data) {
|
|
||||||
// add bing search engine
|
|
||||||
data.state.header.search.engine.bing = {
|
data.state.header.search.engine.bing = {
|
||||||
url: "https://www.bing.com/search?q=",
|
url: "https://www.bing.com/search?q=",
|
||||||
name: "Bing"
|
name: "Bing"
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function run(data) {
|
function run(data) {
|
||||||
|
// legacy update as first version of nightTab did not have a version number stored in the state object
|
||||||
if (!("version" in data)) {
|
if (!("version" in data)) {
|
||||||
// legacy update as first version of nightTab did not have a version number stored in the state
|
|
||||||
data = _update["1.0.0"](data);
|
data = _update["1.0.0"](data);
|
||||||
};
|
};
|
||||||
if (typeof data.version == "number") {
|
|
||||||
// old version numbers were type of number
|
// old version numbers were type of number
|
||||||
// change them to strings to support new version checking
|
// change them to strings to support new version checking
|
||||||
|
if (typeof data.version == "number") {
|
||||||
data.version = data.version.toString().split(".")
|
data.version = data.version.toString().split(".")
|
||||||
data.version.push("0");
|
data.version.push("0");
|
||||||
data.version = data.version.join(".");
|
data.version = data.version.join(".");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// loop over all updates in _update object
|
||||||
for (var key in _update) {
|
for (var key in _update) {
|
||||||
if (version.compare(data.version, key) == -1) {
|
if (version.compare(data.version, key) == -1) {
|
||||||
console.log("\t= running update", key);
|
console.log("\t= running update", key);
|
||||||
@ -623,6 +584,7 @@ var update = (function() {
|
|||||||
|
|
||||||
// exposed methods
|
// exposed methods
|
||||||
return {
|
return {
|
||||||
|
_update: _update,
|
||||||
run: run
|
run: run
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user