reduce needed cyle when idleing

This commit is contained in:
Matthias 2021-11-30 17:45:56 +01:00
parent cc9107d72a
commit ec7ef6ef1e
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
2 changed files with 24 additions and 5 deletions

View File

@ -218,12 +218,14 @@ function inventreeDocReady() {
// Display any cached alert messages // Display any cached alert messages
showCachedAlerts(); showCachedAlerts();
// Start notification background worker to check every 1 seconds if notifications are available // always refresh when the focus returns
setInterval(notificationCheck, 1000); $(document).focus(function(){
startNotificationWatcher();
});
// also run when the focus returns // kill notification watcher if focus is lost -> respect your users cycles
$(document).on('focus', function(e){ $(document).focusout(function(){
notificationCheck(force = true); stopNotificationWatcher();
}); });
$('#offcanvasRight').on('show.bs.offcanvas', openNotificationPanel) // listener for opening the notification panel $('#offcanvasRight').on('show.bs.offcanvas', openNotificationPanel) // listener for opening the notification panel

View File

@ -119,6 +119,23 @@ function showMessage(message, options={}) {
}); });
} }
var notificationWatcher = null; // reference for the notificationWatcher
/**
* start the regular notification checks
**/
function startNotificationWatcher() {
notificationCheck(force=true);
notificationWatcher = setInterval(notificationCheck, 1000);
}
/**
* stop the regular notification checks
**/
function stopNotificationWatcher() {
clearInterval(notificationWatcher);
}
var notificationUpdateTic = 0; var notificationUpdateTic = 0;
/** /**
* The notification checker is initiated when the document is loaded. It checks if there are unread notifications * The notification checker is initiated when the document is loaded. It checks if there are unread notifications