1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-02-12 02:51:50 +00:00

fix messenger background notifications #2440

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
si458 2024-12-01 23:19:41 +00:00
parent d9262f7c9d
commit ce4217c346

View file

@ -85,7 +85,6 @@
var remoteUserId = '{{{userid}}}';
var webrtcconfiguration = '{{{webrtcconfig}}}';
if (webrtcconfiguration == '') { webrtcconfiguration = null; } else { try { webrtcconfiguration = JSON.parse(decodeURIComponent(webrtcconfiguration)); } catch (ex) { console.log('Invalid WebRTC config: "' + webrtcconfiguration + '".'); webrtcconfiguration = null; } }
var windowFocus = true;
var chatTextSession = new Date().toString() + '\r\n';
var localOutText = false;
var remoteOutText = false;
@ -124,10 +123,6 @@
// Setup web notifications
try { if (Notification) { QV('notifyButton', Notification.permission != 'granted'); } } catch (ex) { notificationSupport = false; }
// Track window focus
window.addEventListener('focus', function (event) { windowFocus = true; }, false);
window.addEventListener('blur', function (event) { windowFocus = false; }, false);
// Listen to drag & drop events
document.addEventListener('dragover', haltEvent, false);
document.addEventListener('dragleave', haltEvent, false);
@ -237,9 +232,14 @@
// If web notifications are granted, use it.
if (notificationSupport) {
if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
if (Notification && (windowFocus == false) && (Notification.permission == 'granted')) {
if (Notification && (document.visibilityState === 'hidden') && (Notification.permission == 'granted')) {
if (notification != null) { notification.close(); notification = null; }
notification = new Notification(Q('xtitle').innerHTML.split('&nbsp;').join(' '), { body: msg });
notification.onclick = function(event) {
event.preventDefault();
if (document.visibilityState === 'hidden') window.focus();
notification.close();
};
}
}
}