Documentation
¶
Overview ¶
Package pwa hosts Progressive Web App glue — the dynamic web app manifest plus future hooks (service worker registration, push subscription endpoints). Kept separate from internal/pkg/api so server.go stays a wiring file and doesn't accumulate PWA logic.
Index ¶
- func DisabledServiceWorkerHandler(w http.ResponseWriter, r *http.Request)
- func EnsurePushConfig(ctx context.Context, cfg pushConfigStore) error
- func ManifestHandler(w http.ResponseWriter, r *http.Request)
- func ServiceWorkerHandler(w http.ResponseWriter, r *http.Request)
- type BrowserSubscription
- type PushDevice
- type PushHandler
- type PushService
- func (s *PushService) Devices(ctx context.Context, userID string) ([]PushDevice, error)
- func (s *PushService) PublicKey() string
- func (s *PushService) SendTest(ctx context.Context, userID, endpoint string) (int, error)
- func (s *PushService) SendToUser(ctx context.Context, userID, title, body, url string) (int, error)
- func (s *PushService) Subscribe(ctx context.Context, userID, userAgent string, req BrowserSubscription) error
- func (s *PushService) Unsubscribe(ctx context.Context, userID, endpoint string) error
- func (s *PushService) UserPushID(userID string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisabledServiceWorkerHandler ¶ added in v0.34.0
func DisabledServiceWorkerHandler(w http.ResponseWriter, r *http.Request)
DisabledServiceWorkerHandler serves /sw.js as a 404 (WICK_SW_ENABLED=false). The service worker's own caching (stale-while-revalidate on static assets, cache-fallback on navigations) can pin a stale build across a dev rebuild, so this lets a dev server run with no SW at all. A 404 here — rather than just not registering — makes the browser drop any worker it already registered for this origin on the next page load, so switching the flag off actually clears prior state instead of leaving an old worker running alongside the new "disabled" server.
func EnsurePushConfig ¶ added in v0.15.0
EnsurePushConfig seeds PWA Web Push config rows and creates one VAPID keypair on first boot. Public/private keys must be generated together, so this lives outside the generic per-key config generator.
func ManifestHandler ¶
func ManifestHandler(w http.ResponseWriter, r *http.Request)
ManifestHandler serves /public/manifest.json with the configured app name + description baked in, so downstream wick deployments install as their own brand instead of "wick". The agents shortcut name follows suit — "MyApp Agent" rather than a static fallback. Icons and theme colour stay shared from the embedded SVGs under /public/img.
Reads everything from the request context. The caller is expected to chain the existing appNameHandler middleware before this handler so ui.AppNameFromContext / ui.AppDescFromContext are populated.
func ServiceWorkerHandler ¶ added in v0.14.19
func ServiceWorkerHandler(w http.ResponseWriter, r *http.Request)
ServiceWorkerHandler serves /sw.js. It must be registered at the root path (not under /public/) so the default scope is "/". no-cache lets the browser pick up a new worker on each deploy.
Types ¶
type BrowserSubscription ¶ added in v0.15.0
type PushDevice ¶ added in v0.15.0
type PushHandler ¶ added in v0.15.0
type PushHandler struct {
// contains filtered or unexported fields
}
func NewPushHandler ¶ added in v0.15.0
func NewPushHandler(svc *PushService, auth *login.Service) *PushHandler
func (*PushHandler) Register ¶ added in v0.15.0
func (h *PushHandler) Register(mux *http.ServeMux, midd *login.Middleware)
type PushService ¶ added in v0.15.0
type PushService struct {
// contains filtered or unexported fields
}
func NewPushService ¶ added in v0.15.0
func NewPushService(db *gorm.DB, cfg pushConfigStore) *PushService
func (*PushService) Devices ¶ added in v0.15.0
func (s *PushService) Devices(ctx context.Context, userID string) ([]PushDevice, error)
func (*PushService) PublicKey ¶ added in v0.15.0
func (s *PushService) PublicKey() string
func (*PushService) SendToUser ¶ added in v0.15.0
func (*PushService) Subscribe ¶ added in v0.15.0
func (s *PushService) Subscribe(ctx context.Context, userID, userAgent string, req BrowserSubscription) error
func (*PushService) Unsubscribe ¶ added in v0.15.0
func (s *PushService) Unsubscribe(ctx context.Context, userID, endpoint string) error
func (*PushService) UserPushID ¶ added in v0.15.0
func (s *PushService) UserPushID(userID string) string