fix(date): correction on date utils
Some checks failed
Deploy to Development / build-and-deploy (push) Has been cancelled
Deploy to Production / build-and-deploy (push) Successful in 1m51s

This commit is contained in:
EvanChal
2026-01-26 22:43:35 +01:00
parent d63f2f9f51
commit 08810440e0
13 changed files with 4981 additions and 105 deletions

View File

@@ -7,6 +7,47 @@ class NotificationService {
this.isPolling = false
}
// Détecter iOS
isIOS() {
return /iPhone|iPad|iPod/i.test(navigator.userAgent)
}
// Vérifier si la PWA est installée (nécessaire pour iOS)
isPWAInstalled() {
return window.matchMedia('(display-mode: standalone)').matches ||
window.navigator.standalone === true ||
document.referrer.includes('android-app://')
}
// Vérifier si les notifications sont supportées sur cette plateforme
isNotificationSupported() {
if (!('Notification' in window)) {
console.warn('Notifications API not supported')
return false
}
// Sur iOS, les notifications push ne fonctionnent que si la PWA est installée (iOS 16.4+)
if (this.isIOS()) {
if (!this.isPWAInstalled()) {
console.warn('iOS: Notifications push require PWA to be installed (added to home screen)')
return false
}
// Vérifier la version iOS (approximatif via user agent)
const iosVersion = navigator.userAgent.match(/OS (\d+)_(\d+)/)
if (iosVersion) {
const major = parseInt(iosVersion[1], 10)
const minor = parseInt(iosVersion[2], 10)
if (major < 16 || (major === 16 && minor < 4)) {
console.warn('iOS: Push notifications require iOS 16.4 or later')
return false
}
}
}
return true
}
startPolling() {
if (this.isPolling) return
@@ -89,28 +130,74 @@ class NotificationService {
// Gestion des notifications push PWA
async requestNotificationPermission() {
if (!('Notification' in window)) {
console.log('Ce navigateur ne supporte pas les notifications')
if (!this.isNotificationSupported()) {
console.log('Notifications not supported on this platform')
return false
}
if (Notification.permission === 'granted') {
console.log('Notification permission already granted')
return true
}
if (Notification.permission !== 'denied') {
const permission = await Notification.requestPermission()
return permission === 'granted'
if (Notification.permission === 'denied') {
console.warn('Notification permission denied by user')
return false
}
return false
// Sur iOS, s'assurer que la PWA est installée avant de demander
if (this.isIOS() && !this.isPWAInstalled()) {
console.warn('iOS: Cannot request notification permission - PWA must be installed first')
return false
}
try {
const permission = await Notification.requestPermission()
const granted = permission === 'granted'
if (granted) {
console.log('Notification permission granted')
} else {
console.warn('Notification permission denied:', permission)
}
return granted
} catch (error) {
console.error('Error requesting notification permission:', error)
return false
}
}
async showPushNotification(title, options = {}) {
if (!('Notification' in window)) return
if (!this.isNotificationSupported()) {
console.warn('Cannot show notification - not supported on this platform')
return null
}
const hasPermission = await this.requestNotificationPermission()
if (!hasPermission) return
if (!hasPermission) {
console.warn('Cannot show notification - permission not granted')
return null
}
// Préparer les options de notification (iOS ne supporte pas vibrate)
const notificationOptions = {
body: options.body || options.message || '',
icon: '/icon-192x192.png',
badge: '/icon-96x96.png',
tag: 'lediscord-notification',
requireInteraction: false,
data: {
link: options.link || '/',
notificationId: options.data?.notificationId
},
...options
}
// Retirer vibrate sur iOS (non supporté)
if (!this.isIOS()) {
notificationOptions.vibrate = [200, 100, 200]
}
// Toujours utiliser le service worker pour les notifications push
// Cela permet aux notifications de fonctionner même quand l'app est fermée
@@ -118,74 +205,58 @@ class NotificationService {
try {
const registration = await navigator.serviceWorker.ready
if (!registration.active) {
console.warn('Service worker not active, using fallback')
throw new Error('Service worker not active')
}
// Envoyer un message au service worker pour afficher la notification
// Cela permet de gérer les clics correctement
registration.active?.postMessage({
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
}
options: notificationOptions
})
// 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
// Aussi utiliser l'API directe du service worker
await registration.showNotification(title, notificationOptions)
console.log('Notification shown via service worker')
return null
} catch (error) {
console.error('Error showing notification via service worker:', error)
// Continuer avec le fallback
}
}
// 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
})
try {
const notification = new Notification(title, notificationOptions)
notification.onclick = () => {
window.focus()
notification.close()
if (options.link) {
// Utiliser le router si disponible
if (window.location.pathname !== options.link) {
window.location.href = options.link
notification.onclick = () => {
window.focus()
notification.close()
if (options.link) {
// Utiliser le router si disponible
if (window.location.pathname !== options.link) {
window.location.href = options.link
}
}
}
// Fermer automatiquement après 5 secondes (sauf sur iOS où c'est géré par le système)
if (!this.isIOS()) {
setTimeout(() => {
notification.close()
}, 5000)
}
console.log('Notification shown via native API')
return notification
} catch (error) {
console.error('Error showing notification:', error)
return null
}
// Fermer automatiquement après 5 secondes
setTimeout(() => {
notification.close()
}, 5000)
return notification
}
// Écouter les messages du service worker pour les notifications push