From 2dcad150ebd8b41d391e222c0a78908170ffe879 Mon Sep 17 00:00:00 2001 From: nimbleghost <132819643+nimbleghost@users.noreply.github.com> Date: Wed, 14 Jun 2023 20:54:25 +0200 Subject: [PATCH] Add missing await --- web/public/sw.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/web/public/sw.js b/web/public/sw.js index 31d72ca4..ba70d01a 100644 --- a/web/public/sw.js +++ b/web/public/sw.js @@ -20,6 +20,8 @@ const broadcastChannel = new BroadcastChannel("web-push-broadcast"); const isImage = (filenameOrUrl) => filenameOrUrl?.match(/\.(png|jpe?g|gif|webp)$/i) ?? false; +const icon = "/static/images/ntfy.png"; + const addNotification = async (data) => { const db = await dbAsync(); @@ -41,15 +43,15 @@ const addNotification = async (data) => { self.navigator.setAppBadge?.(badgeCount); }; -const showNotification = (data) => { +const showNotification = async (data) => { const { subscription_id: subscriptionId, message } = data; // Please update the desktop notification in Notifier.js to match any changes here const image = isImage(message.attachment?.name) ? message.attachment.url : undefined; - self.registration.showNotification(formatTitleWithDefault(message, message.topic), { + await self.registration.showNotification(formatTitleWithDefault(message, message.topic), { tag: subscriptionId, body: formatMessage(message), - icon: image ?? "/static/images/ntfy.png", + icon: image ?? icon, image, data, timestamp: message.time * 1_000, @@ -70,7 +72,7 @@ const handlePush = async (data) => { if (data.event === "subscription_expiring") { await self.registration.showNotification("Notifications will be paused", { body: "Open ntfy to continue receiving notifications", - icon: "/static/images/ntfy.png", + icon, data, }); } else if (data.event === "message") { @@ -85,7 +87,7 @@ const handlePush = async (data) => { // We can't ignore the push, since permission can be revoked by the browser await self.registration.showNotification("Unknown notification received from server", { body: "You may need to update ntfy by opening the web app", - icon: "/static/images/ntfy.png", + icon, data, }); } @@ -132,6 +134,7 @@ const handleClick = async (event) => { console.error("[ServiceWorker] Error performing http action", e); self.registration.showNotification(`Unsuccessful action ${action.label} (${action.action})`, { body: e.message, + icon, }); } }