fix(pwa+timezone)
Some checks failed
Deploy to Development / build-and-deploy (push) Has been cancelled
Deploy to Production / build-and-deploy (push) Successful in 1m32s

This commit is contained in:
EvanChal
2026-01-25 23:54:42 +01:00
parent e32b1ce04e
commit 02a54f5625
23 changed files with 579 additions and 85 deletions

View File

@@ -51,11 +51,25 @@ class NotificationService {
.slice(0, result.newCount - result.previousCount)
if (newUnreadNotifications.length > 0) {
// Ne pas afficher de notification si l'app est en focus
// (pour éviter les doublons avec les notifications dans l'app)
if (document.hasFocus()) {
return
}
// Afficher une notification push pour la plus récente
const latestNotification = newUnreadNotifications[0]
// Gérer les liens de posts différemment
let link = latestNotification.link || '/'
if (link.startsWith('/posts/')) {
const postId = link.split('/posts/')[1]
link = `/posts?highlight=${postId}`
}
await this.showPushNotification(latestNotification.title, {
body: latestNotification.message,
link: latestNotification.link || '/',
link: link,
data: { notificationId: latestNotification.id }
})
}
@@ -98,16 +112,44 @@ class NotificationService {
const hasPermission = await this.requestNotificationPermission()
if (!hasPermission) return
// Si on est dans un service worker, utiliser la notification API du SW
// Toujours utiliser le service worker pour les notifications push
// Cela permet aux notifications de fonctionner même quand l'app est fermée
if ('serviceWorker' in navigator) {
try {
const registration = await navigator.serviceWorker.ready
// Envoyer un message au service worker pour afficher la notification
// Cela permet de gérer les clics correctement
registration.active?.postMessage({
type: 'SHOW_NOTIFICATION',
title,
options: {
body: options.body || options.message || '',
icon: '/icon-192x192.png',
badge: '/icon-96x96.png',
tag: 'lediscord-notification',
requireInteraction: false,
vibrate: [200, 100, 200],
data: {
link: options.link || '/',
notificationId: options.data?.notificationId
},
...options
}
})
// Aussi utiliser l'API directe comme fallback
await registration.showNotification(title, {
icon: '/icon-192x192.png',
badge: '/icon-96x96.png',
tag: 'lediscord-notification',
requireInteraction: false,
vibrate: [200, 100, 200],
data: {
link: options.link || '/',
notificationId: options.data?.notificationId
},
body: options.body || options.message || '',
...options
})
return
@@ -116,12 +158,13 @@ class NotificationService {
}
}
// Fallback: notification native du navigateur
// Fallback: notification native du navigateur (seulement si le SW n'est pas disponible)
const notification = new Notification(title, {
icon: '/icon-192x192.png',
badge: '/icon-96x96.png',
tag: 'lediscord-notification',
requireInteraction: false,
body: options.body || options.message || '',
...options
})
@@ -130,7 +173,10 @@ class NotificationService {
notification.close()
if (options.link) {
window.location.href = options.link
// Utiliser le router si disponible
if (window.location.pathname !== options.link) {
window.location.href = options.link
}
}
}