static_manifest.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui // import "miniflux.app/ui"
  5. import (
  6. "net/http"
  7. "miniflux.app/http/request"
  8. "miniflux.app/http/response/json"
  9. "miniflux.app/http/route"
  10. "miniflux.app/model"
  11. )
  12. func (h *handler) showWebManifest(w http.ResponseWriter, r *http.Request) {
  13. type webManifestShareTargetParams struct {
  14. URL string `json:"url"`
  15. Text string `json:"text"`
  16. }
  17. type webManifestShareTarget struct {
  18. Action string `json:"action"`
  19. Method string `json:"method"`
  20. Enctype string `json:"enctype"`
  21. Params webManifestShareTargetParams `json:"params"`
  22. }
  23. type webManifestIcon struct {
  24. Source string `json:"src"`
  25. Sizes string `json:"sizes"`
  26. Type string `json:"type"`
  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, "unread"),
  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"},
  59. {Source: route.Path(h.router, "appIcon", "filename", "icon-192.png"), Sizes: "192x192", Type: "image/png"},
  60. {Source: route.Path(h.router, "appIcon", "filename", "icon-512.png"), Sizes: "512x512", Type: "image/png"},
  61. },
  62. ShareTarget: webManifestShareTarget{
  63. Action: route.Path(h.router, "bookmarklet"),
  64. Method: http.MethodGet,
  65. Enctype: "application/x-www-form-urlencoded",
  66. Params: webManifestShareTargetParams{URL: "uri", Text: "text"},
  67. },
  68. }
  69. json.OK(w, r, manifest)
  70. }