1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

Make web app display mode configurable

The change is visible after reinstalling the web app. 

It's not compatible with all browsers.

See https://developer.mozilla.org/en-US/docs/Web/Manifest/display
This commit is contained in:
1pav 2021-02-28 22:29:51 +01:00 committed by GitHub
parent 053b1d0f8d
commit 0d935a863f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 182 additions and 12 deletions

View file

@ -26,6 +26,7 @@ type SettingsForm struct {
ShowReadingTime bool
CustomCSS string
EntrySwipe bool
DisplayMode string
}
// Merge updates the fields of the given user.
@ -40,6 +41,7 @@ func (s *SettingsForm) Merge(user *model.User) *model.User {
user.ShowReadingTime = s.ShowReadingTime
user.Stylesheet = s.CustomCSS
user.EntrySwipe = s.EntrySwipe
user.DisplayMode = s.DisplayMode
if s.Password != "" {
user.Password = s.Password
@ -50,7 +52,7 @@ func (s *SettingsForm) Merge(user *model.User) *model.User {
// Validate makes sure the form values are valid.
func (s *SettingsForm) Validate() error {
if s.Username == "" || s.Theme == "" || s.Language == "" || s.Timezone == "" || s.EntryDirection == "" {
if s.Username == "" || s.Theme == "" || s.Language == "" || s.Timezone == "" || s.EntryDirection == "" || s.DisplayMode == "" {
return errors.NewLocalizedError("error.settings_mandatory_fields")
}
@ -87,5 +89,6 @@ func NewSettingsForm(r *http.Request) *SettingsForm {
ShowReadingTime: r.FormValue("show_reading_time") == "1",
CustomCSS: r.FormValue("custom_css"),
EntrySwipe: r.FormValue("entry_swipe") == "1",
DisplayMode: r.FormValue("display_mode"),
}
}

View file

@ -14,6 +14,7 @@ func TestValid(t *testing.T) {
Timezone: "UTC",
EntryDirection: "asc",
EntriesPerPage: 50,
DisplayMode: "standalone",
}
err := settings.Validate()
@ -32,6 +33,7 @@ func TestConfirmationEmpty(t *testing.T) {
Timezone: "UTC",
EntryDirection: "asc",
EntriesPerPage: 50,
DisplayMode: "standalone",
}
err := settings.Validate()
@ -54,6 +56,7 @@ func TestConfirmationIncorrect(t *testing.T) {
Timezone: "UTC",
EntryDirection: "asc",
EntriesPerPage: 50,
DisplayMode: "standalone",
}
err := settings.Validate()

View file

@ -37,6 +37,7 @@ func (h *handler) showSettingsPage(w http.ResponseWriter, r *http.Request) {
ShowReadingTime: user.ShowReadingTime,
CustomCSS: user.Stylesheet,
EntrySwipe: user.EntrySwipe,
DisplayMode: user.DisplayMode,
}
timezones, err := h.store.Timezones()

View file

@ -60,6 +60,7 @@ func (h *handler) updateSettings(w http.ResponseWriter, r *http.Request) {
Timezone: model.OptionalString(settingsForm.Timezone),
EntryDirection: model.OptionalString(settingsForm.EntryDirection),
EntriesPerPage: model.OptionalInt(settingsForm.EntriesPerPage),
DisplayMode: model.OptionalString(settingsForm.DisplayMode),
}
if validationErr := validator.ValidateUserModification(h.store, loggedUser.ID, userModificationRequest); validationErr != nil {

View file

@ -44,12 +44,21 @@ func (h *handler) showWebManifest(w http.ResponseWriter, r *http.Request) {
BackgroundColor string `json:"background_color"`
}
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
}
themeColor := model.ThemeColor(request.UserTheme(r))
manifest := &webManifest{
Name: "Miniflux",
ShortName: "Miniflux",
Description: "Minimalist Feed Reader",
Display: "standalone",
Display: displayMode,
StartURL: route.Path(h.router, "unread"),
ThemeColor: themeColor,
BackgroundColor: themeColor,