Added notification settings page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 12s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 11s
Gemini PR Review / Gemini PR Review (pull_request) Successful in 17s
Laravel Pint / pint (pull_request) Failing after 2m43s
Laravel Larastan / larastan (pull_request) Failing after 2m47s

This commit is contained in:
dhanabalan
2026-01-23 18:11:00 +05:30
parent 9b5e66c834
commit 3ffc59f0cf
2 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
<x-filament-panels::page>
<button
type="button"
class="filament-button filament-button-primary"
onclick="registerPush()"
>
Enable Push Notifications
</button>
<script>
const vapidKey = "{{ config('webpush.vapid.public_key') }}";
const csrfToken = "{{ csrf_token() }}";
async function registerPush() {
if (!('serviceWorker' in navigator)) return;
const permission = await Notification.requestPermission();
if (permission != 'granted') return;
const registration = await navigator.serviceWorker.register('/service-worker.js');
const subscription = await registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: vapidKey
});
await fetch('/push/subscribe', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': csrfToken
},
body: JSON.stringify(subscription)
});
alert("Push notifications enabled ✅");
}
</script>
</x-filament-panels::page>