From ce4217c346d7bcd6e2bdf3fb2657a14bad74cd61 Mon Sep 17 00:00:00 2001 From: si458 Date: Sun, 1 Dec 2024 23:19:41 +0000 Subject: [PATCH] fix messenger background notifications #2440 Signed-off-by: si458 --- views/messenger.handlebars | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/views/messenger.handlebars b/views/messenger.handlebars index cf0d9115..cdc26c9e 100644 --- a/views/messenger.handlebars +++ b/views/messenger.handlebars @@ -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(' ').join(' '), { body: msg }); + notification.onclick = function(event) { + event.preventDefault(); + if (document.visibilityState === 'hidden') window.focus(); + notification.close(); + }; } } }