Skip to content

Commit 6d53052

Browse files
authored
0075 add available update detection (#109)
* Added the basis for a version check to the back end. * Fixed the backend so we only send an update once the client has connected. * Altered the front end to display an alert if a new version is available. * Added some protection to the back end in case the version check has problems.
1 parent 3c530d0 commit 6d53052

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

EDScoutWebUI/EDScout.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import tempfile
77
import psutil
88
import time
9+
import threading
10+
import requests
11+
import re
12+
913
from datetime import datetime
1014
from pathlib import Path
1115

@@ -87,6 +91,34 @@ def configure_logger(logger_to_configure, log_path, log_level_override=None):
8791
logger_to_configure.addHandler(ch)
8892

8993

94+
def version_check(current_version):
95+
latest_release_url = 'https://github.com/joncage/ed-scout/releases/latest'
96+
try:
97+
r = requests.get(latest_release_url)
98+
except Exception as pass_on_failure:
99+
log.exception(pass_on_failure)
100+
return
101+
102+
latest_version = r.url.split('/')[-1]
103+
104+
regex = r"[vV]?\d+\.\d+\.\d+\.?\d?"
105+
if re.search(regex, latest_version) is not None:
106+
new_version_available = latest_version != current_version
107+
content = {
108+
'current_version': current_version,
109+
'latest_version': latest_version,
110+
'new_release_detected': new_version_available,
111+
'url': latest_release_url
112+
}
113+
114+
version_check_description = 'New version available: '+latest_version if new_version_available else 'Up to date'
115+
log.info(f"Version check: {version_check_description}")
116+
117+
socketio.emit('version', content, broadcast=True)
118+
else:
119+
log.error(f"Failed to identify latest version from '{latest_version}'")
120+
121+
90122
# Work out where to stick the logs and make sure it exists
91123
logging_dir = os.path.join(os.path.expanduser('~'), 'AppData', 'Local', 'EDScout', 'Logs')
92124
if not os.path.isdir(logging_dir):
@@ -160,6 +192,10 @@ def receive_and_forward(scout):
160192
r = Receiver(port=scout.port)
161193
scout.trigger_current_journal_check()
162194

195+
# Launch the version check. Note that we only do this after the client has connected to avoid them missing this.
196+
version_check_thread = threading.Thread(target=version_check, args=(__version__,))
197+
version_check_thread.start()
198+
163199
while True:
164200
message = r.receive().decode('ascii')
165201
try:
@@ -171,7 +207,7 @@ def receive_and_forward(scout):
171207
log.exception(pass_on_failure)
172208

173209

174-
@app.route('/')Disabling caching
210+
@app.route('/')
175211
def index():
176212
return render_template('index.html',
177213
version=__version__,
@@ -237,6 +273,7 @@ def remap_css_to_match_hud():
237273
# Enable toggling
238274
toggler = WindowToggler.ScoutToggler()
239275

276+
240277
# Launch the web server either directly or as an app
241278
if ui:
242279
ui.run()

EDScoutWebUI/static/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,8 @@ div b.active.landable {
104104
.next-system hr {
105105
border-color: #17EFF9;
106106
}
107+
108+
.alert {
109+
top: 1em;
110+
bottom: 1em;
111+
}

EDScoutWebUI/templates/index.html

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@
2020

2121
<body>
2222

23-
23+
<div class="container-fluid">
24+
<div class="row">
25+
<div class="col">
26+
<div id="new-version-alert-wrapper" class="alert alert-info alert-dismissible fade show" role="alert" hidden>
27+
<span>New Version Available</span>: <strong id="version-link-wrapper"></strong>
28+
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
29+
<span aria-hidden="true">&times;</span>
30+
</button>
31+
</div>
32+
</div>
33+
</div>
34+
</div>
2435

2536
<div class="container-fluid">
2637
<div class="row separator align-items-center">
@@ -801,9 +812,28 @@
801812
802813
/**/
803814

815+
function versionCheckReport(versionCheck) {
816+
console.log(versionCheck);
817+
818+
if (versionCheck['new_release_detected']) {
819+
let versionInfoElement = document.getElementById('version-link-wrapper')
820+
let link = document.createElement('a')
821+
link.href = versionCheck['url']
822+
link.text = versionCheck['latest_version']
823+
link.target = '_blank'
824+
link.classList.add('alert-link')
825+
versionInfoElement.innerHTML = link.outerHTML
826+
827+
let alertDiv = document.getElementById('new-version-alert-wrapper')
828+
alertDiv.hidden = false;
829+
}
830+
}
831+
832+
804833
if (enableBackendConnections) {
805834
var socket = io()
806835
socket.on('log', postData)
836+
socket.on('version', versionCheckReport)
807837

808838
document.addEventListener('DOMContentLoaded', function() {
809839
var url = 'http://'+window.location.hostname+':5001/GUI-is-still-open';

0 commit comments

Comments
 (0)