Check for updates without refreshing the page

This commit is contained in:
JonnyWong16 2018-02-16 10:24:55 -08:00
parent 16f270691d
commit cab8b1c041
5 changed files with 112 additions and 20 deletions

21
API.md
View file

@ -2409,7 +2409,26 @@ Uninstalls the GeoLite2 database
### update
Check for Tautulli updates on Github.
Update Tautulli.
### update_check
Check for Tautulli updates.
```
Required parameters:
None
Optional parameters:
None
Returns:
json
{"result": "success",
"update": true,
"message": "An update for Tautulli is available."
}
```
### update_metadata_details

View file

@ -44,16 +44,18 @@
% if _session['user_group'] == 'admin':
% if plexpy.CONFIG.CHECK_GITHUB and not plexpy.CURRENT_VERSION:
<div id="updatebar" style="display: none;">
You're running an unknown version of Tautulli.<br />
You are running an unknown version of Tautulli.<br />
<a href="update">Update</a> or <a href="#" id="updateDismiss">Close</a>
</div>
% elif plexpy.CONFIG.CHECK_GITHUB and plexpy.CURRENT_VERSION != plexpy.LATEST_VERSION and plexpy.COMMITS_BEHIND > 0 and plexpy.INSTALL_TYPE != 'win':
<div id="updatebar" style="display: none;">
A <a href="${anon_url('https://github.com/%s/%s/compare/%s...%s' % (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO, plexpy.CURRENT_VERSION, plexpy.LATEST_VERSION))}" target="_blank">
newer version</a> is available.<br />
You're ${plexpy.COMMITS_BEHIND} commits behind.<br />
newer version</a> is available!<br />
You are ${plexpy.COMMITS_BEHIND} commits behind.<br />
<a href="update">Update</a> or <a href="#" id="updateDismiss">Close</a>
</div>
% else:
<div id="updatebar" style="display: none;"></div>
% endif
% endif
<nav class="navbar navbar-fixed-top">
@ -296,7 +298,37 @@ ${next.modalIncludes()}
});
if (!getCookie('updateDismiss')) {
$('#updatebar').show();
if ($('#updatebar').html().length > 0) {
$('#updatebar').show();
}
}
function checkUpdate(_callback) {
// Allow the update bar to show again if previously dismissed.
setCookie('updateDismiss', 'true', 0);
$.ajax({
url: 'update_check',
complete: function (xhr, status) {
var result = $.parseJSON(xhr.responseText);
var msg = '';
if (result.update === true) {
msg = 'A <a href="' + result.compare_url + '" target="_blank">newer version</a> is available!<br />' +
'You are '+ result.commits_behind + ' commits behind.<br />' +
'<a href="update">Update</a> or <a href="#" id="updateDismiss">Close</a>.';
$('#updatebar').html(msg).show();
} else if (result.update === false) {
showMsg('<i class="fa fa-check"></i> ' + result.message, false, true, 2000);
} else if (result.update === null) {
msg = 'You are running an unknown version of Tautulli.<br />' +
'<a href="update">Update</a> or <a href="#" id="updateDismiss">Close</a>.';
$('#updatebar').html(msg).show();
}
if (_callback) {
_callback();
}
}
});
}
$("#nav-shutdown").click(function() {
@ -315,11 +347,9 @@ ${next.modalIncludes()}
});
});
$("#nav-update").first().one("click", function () {
// Allow the update bar to show again if previously dismissed.
setCookie('updateDismiss', 'true', 0);
$(this).html('<i class="fa fa-spin fa-refresh"></i> Checking');
window.location.href = "checkGithub";
$('#nav-update').click(function () {
$(this).html('<i class="fa fa-fw fa-spin fa-refresh"></i> Checking');
checkUpdate(function () { $('#nav-update').html('<i class="fa fa-fw fa-arrow-circle-up"></i> Check for Updates'); });
});
$('#donation_type a.crypto-donation').on('shown.bs.tab', function () {

View file

@ -1648,11 +1648,11 @@ $(document).ready(function() {
});
$('#menu_link_update_check').click(function() {
// Allow the update bar to show again if previously dismissed.
setCookie('updateDismiss', 'true', 0);
$(this).html('<i class="fa fa-spin fa-refresh"></i> Checking');
$(this).prop('disabled', true);
window.location.href = 'checkGithub';
$(this).html('<i class="fa fa-spin fa-refresh"></i> Checking').prop('disabled', true);
checkUpdate(function () {
$('#menu_link_update_check').html('<i class="fa fa-arrow-circle-up"></i> Check for Updates')
.prop('disabled', false);
});
});
$('#modal_link_restart').click(function() {

View file

@ -335,14 +335,14 @@ class API2:
""" Restart Tautulli."""
plexpy.SIGNAL = 'restart'
self._api_msg = 'Restarting plexpy'
self._api_msg = 'Restarting Tautulli'
self._api_result_type = 'success'
def update(self, **kwargs):
""" Check for Tautulli updates on Github."""
""" Update Tautulli."""
plexpy.SIGNAL = 'update'
self._api_msg = 'Updating plexpy'
self._api_msg = 'Updating Tautulli'
self._api_result_type = 'success'
def refresh_libraries_list(self, **kwargs):

View file

@ -3508,10 +3508,53 @@ class WebInterface(object):
return apikey
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))
def checkGithub(self, **kwargs):
@addtoapi()
def update_check(self, **kwargs):
""" Check for Tautulli updates.
```
Required parameters:
None
Optional parameters:
None
Returns:
json
{"result": "success",
"update": true,
"message": "An update for Tautulli is available."
}
```
"""
versioncheck.checkGithub()
raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT + "home")
if not plexpy.CURRENT_VERSION:
return {'result': 'error',
'message': 'You are running an unknown version of Tautulli.',
'update': None}
elif plexpy.CURRENT_VERSION != plexpy.LATEST_VERSION and \
plexpy.COMMITS_BEHIND > 0 and plexpy.INSTALL_TYPE != 'win':
return {'result': 'success',
'update': True,
'message': 'An update for Tautulli is available.',
'latest_version': plexpy.LATEST_VERSION,
'commits_behind': plexpy.COMMITS_BEHIND,
'compare_url': helpers.anon_url(
'https://github.com/%s/%s/compare/%s...%s'
% (plexpy.CONFIG.GIT_USER,
plexpy.CONFIG.GIT_REPO,
plexpy.CURRENT_VERSION,
plexpy.LATEST_VERSION))
}
else:
return {'result': 'success',
'update': False,
'message': 'Tautulli is up to date.'}
@cherrypy.expose
@requireAuth(member_of("admin"))