From 217d1ee87dbd64c6f907d2cf52650059fc2e80c7 Mon Sep 17 00:00:00 2001 From: Adrian Gruntkowski Date: Sat, 16 Nov 2024 19:10:27 +0100 Subject: [PATCH] Send notifications via service worker --- js/notifications.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/js/notifications.js b/js/notifications.js index f116c20..d2d97ef 100644 --- a/js/notifications.js +++ b/js/notifications.js @@ -14,9 +14,11 @@ export function authorizeNotifications(afterCallback) { }); } -export function sendNotification(titleSuffix, message) { - return new Notification(`Jenot ${titleSuffix}`, { - body: message, - icon: notificationIcon, - }); +export async function sendNotification(titleSuffix, message) { + return navigator.serviceWorker.ready.then((registration) => + registration.showNotification(`Jenot ${titleSuffix}`, { + body: message, + icon: notificationIcon, + }), + ); }