diff --git a/app/Jobs/StorePushNotification.php b/app/Jobs/StorePushNotification.php index 6329117..a06c2a8 100644 --- a/app/Jobs/StorePushNotification.php +++ b/app/Jobs/StorePushNotification.php @@ -43,7 +43,7 @@ public function handle(): void $webPush->sendOneNotification( Subscription::create(json_decode($notification->subscriptions, true)), $payload, - ['TTL' => 5000], + ['TTL' => 86400, 'urgency' => 'high'], ); } } diff --git a/public/manifest.json b/public/manifest.json new file mode 100644 index 0000000..fd89a1a --- /dev/null +++ b/public/manifest.json @@ -0,0 +1,20 @@ +{ + "name": "Pangestu Yadi Parfum", + "short_name": "PYParfum", + "start_url": "/", + "display": "standalone", + "background_color": "#ffffff", + "theme_color": "#000000", + "icons": [ + { + "src": "/assets/images/logo.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/assets/images/logo.png", + "sizes": "512x512", + "type": "image/png" + } + ] +} \ No newline at end of file diff --git a/public/service-worker.js b/public/service-worker.js index b8609a4..54724e0 100644 --- a/public/service-worker.js +++ b/public/service-worker.js @@ -1,11 +1,27 @@ +self.addEventListener('install', (event) => { + self.skipWaiting(); +}); + +self.addEventListener('activate', (event) => { + event.waitUntil(clients.claim()); +}); + self.addEventListener('push', (event) => { - const notification = event.data.json(); + let notification; + try { + notification = event.data.json(); + } catch (e) { + return; + } event.waitUntil( self.registration.showNotification( notification.title, { body: notification.body, icon: 'assets/images/dark-logo.png', + badge: 'assets/images/dark-logo.png', + vibrate: [200, 100, 200], + requireInteraction: true, data: { url: notification.url } @@ -14,7 +30,20 @@ self.addEventListener('push', (event) => { }) self.addEventListener('notificationclick', (event) => { + event.notification.close(); + event.waitUntil( - clients.openWindow(event.notification.data.url) + clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clientList) => { + // Check if there's already a tab open with this URL + for (const client of clientList) { + if (client.url === event.notification.data.url && 'focus' in client) { + return client.focus(); + } + } + // If not, open a new window + if (clients.openWindow) { + return clients.openWindow(event.notification.data.url); + } + }) ); -}) +}); diff --git a/resources/views/components/layouts/home.blade.php b/resources/views/components/layouts/home.blade.php index 1b9e636..2f7fad0 100644 --- a/resources/views/components/layouts/home.blade.php +++ b/resources/views/components/layouts/home.blade.php @@ -8,6 +8,7 @@ @vite(['resources/css/app.css', 'resources/js/app.js']) @fluxAppearance +