diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-04-24 00:18:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-24 00:18:41 +0800 |
commit | b79e3db264e5734d8cc038be898d45186b3afcbd (patch) | |
tree | 792a169c1504bcda5d967ffc029b8cbd2f619e93 /routers | |
parent | dd2aaadce3ecd3134a1ba0c82c5aaa05d6c11b2b (diff) | |
download | gitea-b79e3db264e5734d8cc038be898d45186b3afcbd.tar.gz gitea-b79e3db264e5734d8cc038be898d45186b3afcbd.zip |
Initial support for colorblindness-friendly themes (#30625)
Initial support for #25680
This PR only adds some simple styles from GitHub, it is big enough and
it focuses on adding the necessary framework-level supports. More styles
could be fine-tuned later.
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/user/setting/profile.go | 11 | ||||
-rw-r--r-- | routers/web/web.go | 2 |
2 files changed, 11 insertions, 2 deletions
diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 49eb050dcb..e5ff8570cf 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -31,6 +31,7 @@ import ( "code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/forms" user_service "code.gitea.io/gitea/services/user" + "code.gitea.io/gitea/services/webtheme" ) const ( @@ -319,6 +320,13 @@ func Appearance(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("settings.appearance") ctx.Data["PageIsSettingsAppearance"] = true + allThemes := webtheme.GetAvailableThemes() + if webtheme.IsThemeAvailable(setting.UI.DefaultTheme) { + allThemes = util.SliceRemoveAll(allThemes, setting.UI.DefaultTheme) + allThemes = append([]string{setting.UI.DefaultTheme}, allThemes...) // move the default theme to the top + } + ctx.Data["AllThemes"] = allThemes + var hiddenCommentTypes *big.Int val, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes) if err != nil { @@ -341,11 +349,12 @@ func UpdateUIThemePost(ctx *context.Context) { ctx.Data["PageIsSettingsAppearance"] = true if ctx.HasError() { + ctx.Flash.Error(ctx.GetErrMsg()) ctx.Redirect(setting.AppSubURL + "/user/settings/appearance") return } - if !form.IsThemeExists() { + if !webtheme.IsThemeAvailable(form.Theme) { ctx.Flash.Error(ctx.Tr("settings.theme_update_error")) ctx.Redirect(setting.AppSubURL + "/user/settings/appearance") return diff --git a/routers/web/web.go b/routers/web/web.go index 994e639e20..c6132f0d61 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -652,7 +652,7 @@ func registerRoutes(m *web.Route) { m.Get("", user_setting.BlockedUsers) m.Post("", web.Bind(forms.BlockUserForm{}), user_setting.BlockedUsersPost) }) - }, reqSignIn, ctxDataSet("PageIsUserSettings", true, "AllThemes", setting.UI.Themes, "EnablePackages", setting.Packages.Enabled)) + }, reqSignIn, ctxDataSet("PageIsUserSettings", true, "EnablePackages", setting.Packages.Enabled)) m.Group("/user", func() { m.Get("/activate", auth.Activate) |