Skip to content

Commit c7bce43

Browse files
committed
double opt-in for notifications
1 parent 9f674c3 commit c7bce43

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

frontend/src/components/NotificationCenter.svelte

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,18 @@
204204
}
205205
206206
// getNotificationIcon now based on tags above
207-
208-
// Request notification permission
209-
if ('Notification' in window && Notification.permission === 'default') {
210-
Notification.requestPermission();
207+
208+
// Track permission state reactively
209+
let notificationPermission = $state(
210+
typeof window !== 'undefined' && 'Notification' in window
211+
? Notification.permission
212+
: 'denied'
213+
);
214+
215+
async function requestNotificationPermission(): Promise<void> {
216+
if (!('Notification' in window)) return;
217+
const result = await Notification.requestPermission();
218+
notificationPermission = result;
211219
}
212220
</script>
213221

@@ -242,6 +250,17 @@
242250
</button>
243251
{/if}
244252
</div>
253+
{#if notificationPermission === 'default'}
254+
<button
255+
onclick={requestNotificationPermission}
256+
class="mt-2 w-full text-xs text-fg-muted dark:text-dark-fg-muted hover:text-blue-600 dark:hover:text-blue-400 flex items-center justify-center gap-1"
257+
>
258+
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
259+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"></path>
260+
</svg>
261+
Enable desktop notifications
262+
</button>
263+
{/if}
245264
</div>
246265

247266
<div class="max-h-96 overflow-y-auto">

0 commit comments

Comments
 (0)