add web notification popup

This commit is contained in:
Peter Maquiran
2021-08-31 11:10:40 +01:00
parent 8056981ca1
commit b9b3f5be24
3 changed files with 70 additions and 1 deletions
@@ -0,0 +1,47 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class WebNotificationPopupService {
constructor() { }
askNotificationPermission() {
// function to actually ask the permissions
function handlePermission(permission) {}
// Let's check if the browser supports notifications
if (!('Notification' in window)) {
console.log("This browser does not support notifications.");
} else {
if(this.checkNotificationPromise()) {
Notification.requestPermission()
.then((permission) => {
handlePermission(permission);
})
} else {
Notification.requestPermission(function(permission) {
handlePermission(permission);
});
}
}
}
private checkNotificationPromise() {
try {
Notification.requestPermission().then();
} catch(e) {
return false;
}
return true;
}
sendNotification(message) {
var n = new Notification(message);
}
}