PHPMailer neu implementiert
This commit is contained in:
102
sw.js
102
sw.js
@@ -35,38 +35,38 @@ self.addEventListener('activate', event => {
|
||||
});
|
||||
|
||||
// Fetch mit Network First für PHP, Cache First für statische Dateien
|
||||
self.addEventListener('fetch', event => {
|
||||
if (!event.request.url.startsWith('http')) return;
|
||||
self.addEventListener('fetch', function(event) {
|
||||
if (!event.request.url.startsWith('http')) return;
|
||||
|
||||
const url = new URL(event.request.url);
|
||||
|
||||
// Statische Ressourcen - Cache First
|
||||
if (url.pathname.endsWith('.css') ||
|
||||
url.pathname.endsWith('.png') ||
|
||||
url.pathname.endsWith('.jpg') ||
|
||||
url.pathname.endsWith('.js')) {
|
||||
event.respondWith(
|
||||
caches.match(event.request)
|
||||
.then(response => response || fetch(event.request))
|
||||
);
|
||||
}
|
||||
// Dynamische Seiten - Network First mit Offline-Fallback
|
||||
else {
|
||||
event.respondWith(
|
||||
fetch(event.request)
|
||||
.then(response => {
|
||||
// Bei erfolgreicher Antwort: in Cache speichern
|
||||
if (response && response.status === 200) {
|
||||
const responseToCache = response.clone();
|
||||
caches.open(CACHE_NAME).then(cache => {
|
||||
cache.put(event.request, responseToCache);
|
||||
});
|
||||
}
|
||||
return response;
|
||||
})
|
||||
.catch(() => caches.match('/offline.html'))
|
||||
);
|
||||
}
|
||||
const url = new URL(event.request.url);
|
||||
|
||||
// Statische Ressourcen - Cache First
|
||||
if (url.pathname.endsWith('.css') ||
|
||||
url.pathname.endsWith('.png') ||
|
||||
url.pathname.endsWith('.jpg') ||
|
||||
url.pathname.endsWith('.js')) {
|
||||
event.respondWith(
|
||||
caches.match(event.request)
|
||||
.then(response => response || fetch(event.request))
|
||||
);
|
||||
}
|
||||
// Dynamische Seiten - Network First mit Offline-Fallback
|
||||
else {
|
||||
event.respondWith(
|
||||
fetch(event.request)
|
||||
.then(response => {
|
||||
// Nur bei GET-Anfragen und erfolgreicher Antwort cachen
|
||||
if (response && response.status === 200 && event.request.method === 'GET') {
|
||||
const responseToCache = response.clone();
|
||||
caches.open(CACHE_NAME).then(cache => {
|
||||
cache.put(event.request, responseToCache);
|
||||
});
|
||||
}
|
||||
return response;
|
||||
})
|
||||
.catch(() => caches.match('/offline.html'))
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Nachrichten vom Client empfangen
|
||||
@@ -74,4 +74,44 @@ self.addEventListener('message', event => {
|
||||
if (event.data.action === 'skipWaiting') {
|
||||
self.skipWaiting();
|
||||
}
|
||||
});
|
||||
|
||||
// >>> NEU: Push-Benachrichtigungen <<<
|
||||
self.addEventListener('push', function(event) {
|
||||
let data = {};
|
||||
if (event.data) {
|
||||
data = event.data.json();
|
||||
}
|
||||
|
||||
const title = data.title || 'DoMiLi';
|
||||
const options = {
|
||||
body: data.body || 'Du hast eine neue Benachrichtigung.',
|
||||
icon: '/domili/favicon.ico',
|
||||
badge: '/domili/favicon.ico',
|
||||
vibrate: [200, 100, 200],
|
||||
data: {
|
||||
url: data.url || '/domili/'
|
||||
}
|
||||
};
|
||||
|
||||
event.waitUntil(
|
||||
self.registration.showNotification(title, options)
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('notificationclick', function(event) {
|
||||
event.notification.close();
|
||||
event.waitUntil(
|
||||
clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function(clientList) {
|
||||
for (let i = 0; i < clientList.length; i++) {
|
||||
let client = clientList[i];
|
||||
if (client.url === event.notification.data.url && 'focus' in client) {
|
||||
return client.focus();
|
||||
}
|
||||
}
|
||||
if (clients.openWindow) {
|
||||
return clients.openWindow(event.notification.data.url);
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user