akrherz / live

IEMChat/NWSChat Live Client
1 stars 2 forks source link

Add desktop notifications #31

Open akrherz opened 2 years ago

akrherz commented 2 years ago

Requested addition of desktop notifications.

Arch881010 commented 1 year ago

Possible idea: (You'd need to implement comment and the else statement can be changed to whatever. I have it there as debug and can be easily be overridden and set to cookies to check this.)

let permission = Notification.permission;
if(permission === "granted") {
   showNotification();
} else if(permission === "default"){
   requestAndShowPermission();
} else {
  console.warn('You don\'t have permissions enabled or set to asked! Missing PERMS')
}
function showNotification() {
   if(document.visibilityState === "visible") {
      return;
   }
   var title = "New Notification";
   var icon = "https://weather.im/live/images/nws.png"
   var body = "Message to be displayed";
   var notification = new Notification(title, { body, icon });
   notification.onclick = () => { 
      notification.close();
      window.parent.focus();
   }
}
function requestAndShowPermission() {
   Notification.requestPermission(function (permission) {
      if (permission === "granted") {
        showNotification();
      }
   });
}
Arch881010 commented 8 months ago

Bump @akrherz

akrherz commented 8 months ago

Sorry, I am generally not doing much development of the Live client.

Arch881010 commented 8 months ago

That's fine. Just making sure an idea of desktop notifications was actually seen for whenever you do.