Skip to content

Commit

Permalink
Version check support semantic compare
Browse files Browse the repository at this point in the history
Fixes #159
  • Loading branch information
alpha0010 authored Jun 1, 2022
1 parent 3674b30 commit 7dd7b7f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion templates/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
$.getJSON("index.php",
{'op':'version_info'},
function(data) {
if (data.latest_version><?php echo Webgrind_Config::$webgrindVersion?>) {
if (isNewer('<?php echo Webgrind_Config::$webgrindVersion?>', data.latest_version)) {
$("#version_info").append('Version '+data.latest_version+' is available for <a href="'+data.download_url+'">download</a>.');
} else {
$("#version_info").append('You have the latest version.');
Expand All @@ -285,6 +285,16 @@
);
}

function parseVersion(version) {
return (version + '.0.0' ).split('.').slice(0, 3).map(x => parseInt(x, 10));
}

function isNewer(oldV, newV) {
var oldP = parseVersion(oldV);
var newP = parseVersion(newV);
return newP[0] > oldP[0] || newP[1] > oldP[1] || newP[2] > oldP[2];
}

function clearFiles() {
$.getJSON("index.php",
{'op':'clear_files'},
Expand Down

3 comments on commit 7dd7b7f

@jokkedk
Copy link
Owner

@jokkedk jokkedk commented on 7dd7b7f Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Do you think we should bump the version and release or just release with 1.9.1 again?

@alpha0010
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend bump version. Treating versions as immutable makes it easier to confirm the correct code is running.

@alpha0010
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, looks like the newP[0] > oldP[0] || newP[1] > oldP[1] || newP[2] > oldP[2] logic is not quite right. It says 1.1.0 is newer than 2.0.0.

Please # to comment.