2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-04-30 01:35:04 +02:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package ui // import "miniflux.app/v2/internal/ui"
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/http/request"
|
|
|
|
"miniflux.app/v2/internal/http/response/json"
|
|
|
|
"miniflux.app/v2/internal/http/route"
|
|
|
|
"miniflux.app/v2/internal/model"
|
2018-04-30 01:35:04 +02:00
|
|
|
)
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
func (h *handler) showWebManifest(w http.ResponseWriter, r *http.Request) {
|
2021-01-01 14:15:33 +01:00
|
|
|
type webManifestShareTargetParams struct {
|
|
|
|
URL string `json:"url"`
|
|
|
|
Text string `json:"text"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type webManifestShareTarget struct {
|
|
|
|
Action string `json:"action"`
|
|
|
|
Method string `json:"method"`
|
|
|
|
Enctype string `json:"enctype"`
|
|
|
|
Params webManifestShareTargetParams `json:"params"`
|
|
|
|
}
|
|
|
|
|
2018-04-30 01:35:04 +02:00
|
|
|
type webManifestIcon struct {
|
2023-05-07 11:40:16 +02:00
|
|
|
Source string `json:"src"`
|
|
|
|
Sizes string `json:"sizes"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Purpose string `json:"purpose"`
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type webManifest struct {
|
2021-01-01 14:15:33 +01:00
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
ShortName string `json:"short_name"`
|
|
|
|
StartURL string `json:"start_url"`
|
|
|
|
Icons []webManifestIcon `json:"icons"`
|
|
|
|
ShareTarget webManifestShareTarget `json:"share_target"`
|
|
|
|
Display string `json:"display"`
|
|
|
|
BackgroundColor string `json:"background_color"`
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 22:29:51 +01:00
|
|
|
displayMode := "standalone"
|
|
|
|
if request.IsAuthenticated(r) {
|
|
|
|
user, err := h.store.UserByID(request.UserID(r))
|
|
|
|
if err != nil {
|
|
|
|
json.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
displayMode = user.DisplayMode
|
|
|
|
}
|
2021-11-28 16:20:51 +01:00
|
|
|
themeColor := model.ThemeColor(request.UserTheme(r), "light")
|
2018-04-30 01:35:04 +02:00
|
|
|
manifest := &webManifest{
|
2018-07-19 07:30:05 +02:00
|
|
|
Name: "Miniflux",
|
|
|
|
ShortName: "Miniflux",
|
|
|
|
Description: "Minimalist Feed Reader",
|
2021-02-28 22:29:51 +01:00
|
|
|
Display: displayMode,
|
2022-11-09 15:38:11 +01:00
|
|
|
StartURL: route.Path(h.router, "login"),
|
2018-07-19 07:30:05 +02:00
|
|
|
BackgroundColor: themeColor,
|
2018-04-30 01:35:04 +02:00
|
|
|
Icons: []webManifestIcon{
|
2023-05-07 11:40:16 +02:00
|
|
|
{Source: route.Path(h.router, "appIcon", "filename", "icon-120.png"), Sizes: "120x120", Type: "image/png", Purpose: "any"},
|
|
|
|
{Source: route.Path(h.router, "appIcon", "filename", "icon-192.png"), Sizes: "192x192", Type: "image/png", Purpose: "any"},
|
|
|
|
{Source: route.Path(h.router, "appIcon", "filename", "icon-512.png"), Sizes: "512x512", Type: "image/png", Purpose: "any"},
|
|
|
|
{Source: route.Path(h.router, "appIcon", "filename", "maskable-icon-120.png"), Sizes: "120x120", Type: "image/png", Purpose: "maskable"},
|
|
|
|
{Source: route.Path(h.router, "appIcon", "filename", "maskable-icon-192.png"), Sizes: "192x192", Type: "image/png", Purpose: "maskable"},
|
|
|
|
{Source: route.Path(h.router, "appIcon", "filename", "maskable-icon-512.png"), Sizes: "512x512", Type: "image/png", Purpose: "maskable"},
|
2018-04-30 01:35:04 +02:00
|
|
|
},
|
2021-01-01 14:15:33 +01:00
|
|
|
ShareTarget: webManifestShareTarget{
|
|
|
|
Action: route.Path(h.router, "bookmarklet"),
|
|
|
|
Method: http.MethodGet,
|
|
|
|
Enctype: "application/x-www-form-urlencoded",
|
|
|
|
Params: webManifestShareTargetParams{URL: "uri", Text: "text"},
|
|
|
|
},
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
|
2018-07-20 04:27:05 +02:00
|
|
|
json.OK(w, r, manifest)
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|