feat: implement progressive web app support with offline capabilities

Add complete PWA implementation including service worker registration,
offline support, and installation prompts:

- Add vite-plugin-pwa and workbox-window dependencies for PWA tooling
- Configure VitePWA plugin with web app manifest and app metadata
- Set up Workbox caching strategies for API endpoints and CDN assets
- Implement service worker auto-update with user-triggered refresh
- Create usePWAInstall hook to handle beforeinstallprompt events
- Create useOnlineStatus hook for monitoring network connectivity
- Add InstallPrompt component with haptic feedback integration
- Add OfflineBanner component to notify users of offline status
- Configure PWA icons and assets (64x64, 192x192, 512x512 variants)
- Add TypeScript type declarations for virtual PWA register module
- Integrate PWA components and service worker into App.tsx and main.tsx
- Add PWA meta tags and viewport configuration to index.html
This commit is contained in:
weishu
2025-12-18 13:40:36 +08:00
parent 9be0a96af4
commit ea9f0f3b1a
19 changed files with 906 additions and 7 deletions
+40
View File
@@ -0,0 +1,40 @@
import { usePWAInstall } from '@/hooks/usePWAInstall'
import { usePlatform } from '@/hooks/usePlatform'
export function InstallPrompt() {
const { canInstall, promptInstall, isStandalone } = usePWAInstall()
const { isTelegram, haptic } = usePlatform()
if (isTelegram || isStandalone || !canInstall) {
return null
}
const handleInstall = async () => {
haptic.impact('light')
const success = await promptInstall()
if (success) {
haptic.notification('success')
}
}
return (
<div className="fixed bottom-4 left-4 right-4 bg-[var(--app-secondary-bg)] border border-[var(--app-border)] rounded-lg p-4 shadow-lg z-50">
<div className="flex items-center justify-between gap-3">
<div className="flex-1 min-w-0">
<p className="text-sm font-medium text-[var(--app-fg)]">
Install Happy App
</p>
<p className="text-xs text-[var(--app-hint)] mt-0.5">
Add to home screen for the best experience
</p>
</div>
<button
onClick={handleInstall}
className="shrink-0 px-4 py-2 bg-[var(--app-button)] text-[var(--app-button-text)] rounded-lg text-sm font-medium active:opacity-80"
>
Install
</button>
</div>
</div>
)
}
+15
View File
@@ -0,0 +1,15 @@
import { useOnlineStatus } from '@/hooks/useOnlineStatus'
export function OfflineBanner() {
const isOnline = useOnlineStatus()
if (isOnline) {
return null
}
return (
<div className="fixed top-0 left-0 right-0 bg-amber-500 text-white text-center py-2 text-sm font-medium z-50">
You're offline. Some features may be unavailable.
</div>
)
}