diff --git a/internal/glance/config.go b/internal/glance/config.go index 0d424a2e..e1bc0e86 100644 --- a/internal/glance/config.go +++ b/internal/glance/config.go @@ -47,6 +47,7 @@ type config struct { LogoText string `yaml:"logo-text"` LogoURL string `yaml:"logo-url"` FaviconURL string `yaml:"favicon-url"` + PwaText string `yaml:"pwa-text"` } `yaml:"branding"` Pages []page `yaml:"pages"` diff --git a/internal/glance/glance.go b/internal/glance/glance.go index 8fb3e405..03e65314 100644 --- a/internal/glance/glance.go +++ b/internal/glance/glance.go @@ -3,6 +3,7 @@ package glance import ( "bytes" "context" + "encoding/json" "fmt" "html/template" "log" @@ -228,6 +229,7 @@ func (a *application) server() (func() error, func() error) { w.WriteHeader(http.StatusOK) }) + mux.HandleFunc(fmt.Sprintf("GET /static/%s/manifest.json", staticFSHash), a.handleManifestRequest) mux.Handle( fmt.Sprintf("GET /static/%s/{path...}", staticFSHash), http.StripPrefix("/static/"+staticFSHash, fileServerWithCache(http.FS(staticFS), 24*time.Hour)), @@ -267,3 +269,36 @@ func (a *application) server() (func() error, func() error) { return start, stop } + +func (a *application) handleManifestRequest(w http.ResponseWriter, r *http.Request) { + manifest := map[string]interface{}{ + "name": func() string { + if a.Config.Branding.PwaText != "" { + return a.Config.Branding.PwaText + } + return "Glance" + }(), + "short_name": a.Config.Branding.PwaText, + "display": "standalone", + "background_color": "#151519", + "scope": "/", + "start_url": "/", + "icons": []map[string]string{ + { + "src": func() string { + if a.Config.Branding.FaviconURL != "" { + return a.transformUserDefinedAssetPath(a.Config.Branding.FaviconURL) + } + return a.AssetPath("app-icon.png") + }(), + "type": "image/png", + "sizes": "512x512", + "purpose": "any maskable", + }, + }, + } + + w.Header().Set("Content-Type", "application/json") + w.Header().Set("Cache-Control", "public, max-age=3600") + json.NewEncoder(w).Encode(manifest) +} diff --git a/internal/glance/templates/document.html b/internal/glance/templates/document.html index a26f8549..2ab70582 100644 --- a/internal/glance/templates/document.html +++ b/internal/glance/templates/document.html @@ -10,9 +10,9 @@ - + - +