diff --git a/InvenTree/InvenTree/static/script/inventree/inventree.js b/InvenTree/InvenTree/static/script/inventree/inventree.js index 1182552bf8..dd9a725fa1 100644 --- a/InvenTree/InvenTree/static/script/inventree/inventree.js +++ b/InvenTree/InvenTree/static/script/inventree/inventree.js @@ -218,11 +218,12 @@ function inventreeDocReady() { // Display any cached alert messages showCachedAlerts(); - // Start notification background worker to check every 5 seconds if notifications are available - setInterval(notificationCheck, 5000); + // Start notification background worker to check every 1 seconds if notifications are available + setInterval(notificationCheck, 1000); + // also run when the focus returns $(document).on('focus', function(e){ - notificationCheck(); + notificationCheck(force = true); }); $('#offcanvasRight').on('show.bs.offcanvas', openNotificationPanel) // listener for opening the notification panel diff --git a/InvenTree/InvenTree/static/script/inventree/notification.js b/InvenTree/InvenTree/static/script/inventree/notification.js index bdee5d200f..50a260af97 100644 --- a/InvenTree/InvenTree/static/script/inventree/notification.js +++ b/InvenTree/InvenTree/static/script/inventree/notification.js @@ -119,14 +119,20 @@ function showMessage(message, options={}) { }); } - +var notificationUpdateTic = 0; /** * The notification checker is initiated when the document is loaded. It checks if there are unread notifications * if unread messages exist the alert flag is raised by making it visible **/ -function notificationCheck() { - // only refresh state if in focus - if (document.hasFocus()) { +function notificationCheck(force = false) { + notificationUpdateTic = notificationUpdateTic + 1; + + console.log(notificationUpdateTic); + + // refresh if forced or + // if in focus and was not refreshed in the last 5 seconds + if (force || (document.hasFocus() && notificationUpdateTic >= 5)) { + notificationUpdateTic = 0; inventreeGet( '/api/notifications/', { @@ -262,6 +268,9 @@ function closeNotificationPanel() { * updates the notification counter **/ function updateNotificationIndicator(count) { + // reset update Ticker -> safe some API bandwidth + notificationUpdateTic = 0; + if (count == 0) { $("#notification-alert").addClass("d-none"); } else {