2018-04-29 19:35:04 -04:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-09-03 17:26:40 -04:00
|
|
|
package ui // import "miniflux.app/ui"
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-09-03 17:26:40 -04:00
|
|
|
"miniflux.app/http/request"
|
2018-08-25 00:51:50 -04:00
|
|
|
"miniflux.app/http/response/json"
|
|
|
|
"miniflux.app/http/route"
|
|
|
|
"miniflux.app/model"
|
2018-04-29 19:35:04 -04:00
|
|
|
)
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
func (h *handler) showWebManifest(w http.ResponseWriter, r *http.Request) {
|
2021-01-01 08:15:33 -05: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-29 19:35:04 -04:00
|
|
|
type webManifestIcon struct {
|
|
|
|
Source string `json:"src"`
|
|
|
|
Sizes string `json:"sizes"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type webManifest struct {
|
2021-01-01 08:15:33 -05: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"`
|
|
|
|
ThemeColor string `json:"theme_color"`
|
|
|
|
BackgroundColor string `json:"background_color"`
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|
|
|
|
|
2021-02-28 16:29:51 -05: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 10:20:51 -05:00
|
|
|
themeColor := model.ThemeColor(request.UserTheme(r), "light")
|
2018-04-29 19:35:04 -04:00
|
|
|
manifest := &webManifest{
|
2018-07-19 01:30:05 -04:00
|
|
|
Name: "Miniflux",
|
|
|
|
ShortName: "Miniflux",
|
|
|
|
Description: "Minimalist Feed Reader",
|
2021-02-28 16:29:51 -05:00
|
|
|
Display: displayMode,
|
2018-11-11 14:28:29 -05:00
|
|
|
StartURL: route.Path(h.router, "unread"),
|
2018-07-19 01:30:05 -04:00
|
|
|
ThemeColor: themeColor,
|
|
|
|
BackgroundColor: themeColor,
|
2018-04-29 19:35:04 -04:00
|
|
|
Icons: []webManifestIcon{
|
2021-01-04 00:20:21 -05:00
|
|
|
{Source: route.Path(h.router, "appIcon", "filename", "icon-120.png"), Sizes: "120x120", Type: "image/png"},
|
|
|
|
{Source: route.Path(h.router, "appIcon", "filename", "icon-192.png"), Sizes: "192x192", Type: "image/png"},
|
|
|
|
{Source: route.Path(h.router, "appIcon", "filename", "icon-512.png"), Sizes: "512x512", Type: "image/png"},
|
2018-04-29 19:35:04 -04:00
|
|
|
},
|
2021-01-01 08:15:33 -05: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-29 19:35:04 -04:00
|
|
|
}
|
|
|
|
|
2018-07-19 22:27:05 -04:00
|
|
|
json.OK(w, r, manifest)
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|