NotificationAPI: Correctly request browser permissions

This commit is contained in:
Vendicated 2023-02-14 19:20:10 +01:00
parent 2b0c25b45c
commit 68055977d2
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
2 changed files with 16 additions and 2 deletions

View file

@ -76,8 +76,15 @@ function shouldBeNative() {
return false;
}
export function showNotification(data: NotificationData) {
if (shouldBeNative()) {
export async function requestPermission() {
return (
Notification.permission === "granted" ||
(Notification.permission !== "denied" && (await Notification.requestPermission()) === "granted")
);
}
export async function showNotification(data: NotificationData) {
if (shouldBeNative() && await requestPermission()) {
const { title, body, icon, image, onClick = null, onClose = null } = data;
const n = new Notification(title, {
body,