mirror of
https://github.com/dergigi/boris.git
synced 2026-02-01 05:04:29 +01:00
5.2 KiB
5.2 KiB
PWA Implementation Summary
Boris has been successfully upgraded to a full Progressive Web App (PWA)!
What Was Implemented
1. Web App Manifest
- File:
public/manifest.webmanifest - Includes app name, description, theme colors, and icon references
- Configured for standalone display mode
- Linked in
index.htmlwith theme-color meta tag
2. Service Worker with Workbox
- File:
src/sw.ts - Plugin:
vite-plugin-pwawith injectManifest strategy - Features:
- Precaching of app shell (HTML, CSS, JS assets)
- Runtime caching for cross-origin images (30-day cache, max 300 entries)
- Runtime caching for cross-origin article HTML (14-day cache, max 100 entries)
- SPA navigation fallback for offline app loading
- Automatic cleanup of old caches
- WebSocket traffic is NOT intercepted - relay functionality preserved
3. PWA Install Experience
- Hook:
src/hooks/usePWAInstall.ts - Component:
src/components/Settings/PWASettings.tsx - Captures
beforeinstallpromptevent - Shows install button in Settings when app is installable
- Displays confirmation when app is already installed
4. Online/Offline Status
- Hook:
src/hooks/useOnlineStatus.ts - Monitors
navigator.onLinestatus - Shows toast notification when going offline
- Integrated into main App component
5. Service Worker Updates
- Checks for updates hourly
- Shows toast notification when new version is available
- User can refresh to get latest version
Files Created/Modified
New Files
src/sw.ts- Workbox service workersrc/hooks/usePWAInstall.ts- Install prompt hooksrc/hooks/useOnlineStatus.ts- Online status monitoringsrc/components/Settings/PWASettings.tsx- Install UIpublic/manifest.webmanifest- Web app manifestpublic/icon-*.png- PWA icons (placeholders)
Modified Files
vite.config.ts- Added VitePWA plugin configurationindex.html- Added manifest link and theme-colorsrc/main.tsx- Enhanced SW registrationsrc/App.tsx- Added online/offline monitoringsrc/components/Settings.tsx- Added PWA settings sectionpackage.json- Added PWA dependencies
Icon Placeholders
⚠️ IMPORTANT: Replace placeholder icons with proper branded designs!
Current placeholders are minimal 1x1 pixel images. You need:
public/icon-192.png- 192x192px app iconpublic/icon-512.png- 512x512px app iconpublic/icon-maskable-192.png- 192x192px with safe area paddingpublic/icon-maskable-512.png- 512x512px with safe area padding
Maskable icons should have ~20% padding on all sides to ensure they look good on all devices.
Testing PWA Functionality
Local Development
npm run build
npm run preview # or serve the dist/ folder
What to Test
- Install prompt: Visit in Chrome/Edge, check for install button in Settings
- Offline mode: Disconnect network, verify app shell loads
- Cached images: View articles with images, go offline, images still load
- Cached articles: View external articles, go offline, articles still available
- Relay connectivity: Verify local relay and WebSocket connections work
- Updates: Deploy new version, verify update notification appears
Lighthouse PWA Audit
Run in Chrome DevTools:
- Open DevTools (F12)
- Go to Lighthouse tab
- Select "Progressive Web App" category
- Run audit
Expected scores:
- ✅ Installable
- ✅ PWA Optimized
- ✅ Works offline
- ⚠️ Icons (will pass after replacing placeholders)
Build Output
The build process now:
- Compiles TypeScript and bundles assets
- Generates Workbox service worker from
src/sw.ts - Injects precache manifest with all app assets
- Outputs
dist/sw.jsanddist/manifest.webmanifest
Build command:
npm run build
Deployment Notes
Vercel/Cloudflare/Netlify
- No special configuration needed
_headers,_redirects,_routes.jsonalready excluded from precache- Service worker will be served at
/sw.js - Manifest will be served at
/manifest.webmanifest
CDN Considerations
- Set proper cache headers for
sw.js(short cache, must-revalidate) - App assets can have long cache (they're versioned)
- Icons and manifest can have moderate cache (1 hour - 1 day)
Existing Functionality Preserved
✅ Local Relay: WebSocket connections not intercepted by SW ✅ Airplane Mode: Existing offline sync functionality intact ✅ Image Caching: Behavior preserved, now using Workbox ✅ Nostr Events: All relay operations work as before
Next Steps
- Replace icon placeholders with branded designs
- Test install flow on mobile devices (iOS Safari, Android Chrome)
- Test offline experience thoroughly
- Monitor service worker updates in production
- Consider adding:
- Web Share Target (share to Boris from system share sheet)
- Background Sync (queue writes when offline)
- Badging API (unread counts on app icon)
- Push notifications (optional, requires push service)