static_manifest.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. themeColor := model.ThemeColor(request.UserTheme(r))
  40. manifest := &webManifest{
  41. Name: "Miniflux",
  42. ShortName: "Miniflux",
  43. Description: "Minimalist Feed Reader",
  44. Display: "minimal-ui",
  45. StartURL: route.Path(h.router, "unread"),
  46. ThemeColor: themeColor,
  47. BackgroundColor: themeColor,
  48. Icons: []webManifestIcon{
  49. {Source: route.Path(h.router, "appIcon", "filename", "icon-120.png"), Sizes: "120x120", Type: "image/png"},
  50. {Source: route.Path(h.router, "appIcon", "filename", "icon-192.png"), Sizes: "192x192", Type: "image/png"},
  51. {Source: route.Path(h.router, "appIcon", "filename", "icon-512.png"), Sizes: "512x512", Type: "image/png"},
  52. },
  53. ShareTarget: webManifestShareTarget{
  54. Action: route.Path(h.router, "bookmarklet"),
  55. Method: http.MethodGet,
  56. Enctype: "application/x-www-form-urlencoded",
  57. Params: webManifestShareTargetParams{URL: "uri", Text: "text"},
  58. },
  59. }
  60. json.OK(w, r, manifest)
  61. }