static_manifest.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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/locale"
  10. "miniflux.app/v2/internal/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,omitempty"`
  26. Type string `json:"type,omitempty"`
  27. Purpose string `json:"purpose,omitempty"`
  28. }
  29. type webManifestShortcut struct {
  30. Name string `json:"name"`
  31. URL string `json:"url"`
  32. Icons []webManifestIcon `json:"icons,omitempty"`
  33. }
  34. type webManifest struct {
  35. Name string `json:"name"`
  36. Description string `json:"description"`
  37. ShortName string `json:"short_name"`
  38. StartURL string `json:"start_url"`
  39. Icons []webManifestIcon `json:"icons"`
  40. ShareTarget webManifestShareTarget `json:"share_target"`
  41. Display string `json:"display"`
  42. BackgroundColor string `json:"background_color"`
  43. Shortcuts []webManifestShortcut `json:"shortcuts"`
  44. }
  45. displayMode := "standalone"
  46. labelNewFeed := "Add Feed"
  47. labelUnreadMenu := "Unread"
  48. labelStarredMenu := "Starred"
  49. labelHistoryMenu := "History"
  50. labelFeedsMenu := "Feeds"
  51. labelCategoriesMenu := "Categories"
  52. labelSearchMenu := "Search"
  53. labelSettingsMenu := "Settings"
  54. if request.IsAuthenticated(r) {
  55. user, err := h.store.UserByID(request.UserID(r))
  56. if err != nil {
  57. json.ServerError(w, r, err)
  58. return
  59. }
  60. displayMode = user.DisplayMode
  61. printer := locale.NewPrinter(user.Language)
  62. labelNewFeed = printer.Print("menu.add_feed")
  63. labelUnreadMenu = printer.Print("menu.unread")
  64. labelStarredMenu = printer.Print("menu.starred")
  65. labelHistoryMenu = printer.Print("menu.history")
  66. labelFeedsMenu = printer.Print("menu.feeds")
  67. labelCategoriesMenu = printer.Print("menu.categories")
  68. labelSearchMenu = printer.Print("menu.search")
  69. labelSettingsMenu = printer.Print("menu.settings")
  70. }
  71. themeColor := model.ThemeColor(request.UserTheme(r), "light")
  72. manifest := &webManifest{
  73. Name: "Miniflux",
  74. ShortName: "Miniflux",
  75. Description: "Minimalist Feed Reader",
  76. Display: displayMode,
  77. StartURL: route.Path(h.router, "login"),
  78. BackgroundColor: themeColor,
  79. Icons: []webManifestIcon{
  80. {Source: route.Path(h.router, "appIcon", "filename", "icon-120.png"), Sizes: "120x120", Type: "image/png", Purpose: "any"},
  81. {Source: route.Path(h.router, "appIcon", "filename", "icon-192.png"), Sizes: "192x192", Type: "image/png", Purpose: "any"},
  82. {Source: route.Path(h.router, "appIcon", "filename", "icon-512.png"), Sizes: "512x512", Type: "image/png", Purpose: "any"},
  83. {Source: route.Path(h.router, "appIcon", "filename", "maskable-icon-120.png"), Sizes: "120x120", Type: "image/png", Purpose: "maskable"},
  84. {Source: route.Path(h.router, "appIcon", "filename", "maskable-icon-192.png"), Sizes: "192x192", Type: "image/png", Purpose: "maskable"},
  85. {Source: route.Path(h.router, "appIcon", "filename", "maskable-icon-512.png"), Sizes: "512x512", Type: "image/png", Purpose: "maskable"},
  86. },
  87. ShareTarget: webManifestShareTarget{
  88. Action: route.Path(h.router, "bookmarklet"),
  89. Method: http.MethodGet,
  90. Enctype: "application/x-www-form-urlencoded",
  91. Params: webManifestShareTargetParams{URL: "uri", Text: "text"},
  92. },
  93. Shortcuts: []webManifestShortcut{
  94. {Name: labelNewFeed, URL: route.Path(h.router, "addSubscription"), Icons: []webManifestIcon{{Source: route.Path(h.router, "appIcon", "filename", "add-feed-icon.png"), Sizes: "240x240", Type: "image/png"}}},
  95. {Name: labelUnreadMenu, URL: route.Path(h.router, "unread"), Icons: []webManifestIcon{{Source: route.Path(h.router, "appIcon", "filename", "unread-icon.png"), Sizes: "240x240", Type: "image/png"}}},
  96. {Name: labelStarredMenu, URL: route.Path(h.router, "starred"), Icons: []webManifestIcon{{Source: route.Path(h.router, "appIcon", "filename", "starred-icon.png"), Sizes: "240x240", Type: "image/png"}}},
  97. {Name: labelHistoryMenu, URL: route.Path(h.router, "history"), Icons: []webManifestIcon{{Source: route.Path(h.router, "appIcon", "filename", "history-icon.png"), Sizes: "240x240", Type: "image/png"}}},
  98. {Name: labelFeedsMenu, URL: route.Path(h.router, "feeds"), Icons: []webManifestIcon{{Source: route.Path(h.router, "appIcon", "filename", "feeds-icon.png"), Sizes: "240x240", Type: "image/png"}}},
  99. {Name: labelCategoriesMenu, URL: route.Path(h.router, "categories"), Icons: []webManifestIcon{{Source: route.Path(h.router, "appIcon", "filename", "categories-icon.png"), Sizes: "240x240", Type: "image/png"}}},
  100. {Name: labelSearchMenu, URL: route.Path(h.router, "search"), Icons: []webManifestIcon{{Source: route.Path(h.router, "appIcon", "filename", "search-icon.png"), Sizes: "240x240", Type: "image/png"}}},
  101. {Name: labelSettingsMenu, URL: route.Path(h.router, "settings"), Icons: []webManifestIcon{{Source: route.Path(h.router, "appIcon", "filename", "settings-icon.png"), Sizes: "240x240", Type: "image/png"}}},
  102. },
  103. }
  104. json.OK(w, r, manifest)
  105. }