feat(pwa): implement PWA installation banner and context provider

- Add `generate-icons.ts` script to generate PWA icons from SVG.
- Create `InstallBanner` component for prompting users to install the app.
- Implement `PwaProvider` to manage PWA installation state and events.
- Export `PwaProvider` and `InstallBanner` from the PWA feature index.
This commit is contained in:
Jose Selesan
2026-09-28 20:55:48 -03:00
parent 05da085e36
commit 2fd1826014
23 changed files with 1032 additions and 24 deletions

View File

@@ -2,10 +2,79 @@ import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { tanstackRouter } from '@tanstack/router-plugin/vite'
import { VitePWA } from 'vite-plugin-pwa'
export default defineConfig({
plugins: [tanstackRouter({ target: 'react' }), react(), tailwindcss()],
plugins: [
tanstackRouter({ target: 'react' }),
react(),
tailwindcss(),
VitePWA({
// `autoUpdate` activa skipWaiting + clientsClaim: el SW nuevo toma el
// control en el próximo load sin pedirle nada al usuario.
registerType: 'autoUpdate',
// El registro se hace desde PwaProvider para poder avisar cuando la app
// ya está lista para operar sin conexión.
injectRegister: null,
// Los iconos ya entran por `workbox.globPatterns`; con
// `includeManifestIcons` se listarían dos veces en el precache.
includeManifestIcons: false,
manifest: {
name: 'Gruperly',
short_name: 'Gruperly',
description: 'Gestión de cobros grupales',
lang: 'es',
dir: 'ltr',
start_url: '/',
scope: '/',
display: 'standalone',
orientation: 'portrait',
theme_color: '#ffffff',
background_color: '#ffffff',
categories: ['finance', 'productivity'],
icons: [
{ src: 'pwa-192x192.png', sizes: '192x192', type: 'image/png' },
{ src: 'pwa-512x512.png', sizes: '512x512', type: 'image/png' },
{
src: 'pwa-maskable-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable',
},
],
shortcuts: [
{ name: 'Mis grupos', url: '/groups' },
{ name: 'Cobros', url: '/payments' },
],
},
workbox: {
// El woff2 de Inter se importa desde node_modules: Vite lo emite a
// assets/ con hash y entra al precache para que la app abra offline.
globPatterns: ['**/*.{js,css,html,svg,png,ico,woff2}'],
// Solo el script del SW queda fuera: precachearlo cachearía la versión
// vieja. El runtime `workbox-<hash>.js` sí se precachea a propósito, así
// el SW puede arrancar sin red. No usar `**/workbox-*.js`: ese patrón
// también matchea `workbox-window.*.js`, que es el módulo cliente que
// importa `virtual:pwa-register` y sin él falla el registro.
globIgnores: ['**/sw.js'],
// App shell para toda navegación, incluidas las rutas profundas
// /join/$token y /report-absence/$token.
navigateFallback: '/index.html',
navigateFallbackDenylist: [/^\/api\//],
cleanupOutdatedCaches: true,
runtimeCaching: [
{
// La API nunca se cachea: son datos de cobros y una respuesta
// vieja sería peor que un error. Offline carga el shell, no los datos.
urlPattern: ({ url, request }) => request.method !== 'GET' || url.pathname.startsWith('/api/'),
handler: 'NetworkOnly',
},
],
},
devOptions: { enabled: true, type: 'module' },
}),
],
server: {
port: 6173,
},
})
})