OpenBuilds-CONTROL/app/js/updates.js

56 wiersze
2.1 KiB
JavaScript
Czysty Zwykły widok Historia

2018-08-10 19:42:30 +00:00
var time = 10
$(document).ready(function() {
2018-10-29 19:18:59 +00:00
checkUpdate()
});
2020-02-04 13:19:23 +00:00
2018-10-29 19:18:59 +00:00
function checkUpdate() {
2019-06-04 19:01:06 +00:00
if (!isMac && webgl) {
setTimeout(function() {
// console.log('checking for update')
printLog("<span class='fg-red'>[ update ] </span><span class='fg-green'>Checking for Updates</span>")
2020-02-04 13:19:23 +00:00
$.getJSON("https://api.github.com/repos/OpenBuilds/OpenBuilds-CONTROL/releases/latest", {
2020-02-04 13:23:22 +00:00
crossDomain: true
2020-02-04 13:19:23 +00:00
}).done(function(release) {
2019-06-04 19:01:06 +00:00
var availVersion = release.name.substr(1)
var currentVersion = laststatus.driver.version
// console.log(versionCompare(availVersion, currentVersion), availVersion, currentVersion);
if (versionCompare(availVersion, currentVersion) == 1) {
console.log('outdated')
time = 10
printLog("<span class='fg-red'>[ Update Available! ] </span><span class='fg-green'>OpenBuilds CONTROL <code>" + availVersion + "</code>. is available now.</span>")
printLog("<span class='fg-red'>[ Update Available! ] </span><span class='fg-green'>Download will start in <span class='tally' id='countdown'>10</span> seconds (<a href='#' onclick='cancelTimer();'>cancel</a>) </span>")
printLog("<span class='fg-red'>[ Update Available! ] </span><span class='fg-green'>You will be prompted when its ready to be installed </span>")
setTimeout(function() {
updateTime();
}, 1000);
} else {
printLog("<span class='fg-red'>[ update ] </span><span class='fg-green'>You are already running OpenBuilds CONTROL " + currentVersion + "</span>")
setTimeout(function() {
checkUpdate()
2020-02-04 13:23:22 +00:00
}, 60 * 60 * 1000) // 15 mins
2019-06-04 19:01:06 +00:00
}
});
}, 1000)
}
2018-10-29 19:18:59 +00:00
}
2018-08-10 19:42:30 +00:00
function updateTime() {
time--
if (time > 0) {
$('#countdown').html(time)
setTimeout(function() {
updateTime();
}, 1000);
} else if (time == 0) {
$('#countdown').html(time)
socket.emit('downloadUpdate', true)
}
}
function cancelTimer() {
time = -1
$('#countdown').html('cancelled')
printLog("<span class='fg-red'>[ Update Deferred! ] </span><span class='fg-green'>No problem, we will ask you again next time</span>")
}