fix messenger background notifications #2440
Signed-off-by: si458 <simonsmith5521@gmail.com>
si458 committed
Dec 1, 2024 at 23:19 UTC
ce4217c346d7bcd6e2bdf3fb2657a14bad74cd61
1 file changed
+6
-6
views/messenger.handlebars
+6
-6
@@ -85,7 +85,6 @@
85
var remoteUserId = '{{{userid}}}';
86
var webrtcconfiguration = '{{{webrtcconfig}}}';
87
if (webrtcconfiguration == '') { webrtcconfiguration = null; } else { try { webrtcconfiguration = JSON.parse(decodeURIComponent(webrtcconfiguration)); } catch (ex) { console.log('Invalid WebRTC config: "' + webrtcconfiguration + '".'); webrtcconfiguration = null; } }
88
- var windowFocus = true;
88
var chatTextSession = new Date().toString() + '\r\n';
89
var localOutText = false;
90
var remoteOutText = false;
@@ -124,10 +123,6 @@
123
// Setup web notifications
124
try { if (Notification) { QV('notifyButton', Notification.permission != 'granted'); } } catch (ex) { notificationSupport = false; }
125
127
- // Track window focus
128
- window.addEventListener('focus', function (event) { windowFocus = true; }, false);
129
- window.addEventListener('blur', function (event) { windowFocus = false; }, false);
130
-
126
// Listen to drag & drop events
127
document.addEventListener('dragover', haltEvent, false);
128
document.addEventListener('dragleave', haltEvent, false);
@@ -237,9 +232,14 @@
232
// If web notifications are granted, use it.
233
if (notificationSupport) {
234
if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
240
- if (Notification && (windowFocus == false) && (Notification.permission == 'granted')) {
235
+ if (Notification && (document.visibilityState === 'hidden') && (Notification.permission == 'granted')) {
236
if (notification != null) { notification.close(); notification = null; }
237
notification = new Notification(Q('xtitle').innerHTML.split(' ').join(' '), { body: msg });
238
+ notification.onclick = function(event) {
239
+ event.preventDefault();
240
+ if (document.visibilityState === 'hidden') window.focus();
241
+ notification.close();
242
+ };
243
}
244
}
245
}