static_manifest.go 5.1 KB

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