Stop monitored subs when unloading page

This commit is contained in:
Squidly271
2025-03-24 11:33:38 -04:00
parent 7dbc9d14a5
commit 782baac3f0
2 changed files with 18 additions and 19 deletions
+1 -16
View File
@@ -1813,13 +1813,6 @@ $(function() {
$('#netline').val(netline);
$.removeCookie('lockbutton');
// remember latest graph values
$(window).on('beforeunload',function(e){
var data = {};
data.cpu = cpu.tail(cpuline);
data.rxd = rxd.tail(netline);
data.txd = txd.tail(netline);
// $.post('/webGui/include/InitCharts.php',{cmd:'set',data:JSON.stringify(data)});
});
});
// Start graphs over again when window back in focus
@@ -1830,13 +1823,5 @@ $(window).blur(function() {
txd = [];
});
<?endif;?>
window.onunload = function(){
dashboard.stop();
<?if ($vmusage == "Y"):?>
vmdashusage.stop();
<?endif;?>
<?if ($apcupsd):?>
apcups.stop();
<?endif;?>
}
</script>
@@ -1235,7 +1235,7 @@ $('body').on('click','a,.ca_href', function(e) {
}
}
});
// Start & stop live updates when window loses focus
var nchanPaused = false;
<? if ( $display['liveUpdate'] == "no" ):?>
@@ -1249,7 +1249,21 @@ $(window).focus(function() {
}
});
// Stop nchan on loss of focus
$(window).blur(function() {
nchanFocusStop(true);
});
// Include both beforeunload and unload as this may be unreliable in certain circumstances on mobile devices
window.onbeforeunload = function() {
nchanFocusStop(false);
}
window.onunload = function() {
nchanFocusStop(false);
}
function nchanFocusStop(banner) {
if ( subscribers.length ) {
if ( nchanPaused === false ) {
var newsub = subscribers;
@@ -1261,12 +1275,12 @@ $(window).blur(function() {
}
});
subscribers = newsub;
if ( subscribers.length ) {
if ( banner && subscribers.length ) {
nchanPaused = addBannerWarning("<?=_('Live Updates Paused');?>",false,true );
}
}
}
});
}
<?endif;?>
</script>
</body>