From 70bf316aebc2911ad513b54687fe305f4714bda9 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sun, 7 Jul 2024 22:14:00 +1200 Subject: [PATCH] only show push notification if window is not focussed --- public/index.html | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/public/index.html b/public/index.html index 09be43b..cf79039 100644 --- a/public/index.html +++ b/public/index.html @@ -1404,14 +1404,17 @@ } - // show notification for new messages when using electron - Notification.requestPermission().then((result) => { - if(result === "granted"){ - new window.Notification("New Message", { - body: "Someone sent you a message.", - }); - } - }); + // show notification for new messages if window is not focussed + if(!document.hasFocus()){ + Notification.requestPermission().then((result) => { + if(result === "granted"){ + new window.Notification("New Message", { + body: "Someone sent you a message.", + tag: "new_message", // only ever show one notification at a time + }); + } + }); + } // auto scroll to bottom if we want to if(this.autoScrollOnNewMessage){