diff --git a/public/icon-192.png b/public/icon-192.png new file mode 100644 index 0000000..55dfa62 Binary files /dev/null and b/public/icon-192.png differ diff --git a/public/icon-512.png b/public/icon-512.png new file mode 100644 index 0000000..dcf0f05 Binary files /dev/null and b/public/icon-512.png differ diff --git a/public/manifest.webmanifest b/public/manifest.webmanifest new file mode 100644 index 0000000..a06805e --- /dev/null +++ b/public/manifest.webmanifest @@ -0,0 +1,21 @@ +{ + "name": "NutStack", + "short_name": "NutStack", + "description": "Nostr application with Cashu wallet integration", + "start_url": "/", + "display": "standalone", + "background_color": "#000000", + "theme_color": "#000000", + "icons": [ + { + "src": "/icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/icon-512.png", + "sizes": "512x512", + "type": "image/png" + } + ] +} \ No newline at end of file diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 0000000..2a71498 --- /dev/null +++ b/public/sw.js @@ -0,0 +1,33 @@ +// public/sw.js + +self.addEventListener("push", (event) => { + if (!event.data) return; + + try { + const data = event.data.json(); + + const title = data.title || "New Notification"; + const options = { + body: data.body, + icon: data.icon || "/icon-192.png" + // badge: data.badge || "/badge-72x72.png", + // data: data.data || {}, + }; + + event.waitUntil( + self.registration.showNotification(title, options) + ); + } catch (err) { + console.error("Push event error:", err); + } +}); + +self.addEventListener("notificationclick", (event) => { + event.notification.close(); + + // If you send a `url` in payload.data, open it + const url = event.notification.data?.url; + if (url) { + event.waitUntil(clients.openWindow(url)); + } +}); diff --git a/src/main.tsx b/src/main.tsx index e263904..6bce006 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -15,3 +15,16 @@ createRoot(document.getElementById("root")!).render( ); + +// Register service worker for PWA +if ('serviceWorker' in navigator) { + window.addEventListener('load', () => { + navigator.serviceWorker.register('/sw.js') + .then((registration) => { + console.log('SW registered: ', registration); + }) + .catch((registrationError) => { + console.log('SW registration failed: ', registrationError); + }); + }); +} \ No newline at end of file