static_manifest.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package ui // import "miniflux.app/v2/internal/ui"
  4. import (
  5. "net/http"
  6. "miniflux.app/v2/internal/http/request"
  7. "miniflux.app/v2/internal/http/response/json"
  8. "miniflux.app/v2/internal/http/route"
  9. "miniflux.app/v2/internal/model"
  10. )
  11. func (h *handler) showWebManifest(w http.ResponseWriter, r *http.Request) {
  12. type webManifestShareTargetParams struct {
  13. URL string `json:"url"`
  14. Text string `json:"text"`
  15. }
  16. type webManifestShareTarget struct {
  17. Action string `json:"action"`
  18. Method string `json:"method"`
  19. Enctype string `json:"enctype"`
  20. Params webManifestShareTargetParams `json:"params"`
  21. }
  22. type webManifestIcon struct {
  23. Source string `json:"src"`
  24. Sizes string `json:"sizes"`
  25. Type string `json:"type"`
  26. Purpose string `json:"purpose"`
  27. }
  28. type webManifest struct {
  29. Name string `json:"name"`
  30. Description string `json:"description"`
  31. ShortName string `json:"short_name"`
  32. StartURL string `json:"start_url"`
  33. Icons []webManifestIcon `json:"icons"`
  34. ShareTarget webManifestShareTarget `json:"share_target"`
  35. Display string `json:"display"`
  36. BackgroundColor string `json:"background_color"`
  37. }
  38. displayMode := "standalone"
  39. if request.IsAuthenticated(r) {
  40. user, err := h.store.UserByID(request.UserID(r))
  41. if err != nil {
  42. json.ServerError(w, r, err)
  43. return
  44. }
  45. displayMode = user.DisplayMode
  46. }
  47. themeColor := model.ThemeColor(request.UserTheme(r), "light")
  48. manifest := &webManifest{
  49. Name: "Miniflux",
  50. ShortName: "Miniflux",
  51. Description: "Minimalist Feed Reader",
  52. Display: displayMode,
  53. StartURL: route.Path(h.router, "login"),
  54. BackgroundColor: themeColor,
  55. Icons: []webManifestIcon{
  56. {Source: route.Path(h.router, "appIcon", "filename", "icon-120.png"), Sizes: "120x120", Type: "image/png", Purpose: "any"},
  57. {Source: route.Path(h.router, "appIcon", "filename", "icon-192.png"), Sizes: "192x192", Type: "image/png", Purpose: "any"},
  58. {Source: route.Path(h.router, "appIcon", "filename", "icon-512.png"), Sizes: "512x512", Type: "image/png", Purpose: "any"},
  59. {Source: route.Path(h.router, "appIcon", "filename", "maskable-icon-120.png"), Sizes: "120x120", Type: "image/png", Purpose: "maskable"},
  60. {Source: route.Path(h.router, "appIcon", "filename", "maskable-icon-192.png"), Sizes: "192x192", Type: "image/png", Purpose: "maskable"},
  61. {Source: route.Path(h.router, "appIcon", "filename", "maskable-icon-512.png"), Sizes: "512x512", Type: "image/png", Purpose: "maskable"},
  62. },
  63. ShareTarget: webManifestShareTarget{
  64. Action: route.Path(h.router, "bookmarklet"),
  65. Method: http.MethodGet,
  66. Enctype: "application/x-www-form-urlencoded",
  67. Params: webManifestShareTargetParams{URL: "uri", Text: "text"},
  68. },
  69. }
  70. json.OK(w, r, manifest)
  71. }