feat(pwa): app instalável com service worker e shell offline

- manifest.webmanifest: standalone, theme/background color, ícones 192/512
  any+maskable+monochrome (PNGs em web/icons) e atalho 'Nova nota' (?new=1)
- sw.js: cache versionado (notas-shell-v1); navegação network-first com
  fallback ao shell (offline), estáticos stale-while-revalidate, /api/* e
  SSE sempre passthrough; activate limpa caches e notifica janelas
- app.js: registro do SW, beforeinstallprompt com item 'Instalar Aplicativo…'
  no menu Ajuda (escondido em standalone/após instalar), toast de atualização,
  aviso offline/online, deep-link ?new=1
- index.html: meta tags theme-color/mobile-web-app/apple-touch-icon/manifest
- server: staticHandler com MIME application/manifest+json e
  Cache-Control no-cache para /sw.js; embed inclui manifest, sw e ícones
- README: seção PWA + orientação de serving (Go atual e equivalente Rust)
This commit is contained in:
lgcosta committed 2026-11-05 08:04:27 -03:00
1 parent 63fd024f68
commit 18d33ed141
12 files changed
+243 -3

No files matched your search

+20 -1
View File
@@ -78,11 +78,30 @@ func (s *Server) Handler() http.Handler {
mux.HandleFunc("POST /api/presence", s.auth(s.handlePresence))
mux.HandleFunc("GET /{$}", s.serveIndex)
mux.Handle("GET /", http.FileServerFS(s.webFS))
mux.Handle("GET /", s.staticHandler())
return s.wrap(mux)
}
// staticHandler serve o FS embutido com os cabeçalhos que PWA exige:
// sw.js nunca pode ser cacheado pelo browser (a detecção de nova versão é por
// bytes) e o manifest ganha o MIME application/manifest+json.
func (s *Server) staticHandler() http.Handler {
files := http.FileServerFS(s.webFS)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/sw.js":
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Content-Type", "text/javascript; charset=utf-8")
files.ServeHTTP(w, r)
return
case "/manifest.webmanifest":
w.Header().Set("Content-Type", "application/manifest+json; charset=utf-8")
}
files.ServeHTTP(w, r)
})
}
// wrap aplica middlewares globais: recuperação, headers de segurança e log.
func (s *Server) wrap(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {