Skip to content

Commit cd47a8d

Browse files
author
xss
committed
Add version check
1 parent e169925 commit cd47a8d

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.log
44
js/mobile.js
55
js/init_plot.js
6+
js/version.json
67
css/mobile.css
78
cache.manifest
8-
tiles/
9+
tiles/

build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations -
3535
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge _jquery.flot.js >> init_plot.js
3636
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge plot_config.js >> init_plot.js
3737

38+
# create version check file
39+
echo "{\"build_date\": \"$BUILD_DATE\", \"version\": \"$VERSION\", \"refresh\": 86400}" > version.json
40+
3841
cd ..
3942
echo "Done!"
4043
echo -n "Generate cache.manifest..."

css/layout.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,19 @@ header h1{
164164
font-weight: normal;
165165
font-style: normal; }
166166
*/
167+
168+
#reload_warning {
169+
position: absolute;
170+
left: 20px;
171+
bottom: 20px;
172+
font-size: 12;
173+
width: 300px;
174+
height: auto;
175+
background-color: white;
176+
z-index: 10;
177+
box-shadow: rgba(9, 20, 66, 0.25) 0px 20px 32px -8px;
178+
border: #ddd solid;
179+
padding: 10px;
180+
border-width: 1px;
181+
display: none;
182+
}

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ <h3>Report Recovery</h3>
405405
</div>
406406
</div>
407407
</div>
408+
409+
<div id="reload_warning">This version of SondeHub is out of date. <a href="javascript:window.location.reload(true)">Click here to reload</a>. Page will reload automatically in <span id="reload_timer"></span>
410+
</div>
411+
408412
<!-- Was 3.31-->
409413
<script type="text/javascript" language="javascript" src="https://www.google.com/recaptcha/api.js" async defer></script>
410414
<script type="text/javascript" language="javascript" src="https://xc5dqkj2cgb1.statuspage.io/embed/script.js" async defer></script>

js/app.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ var updateTime = function(date) {
456456
}
457457
};
458458

459+
const version = "{VER}";
459460

460461
$(window).ready(function() {
461462
// refresh timebox
@@ -464,7 +465,7 @@ $(window).ready(function() {
464465
}, 1000);
465466

466467
// Update Tracker version info
467-
$('#build_version').text("{VER}");
468+
$('#build_version').text(version);
468469
$('#build_date').text("{BUILD_DATE}");
469470

470471
// resize elements if needed
@@ -999,3 +1000,33 @@ $(window).ready(function() {
9991000
clean_refresh(wvar.mode, true, true);
10001001
});
10011002
});
1003+
1004+
1005+
function check_version(){
1006+
const updateRequest = new Request("/js/version.json");
1007+
fetch(updateRequest)
1008+
.then(function(response){ return response.json()})
1009+
.then(function(response){
1010+
if (response['version'] != version) {
1011+
reload_timer = window.setTimeout(update_site, response['refresh']*1000)
1012+
reload_end_time = new Date().getTime() +response['refresh']*1000
1013+
update_countdown();
1014+
countdown_interval = setInterval(update_countdown, 100);
1015+
document.getElementById("reload_warning").style.display = "block";
1016+
}
1017+
})
1018+
}
1019+
function update_site(){
1020+
window.location.reload(true)
1021+
}
1022+
1023+
function update_countdown(){
1024+
var date = new Date(0);
1025+
time_remaining = (reload_end_time - new Date().getTime())/1000
1026+
date.setSeconds(time_remaining);
1027+
var timeString = date.toISOString().substring(11, 19); // hacky
1028+
document.getElementById("reload_timer").innerText = timeString;
1029+
}
1030+
1031+
check_version()
1032+
update_check = setInterval(check_version, 15 * 60 * 1000)

js/tracker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var client = new Paho.Client(livedata, clientID);
1616
var clientConnected = false;
1717
var clientActive = false;
1818
var clientTopic = [];
19+
var alwaysSub = [];
1920
var messageRate = 0;
2021
var messageRateAverage = 10;
2122

0 commit comments

Comments
 (0)