Skip to content

Commit

Permalink
Add version checker
Browse files Browse the repository at this point in the history
  • Loading branch information
theyosh committed Jul 16, 2017
1 parent b82b403 commit ff62c40
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 30 additions & 1 deletion static/js/terrariumpi.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var globals = {
graphs: {},
graph_cache: 5 * 60,
websocket_timer: null,
online_timer: null
online_timer: null,
current_version: null
};

/**
Expand Down Expand Up @@ -1340,6 +1341,32 @@ function capitalizeFirstLetter(string) {
return string[0].toUpperCase() + string.slice(1);
}

function version_check() {
$.getJSON('https://api.github.com/repos/theyosh/TerrariumPI/releases/latest' ,function(data){

var latest_version = data.tag_name.replace(/\./g,'') * 1;
var current_version = globals.current_version.replace(/\./g,'') * 1;
if (current_version < 100) current_version *= 10;

if (current_version < latest_version) {
var message = 'New version available! <a href="' + data.html_url + '" target="_blank" title="Download TerrariumPI version ' + data.tag_name + '">Click here to download</a>!';
new PNotify({
type: 'info',
title: 'New release: ' + data.tag_name,
text: message,
delay: 1000,
mouse_reset: false,
styling: 'bootstrap3',
hide: false
});
}

setTimeout(function() {
version_check();
}, 24 * 60 * 60 * 1000 ); // Check once a day
});
}

$(document).ready(function() {
init_sidebar();

Expand Down Expand Up @@ -1371,4 +1398,6 @@ $(document).ready(function() {
notification_timestamps();
$('#system_time span').text(moment().format('LLLL'));
}, 30 * 1000);

version_check();
});
3 changes: 3 additions & 0 deletions views/inc/footer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@
<script type="text/javascript" src="/static/js/jquery.fullscreen-min.js"></script>
<!-- Load the terrariumPI JS script-->
<script type="text/javascript" src="/static/js/terrariumpi.js"></script>
<script type="text/javascript">
globals.current_version = '{{version}}';
</script>
</body>
</html>

0 comments on commit ff62c40

Please sign in to comment.