db4e552594cb | atagen | 2026-10-26 04:43 UTC | 1 | <script lang="ts"> |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 2 | import { disableNotifications, enableNotifications, notificationPermission, notificationsEnabled } from './notifications'; |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 3 | |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 4 | let busy = false; |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 5 | |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 6 | $: denied = $notificationPermission === 'denied'; |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 7 | $: unsupported = $notificationPermission === 'unsupported'; |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 8 | $: on = $notificationsEnabled && $notificationPermission === 'granted'; |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 9 | |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 10 | async function toggle(): Promise<void> { |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 11 | if (busy) return; |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 12 | busy = true; |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 13 | try { |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 14 | if (on) disableNotifications(); |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 15 | else await enableNotifications(); |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 16 | } finally { |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 17 | busy = false; |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 18 | } |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 19 | } |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 20 | </script> |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 21 | |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 22 | <section aria-label="Notifications"> |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 23 | <div class="sec-head"> |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 24 | <h3 class="sec-h">Notifications</h3> |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 25 | <span class="state" class:ok={on}>{unsupported ? 'Unavailable' : denied ? 'Blocked' : on ? 'On' : 'Off'}</span> |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 26 | </div> |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 27 | <button type="button" class="ghost-btn" disabled={busy || denied || unsupported} aria-pressed={on} on:click={() => void toggle()}> |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 28 | {on ? 'Turn off' : 'Turn on'} |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 29 | </button> |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 30 | </section> |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 31 | |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 32 | <style> |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 33 | section { margin-top: 18px; } |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 34 | .sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; } |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 35 | .sec-h { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0; } |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 36 | .state { font-size: 12px; color: var(--muted); } |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 37 | .state.ok { color: var(--accent); } |
db4e552594cb | atagen | 2026-10-26 04:43 UTC | 38 | </style> |