aboutsummaryrefslogtreecommitdiffhomepage
path: root/ui
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-07-18 22:30:05 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-07-18 22:30:05 -0700
commita291d8a38b40569fdd1f00125ca0b29e4b9264f2 (patch)
tree13345ce7b413d9919521de258e60954467afcda0 /ui
parentc1ab27172c0d82f9289aeb3402056f727bc473fd (diff)
Improve themes handling
- Store user theme in session - Logged out users will keep their theme - Add theme background color to web manifest and meta tag
Diffstat (limited to 'ui')
-rw-r--r--ui/login_check.go5
-rw-r--r--ui/logout.go1
-rw-r--r--ui/oauth2_callback.go1
-rw-r--r--ui/session/session.go7
-rw-r--r--ui/settings_update.go1
-rw-r--r--ui/static_manifest.go31
-rw-r--r--ui/view/view.go1
7 files changed, 33 insertions, 14 deletions
diff --git a/ui/login_check.go b/ui/login_check.go
index 71e7854..36fafea 100644
--- a/ui/login_check.go
+++ b/ui/login_check.go
@@ -47,13 +47,14 @@ func (c *Controller) CheckLogin(w http.ResponseWriter, r *http.Request) {
logger.Info("[Controller:CheckLogin] username=%s just logged in", authForm.Username)
c.store.SetLastLogin(userID)
- userLanguage, err := c.store.UserLanguage(userID)
+ user, err := c.store.UserByID(userID)
if err != nil {
html.ServerError(w, err)
return
}
- sess.SetLanguage(userLanguage)
+ sess.SetLanguage(user.Language)
+ sess.SetTheme(user.Theme)
http.SetCookie(w, cookie.New(
cookie.CookieUserSessionID,
diff --git a/ui/logout.go b/ui/logout.go
index 2946d1a..0c777ce 100644
--- a/ui/logout.go
+++ b/ui/logout.go
@@ -28,6 +28,7 @@ func (c *Controller) Logout(w http.ResponseWriter, r *http.Request) {
}
sess.SetLanguage(user.Language)
+ sess.SetTheme(user.Theme)
if err := c.store.RemoveUserSessionByToken(user.ID, ctx.UserSessionToken()); err != nil {
logger.Error("[Controller:Logout] %v", err)
diff --git a/ui/oauth2_callback.go b/ui/oauth2_callback.go
index 23e379b..a39c0ac 100644
--- a/ui/oauth2_callback.go
+++ b/ui/oauth2_callback.go
@@ -114,6 +114,7 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
logger.Info("[Controller:OAuth2Callback] username=%s just logged in", user.Username)
c.store.SetLastLogin(user.ID)
sess.SetLanguage(user.Language)
+ sess.SetTheme(user.Theme)
http.SetCookie(w, cookie.New(
cookie.CookieUserSessionID,
diff --git a/ui/session/session.go b/ui/session/session.go
index 3d630a8..474bd18 100644
--- a/ui/session/session.go
+++ b/ui/session/session.go
@@ -51,11 +51,16 @@ func (s *Session) FlashErrorMessage() string {
return message
}
-// SetLanguage updates language field in session.
+// SetLanguage updates the language field in session.
func (s *Session) SetLanguage(language string) {
s.store.UpdateSessionField(s.ctx.SessionID(), "language", language)
}
+// SetTheme updates the theme field in session.
+func (s *Session) SetTheme(theme string) {
+ s.store.UpdateSessionField(s.ctx.SessionID(), "theme", theme)
+}
+
// SetPocketRequestToken updates Pocket Request Token.
func (s *Session) SetPocketRequestToken(requestToken string) {
s.store.UpdateSessionField(s.ctx.SessionID(), "pocket_request_token", requestToken)
diff --git a/ui/settings_update.go b/ui/settings_update.go
index f78b290..229042d 100644
--- a/ui/settings_update.go
+++ b/ui/settings_update.go
@@ -68,6 +68,7 @@ func (c *Controller) UpdateSettings(w http.ResponseWriter, r *http.Request) {
}
sess.SetLanguage(user.Language)
+ sess.SetTheme(user.Theme)
sess.NewFlashMessage(c.translator.GetLanguage(ctx.UserLanguage()).Get("Preferences saved!"))
response.Redirect(w, r, route.Path(c.router, "settings"))
}
diff --git a/ui/static_manifest.go b/ui/static_manifest.go
index 47de9f3..27abaec 100644
--- a/ui/static_manifest.go
+++ b/ui/static_manifest.go
@@ -7,8 +7,10 @@ package ui
import (
"net/http"
+ "github.com/miniflux/miniflux/http/context"
"github.com/miniflux/miniflux/http/response/json"
"github.com/miniflux/miniflux/http/route"
+ "github.com/miniflux/miniflux/model"
)
// WebManifest renders web manifest file.
@@ -20,20 +22,27 @@ func (c *Controller) WebManifest(w http.ResponseWriter, r *http.Request) {
}
type webManifest struct {
- Name string `json:"name"`
- Description string `json:"description"`
- ShortName string `json:"short_name"`
- StartURL string `json:"start_url"`
- Icons []webManifestIcon `json:"icons"`
- Display string `json:"display"`
+ Name string `json:"name"`
+ Description string `json:"description"`
+ ShortName string `json:"short_name"`
+ StartURL string `json:"start_url"`
+ Icons []webManifestIcon `json:"icons"`
+ Display string `json:"display"`
+ ThemeColor string `json:"theme_color"`
+ BackgroundColor string `json:"background_color"`
}
+ ctx := context.New(r)
+ themeColor := model.ThemeColor(ctx.UserTheme())
+
manifest := &webManifest{
- Name: "Miniflux",
- ShortName: "Miniflux",
- Description: "Minimalist Feed Reader",
- Display: "minimal-ui",
- StartURL: route.Path(c.router, "unread"),
+ Name: "Miniflux",
+ ShortName: "Miniflux",
+ Description: "Minimalist Feed Reader",
+ Display: "minimal-ui",
+ StartURL: route.Path(c.router, "unread"),
+ ThemeColor: themeColor,
+ BackgroundColor: themeColor,
Icons: []webManifestIcon{
webManifestIcon{Source: route.Path(c.router, "appIcon", "filename", "icon-120.png"), Sizes: "120x120", Type: "image/png"},
webManifestIcon{Source: route.Path(c.router, "appIcon", "filename", "icon-192.png"), Sizes: "192x192", Type: "image/png"},
diff --git a/ui/view/view.go b/ui/view/view.go
index a1c6646..0854222 100644
--- a/ui/view/view.go
+++ b/ui/view/view.go
@@ -35,5 +35,6 @@ func New(tpl *template.Engine, ctx *context.Context, sess *session.Session) *Vie
b.params["csrf"] = ctx.CSRF()
b.params["flashMessage"] = sess.FlashMessage()
b.params["flashErrorMessage"] = sess.FlashErrorMessage()
+ b.params["theme"] = ctx.UserTheme()
return b
}