mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
add web notification popup
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user