diff --git a/emhttp/plugins/dynamix.docker.manager/DockerContainers.page b/emhttp/plugins/dynamix.docker.manager/DockerContainers.page index 3d18edb88..b88a44dc4 100644 --- a/emhttp/plugins/dynamix.docker.manager/DockerContainers.page +++ b/emhttp/plugins/dynamix.docker.manager/DockerContainers.page @@ -192,7 +192,7 @@ $(function() { }); $.removeCookie('lockbutton'); loadlist(true); - dockerload.start(); + dockerload.start().monitor(); }); diff --git a/emhttp/plugins/dynamix/ArrayOperation.page b/emhttp/plugins/dynamix/ArrayOperation.page index 8ec38e4bb..8be2d5cab 100644 --- a/emhttp/plugins/dynamix/ArrayOperation.page +++ b/emhttp/plugins/dynamix/ArrayOperation.page @@ -114,7 +114,7 @@ function toggle_state(device,name,action) { button = '[id^=button-]'; } devices.stop(); - $.post('/webGui/include/ToggleState.php',{device:device,name:name,action:action},function(){setTimeout(function(){devices.start();},1000);if (button) $(button).prop('disabled',false);}); + $.post('/webGui/include/ToggleState.php',{device:device,name:name,action:action},function(){setTimeout(function(){devices.start().monitor();},1000);if (button) $(button).prop('disabled',false);}); } function display_diskio() { @@ -420,7 +420,7 @@ devices.on('message', function(msg,meta) { break; } }); -devices.start(); +devices.start().monitor(); var fsState = new NchanSubscriber('/sub/fsState',{subscriber:'websocket', reconnectTimeout:5000}); diff --git a/emhttp/plugins/dynamix/DashStats.page b/emhttp/plugins/dynamix/DashStats.page index b553c9b75..25ce5891c 100644 --- a/emhttp/plugins/dynamix/DashStats.page +++ b/emhttp/plugins/dynamix/DashStats.page @@ -1795,12 +1795,12 @@ $(function() { dropdown('enter_view'); startup = false; - dashboard.start(); + dashboard.start().monitor(); - vmdashusage.start(); + vmdashusage.start().monitor(); - apcups.start(); + apcups.start().monitor(); update900(); toggleChart(true); diff --git a/emhttp/plugins/dynamix/DisplaySettings.page b/emhttp/plugins/dynamix/DisplaySettings.page index 4ee14acb2..10d6a86ea 100644 --- a/emhttp/plugins/dynamix/DisplaySettings.page +++ b/emhttp/plugins/dynamix/DisplaySettings.page @@ -323,6 +323,12 @@ _(Favorites enabled)_: :display_favorites_enabled_help: +_(Allow realtime updates on inactive browsers)_: +: + : diff --git a/emhttp/plugins/dynamix/default.cfg b/emhttp/plugins/dynamix/default.cfg index 9096beced..46a20fb8e 100644 --- a/emhttp/plugins/dynamix/default.cfg +++ b/emhttp/plugins/dynamix/default.cfg @@ -35,6 +35,7 @@ headermetacolor="" headerdescription="yes" showBannerGradient="yes" favorites="yes" +liveUpdate="no" [parity] mode="0" hour="0 0" diff --git a/emhttp/plugins/dynamix/include/DefaultPageLayout.php b/emhttp/plugins/dynamix/include/DefaultPageLayout.php index 23184b0d6..291e652cf 100644 --- a/emhttp/plugins/dynamix/include/DefaultPageLayout.php +++ b/emhttp/plugins/dynamix/include/DefaultPageLayout.php @@ -105,10 +105,14 @@ if (!file_exists($notes)) file_put_contents($notes,shell_exec("$docroot/plugins/ \n"; echo "
"; $tab = 1; $pages = []; @@ -1270,6 +1271,76 @@ $('body').on('click','a,.ca_href', function(e) { } } }); + +// Start & stop live updates when window loses focus +var nchanPaused = false; +var blurTimer = false; + +$(window).focus(function() { + nchanFocusStart(); +}); + +// Stop nchan on loss of focus + +$(window).blur(function() { + blurTimer = setTimeout(function(){ + nchanFocusStop(); + },30000); +}); + + +document.addEventListener("visibilitychange", (event) => { + + if (document.hidden) { + nchanFocusStop(); + } + + if (document.hidden) { + nchanFocusStop(); + } else { + nchanFocusStart(); + } + +}); + +function nchanFocusStart() { + if ( blurTimer !== false ) { + clearTimeout(blurTimer); + blurTimer = false; + } + + if (nchanPaused !== false ) { + removeBannerWarning(nchanPaused); + nchanPaused = false; + + try { + pageFocusFunction(); + } catch(error) {} + + subscribers.forEach(function(e) { + e.start(); + }); + } +} + +function nchanFocusStop(banner=true) { + if ( subscribers.length ) { + if ( nchanPaused === false ) { + var newsub = subscribers; + subscribers.forEach(function(e) { + try { + e.stop(); + } catch(err) { + newsub.splice(newsub.indexOf(e,1)); + } + }); + subscribers = newsub; + if ( banner && subscribers.length ) { + nchanPaused = addBannerWarning("",false,true ); + } + } + } +}