mirror of
https://github.com/Tony0410/quietthanks.git
synced 2026-05-24 13:21:38 +08:00
Add PWA infrastructure for iOS notification support
- Add manifest.json for proper PWA installation - Add service worker (sw.js) for push notification handling - Add ServiceWorkerProvider to register SW and manage notifications - Generate PNG icons (192x192, 512x512) for iOS compatibility - Update settings to show notification status and test button - Use service worker showNotification for iOS Safari compatibility Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
BIN
public/icons/icon-192.png
Normal file
BIN
public/icons/icon-192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
BIN
public/icons/icon-512.png
Normal file
BIN
public/icons/icon-512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
30
public/manifest.json
Normal file
30
public/manifest.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "Quiet Thanks",
|
||||
"short_name": "Quiet Thanks",
|
||||
"description": "A calm, private gratitude and mood log",
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#0a0a0a",
|
||||
"theme_color": "#0a0a0a",
|
||||
"orientation": "portrait-primary",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/icons/icon.svg",
|
||||
"sizes": "any",
|
||||
"type": "image/svg+xml",
|
||||
"purpose": "any maskable"
|
||||
},
|
||||
{
|
||||
"src": "/icons/icon-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/icons/icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
}
|
||||
],
|
||||
"categories": ["lifestyle", "health"],
|
||||
"id": "quiet-thanks-pwa"
|
||||
}
|
||||
94
public/sw.js
Normal file
94
public/sw.js
Normal file
@@ -0,0 +1,94 @@
|
||||
// Service Worker for Quiet Thanks PWA
|
||||
const CACHE_NAME = 'quiet-thanks-v1';
|
||||
|
||||
// Install event - cache essential assets
|
||||
self.addEventListener('install', (event) => {
|
||||
console.log('[SW] Installing service worker...');
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
// Activate event - clean up old caches
|
||||
self.addEventListener('activate', (event) => {
|
||||
console.log('[SW] Activating service worker...');
|
||||
event.waitUntil(clients.claim());
|
||||
});
|
||||
|
||||
// Push event - handle incoming push notifications
|
||||
self.addEventListener('push', (event) => {
|
||||
console.log('[SW] Push event received');
|
||||
|
||||
let data = {
|
||||
title: 'Quiet Thanks',
|
||||
body: 'Take a moment to reflect on what you\'re grateful for today.',
|
||||
icon: '/icons/icon.svg',
|
||||
badge: '/icons/icon.svg',
|
||||
tag: 'daily-reminder',
|
||||
};
|
||||
|
||||
if (event.data) {
|
||||
try {
|
||||
const payload = event.data.json();
|
||||
data = { ...data, ...payload };
|
||||
} catch (e) {
|
||||
data.body = event.data.text();
|
||||
}
|
||||
}
|
||||
|
||||
const options = {
|
||||
body: data.body,
|
||||
icon: data.icon,
|
||||
badge: data.badge,
|
||||
tag: data.tag,
|
||||
vibrate: [100, 50, 100],
|
||||
data: {
|
||||
url: '/',
|
||||
},
|
||||
actions: [
|
||||
{ action: 'open', title: 'Open app' },
|
||||
{ action: 'dismiss', title: 'Dismiss' },
|
||||
],
|
||||
};
|
||||
|
||||
event.waitUntil(
|
||||
self.registration.showNotification(data.title, options)
|
||||
);
|
||||
});
|
||||
|
||||
// Notification click handler
|
||||
self.addEventListener('notificationclick', (event) => {
|
||||
console.log('[SW] Notification clicked');
|
||||
event.notification.close();
|
||||
|
||||
if (event.action === 'dismiss') {
|
||||
return;
|
||||
}
|
||||
|
||||
event.waitUntil(
|
||||
clients.matchAll({ type: 'window', includeUncontrolled: true })
|
||||
.then((clientList) => {
|
||||
// Focus existing window if available
|
||||
for (const client of clientList) {
|
||||
if (client.url.includes(self.registration.scope) && 'focus' in client) {
|
||||
return client.focus();
|
||||
}
|
||||
}
|
||||
// Open new window
|
||||
if (clients.openWindow) {
|
||||
return clients.openWindow('/');
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// Periodic sync for background reminders (when supported)
|
||||
self.addEventListener('periodicsync', (event) => {
|
||||
if (event.tag === 'daily-reminder') {
|
||||
event.waitUntil(checkAndShowReminder());
|
||||
}
|
||||
});
|
||||
|
||||
async function checkAndShowReminder() {
|
||||
// This would check the reminder time and show notification if appropriate
|
||||
// For now, we rely on the client-side scheduler
|
||||
console.log('[SW] Periodic sync triggered');
|
||||
}
|
||||
Reference in New Issue
Block a user