2016-10-23 02:23:44 +00:00
|
|
|
/** @namespace $.SickGear.Root */
|
|
|
|
/** @namespace $.SickGear.Host */
|
|
|
|
/** @namespace $.SickGear.Port */
|
|
|
|
/** @namespace $.SickGear.UseHttps */
|
|
|
|
/** @namespace data.msg */
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2016-10-23 02:23:44 +00:00
|
|
|
var sgRoot = $.SickGear.Root,
|
|
|
|
browserUrl = window.location.protocol + '//' + window.location.host + sgRoot,
|
|
|
|
baseUrl = 'http' + ($.SickGear.UseHttps ? 's' : '') + '://' + $.SickGear.Host + ':'
|
|
|
|
+ (('' == sgRoot) ? $.SickGear.Port : location.port) + sgRoot,
|
|
|
|
isAliveUrl = sgRoot + '/home/is_alive/',
|
|
|
|
timeoutId;
|
|
|
|
$.SickGear.currentPid = '';
|
|
|
|
$.SickGear.numRestartWaits = 0;
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-07-01 13:08:10 +00:00
|
|
|
function is_alive() {
|
2016-10-23 02:23:44 +00:00
|
|
|
timeoutId = 0;
|
|
|
|
$.get(isAliveUrl, function(data) {
|
|
|
|
|
|
|
|
if ('nope' == data.msg.toString()) {
|
|
|
|
// if initialising then just wait and try again
|
|
|
|
|
|
|
|
$('#shut_down_message').find('.spinner,.hide-yes').removeClass();
|
|
|
|
$('#restart_message').removeClass();
|
2016-10-28 17:57:37 +00:00
|
|
|
setTimeout(is_alive, 100);
|
2016-10-23 02:23:44 +00:00
|
|
|
|
|
|
|
} else if ('' == $.SickGear.currentPid || $.SickGear.currentPid == data.msg) {
|
|
|
|
// if this is before we've even shut down then just try again later
|
|
|
|
|
|
|
|
$.SickGear.currentPid = data.msg;
|
2016-10-28 17:57:37 +00:00
|
|
|
setTimeout(is_alive, 100);
|
2016-10-23 02:23:44 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// if we're ready to go then redirect to new url
|
|
|
|
|
|
|
|
$('#restart_message').find('.spinner,.hide-yes').removeClass();
|
|
|
|
$('#refresh_message').removeClass();
|
|
|
|
window.location = baseUrl + '/home/';
|
|
|
|
}
|
|
|
|
}, 'jsonp');
|
2014-07-01 13:08:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
2016-10-23 02:23:44 +00:00
|
|
|
is_alive();
|
|
|
|
|
|
|
|
//noinspection JSUnusedLocalSymbols
|
|
|
|
$('#shut_down_message').ajaxError(function(e, jqxhr, settings, exception) {
|
|
|
|
$.SickGear.numRestartWaits += 1;
|
|
|
|
|
|
|
|
$('#shut_down_message').find('.spinner,.hide-yes').removeClass();
|
|
|
|
$('#restart_message').removeClass();
|
|
|
|
isAliveUrl = baseUrl + '/home/is_alive/';
|
|
|
|
|
|
|
|
// if https is enabled or you are currently on https and the port or protocol changed just wait 5 seconds then redirect.
|
|
|
|
// This is because the ajax will fail if the cert is untrusted or the the http ajax request from https will fail because of mixed content error.
|
|
|
|
if ($.SickGear.UseHttps || 'https:' == window.location.protocol) {
|
|
|
|
if (browserUrl != baseUrl) {
|
|
|
|
|
|
|
|
timeoutId = 1;
|
|
|
|
setTimeout(function() {
|
|
|
|
$('#restart_message').find('.spinner,.hide-yes').removeClass();
|
|
|
|
$('#refresh_message').removeClass();
|
|
|
|
}, 3000);
|
|
|
|
setTimeout(function() {
|
|
|
|
window.location = baseUrl + '/home/'
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if it is taking forever just give up
|
|
|
|
if (90 < $.SickGear.numRestartWaits) {
|
|
|
|
|
|
|
|
$('#restart_message').find('.spinner,.yes,.hide-no').removeClass();
|
|
|
|
$('#restart_fail_message').removeClass();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == timeoutId) {
|
|
|
|
|
2016-10-28 17:57:37 +00:00
|
|
|
timeoutId = setTimeout(is_alive, 100);
|
2016-10-23 02:23:44 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|