static_manifest.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. ThemeColor string `json:"theme_color"`
  37. BackgroundColor string `json:"background_color"`
  38. }
  39. displayMode := "standalone"
  40. if request.IsAuthenticated(r) {
  41. user, err := h.store.UserByID(request.UserID(r))
  42. if err != nil {
  43. json.ServerError(w, r, err)
  44. return
  45. }
  46. displayMode = user.DisplayMode
  47. }
  48. themeColor := model.ThemeColor(request.UserTheme(r), "light")
  49. manifest := &webManifest{
  50. Name: "Miniflux",
  51. ShortName: "Miniflux",
  52. Description: "Minimalist Feed Reader",
  53. Display: displayMode,
  54. StartURL: route.Path(h.router, "login"),
  55. ThemeColor: themeColor,
  56. BackgroundColor: themeColor,
  57. Icons: []webManifestIcon{
  58. {Source: route.Path(h.router, "appIcon", "filename", "icon-120.png"), Sizes: "120x120", Type: "image/png", Purpose: "any"},
  59. {Source: route.Path(h.router, "appIcon", "filename", "icon-192.png"), Sizes: "192x192", Type: "image/png", Purpose: "any"},
  60. {Source: route.Path(h.router, "appIcon", "filename", "icon-512.png"), Sizes: "512x512", Type: "image/png", Purpose: "any"},
  61. {Source: route.Path(h.router, "appIcon", "filename", "maskable-icon-120.png"), Sizes: "120x120", Type: "image/png", Purpose: "maskable"},
  62. {Source: route.Path(h.router, "appIcon", "filename", "maskable-icon-192.png"), Sizes: "192x192", Type: "image/png", Purpose: "maskable"},
  63. {Source: route.Path(h.router, "appIcon", "filename", "maskable-icon-512.png"), Sizes: "512x512", Type: "image/png", Purpose: "maskable"},
  64. },
  65. ShareTarget: webManifestShareTarget{
  66. Action: route.Path(h.router, "bookmarklet"),
  67. Method: http.MethodGet,
  68. Enctype: "application/x-www-form-urlencoded",
  69. Params: webManifestShareTargetParams{URL: "uri", Text: "text"},
  70. },
  71. }
  72. json.OK(w, r, manifest)
  73. }