[refactor] Better version check and compare

This commit is contained in:
Kombie 2019-03-25 12:24:38 +00:00 committed by GitHub
parent 37e95f8775
commit c480736d23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 81 additions and 40 deletions

BIN
images/icon-128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
images/icon-16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
images/icon-48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
images/icon.psd Normal file

Binary file not shown.

View File

@ -155,45 +155,59 @@ var update = (function() {
console.log("\t -- running update", 1.00);
data = _update_100(data);
};
if (data.version < 2.00) {
console.log("\t -- running update", 2.00);
data = _update_200(data);
};
if (data.version < 2.10) {
console.log("\t -- running update", 2.10);
data = _update_210(data);
};
if (data.version < 2.30) {
console.log("\t -- running update", 2.30);
data = _update_230(data);
};
if (data.version < 2.40) {
console.log("\t -- running update", 2.40);
data = _update_240(data);
};
if (data.version < 2.50) {
console.log("\t -- running update", 2.50);
data = _update_250(data);
};
if (data.version < 2.70) {
console.log("\t -- running update", 2.70);
data = _update_270(data);
};
if (data.version < 2.80) {
console.log("\t -- running update", 2.80);
data = _update_280(data);
};
if (data.version < 2.90) {
console.log("\t -- running update", 2.90);
data = _update_290(data);
};
if (data.version < 2.91) {
console.log("\t -- running update", 2.91);
data.version = 2.91;
if (typeof data.version == "number") {
if (data.version < 2.00) {
console.log("\t -- running update", 2.00);
data = _update_200(data);
};
if (data.version < 2.10) {
console.log("\t -- running update", 2.10);
data = _update_210(data);
};
if (data.version < 2.30) {
console.log("\t -- running update", 2.30);
data = _update_230(data);
};
if (data.version < 2.40) {
console.log("\t -- running update", 2.40);
data = _update_240(data);
};
if (data.version < 2.50) {
console.log("\t -- running update", 2.50);
data = _update_250(data);
};
if (data.version < 2.70) {
console.log("\t -- running update", 2.70);
data = _update_270(data);
};
if (data.version < 2.80) {
console.log("\t -- running update", 2.80);
data = _update_280(data);
};
if (data.version < 2.90) {
console.log("\t -- running update", 2.90);
data = _update_290(data);
};
if (data.version < 2.91) {
console.log("\t -- running update", 2.91);
data.version = 2.91;
};
if (data.version < 2.96) {
// introduction of a new semantic version check function so the version is being bumped to 2.10.0 and changed to a string
console.log("\t -- running update", "2.10.0");
data.version = "2.10.0";
};
} else if (typeof data.version == "string") {
// new updates will go here
// example update compare check
// if (version.compare(data.version, "2.11.0") == -1) {
// console.log("\t -- running update", "2.11.0");
// data.version = "2.11.0";
// };
};
// if no update is needed
// version bump
if (data.version < version.get()) {
if (version.compare(data.version, version.get()) == -1) {
console.log("\t -- nothing to update, version bump to", version.get());
data.version = version.get();
};

View File

@ -1,16 +1,38 @@
var version = (function() {
// version is normally bumped when the state needs changing or any new functionality is added
var current = "2.9.5";
var current = "2.10.0";
var compare = function(a, b) {
var pa = a.split(".");
var pb = b.split(".");
for (var i = 0; i < 3; i++) {
var na = Number(pa[i]);
var nb = Number(pb[i]);
if (na > nb) {
return 1;
};
if (nb > na) {
return -1;
};
if (!isNaN(na) && isNaN(nb)) {
return 1;
};
if (isNaN(na) && !isNaN(nb)) {
return -1;
};
}
return 0;
};
var get = function() {
var number = current.split(".");
return parseFloat(number.shift() + "." + number.join(""));
return current;
};
// exposed methods
return {
get: get
get: get,
compare: compare
};
})();

View File

@ -5,5 +5,10 @@
"manifest_version": 2,
"chrome_url_overrides": {
"newtab": "index.html"
},
"icons": {
"16": "images/icon-16.png",
"48": "images/icon-48.png",
"128": "images/icon-128.png"
}
}