aboutsummaryrefslogtreecommitdiff
path: root/src/api/Notifications/Notifications.tsx
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2023-02-14 19:20:10 +0100
committerVendicated <vendicated@riseup.net>2023-02-14 19:20:10 +0100
commit68055977d24c25cd2d086cba173abb392059b03d (patch)
treea1209e3626ad6a03feec2bf0aa315ad18144ead8 /src/api/Notifications/Notifications.tsx
parent2b0c25b45ccd66612899bb493a59d275458cd46d (diff)
downloadVencord-68055977d24c25cd2d086cba173abb392059b03d.tar.gz
Vencord-68055977d24c25cd2d086cba173abb392059b03d.tar.bz2
Vencord-68055977d24c25cd2d086cba173abb392059b03d.zip
NotificationAPI: Correctly request browser permissions
Diffstat (limited to 'src/api/Notifications/Notifications.tsx')
-rw-r--r--src/api/Notifications/Notifications.tsx11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/api/Notifications/Notifications.tsx b/src/api/Notifications/Notifications.tsx
index 9c599aa..46472ad 100644
--- a/src/api/Notifications/Notifications.tsx
+++ b/src/api/Notifications/Notifications.tsx
@@ -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,