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
40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<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>
|