From 65e9c0fc19d62584e0e48ebe224963a4166cddf7 Mon Sep 17 00:00:00 2001 From: Nathan Lamy Date: Tue, 19 Aug 2025 22:48:33 +0200 Subject: [PATCH] chore: fix a typo --- app/components/settings/notifications.tsx | 10 ++++++++-- app/lib/notification.ts | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/components/settings/notifications.tsx b/app/components/settings/notifications.tsx index 2fdc3c4..bfeacad 100644 --- a/app/components/settings/notifications.tsx +++ b/app/components/settings/notifications.tsx @@ -38,6 +38,9 @@ export default function NotificationSettings() { .then(() => { setPushEnabled(true); }) + .catch((error) => { + console.error("Failed to unregister notifications:", error); + }) .finally(() => { setIsRegistering(false); }); @@ -45,12 +48,15 @@ export default function NotificationSettings() { // Register notifications registerNotification() .then((result) => { - if ("error" in result) { + if ("error" in result && result.error) { console.error("Failed to register notifications:", result.error); } else { setPushEnabled(false); } }) + .catch((error) => { + console.error("Failed to unregister notifications:", error); + }) .finally(() => { setIsRegistering(false); }); @@ -121,7 +127,7 @@ export default function NotificationSettings() { - {isInstalled() ? ( + {!isInstalled() ? ( pushEnabled ? (
diff --git a/app/lib/notification.ts b/app/lib/notification.ts index a904e0f..ceaa147 100644 --- a/app/lib/notification.ts +++ b/app/lib/notification.ts @@ -9,12 +9,16 @@ export async function registerNotification() { error: "E_PERMISSION_DENIED", }; } - + if (!("serviceWorker" in navigator) || !("PushManager" in window)) { + return { + error: "E_UNSUPPORTED", + }; + } const registration = await navigator.serviceWorker.ready; try { const subscription = await registration.pushManager.subscribe({ userVisibleOnly: true, - applicationServerKey: process.env.VITE_PUBLIC_VAPID_KEY, + applicationServerKey: import.meta.env.VITE_PUBLIC_VAPID_KEY, }); await subscribe(subscription); // Store to local storage