Load themes using the utilities

This commit is contained in:
Minecon724 2025-06-03 13:50:53 +02:00
commit 94ceaf505f
Signed by untrusted user who does not match committer: m724
GPG key ID: A02E6E67AB961189
2 changed files with 16 additions and 7 deletions

View file

@ -16,6 +16,7 @@ import (
_ "net/http/pprof" // Used for debugging if enabled and a web server is running _ "net/http/pprof" // Used for debugging if enabled and a web server is running
"forgejo.org/models/theme"
"forgejo.org/modules/container" "forgejo.org/modules/container"
"forgejo.org/modules/graceful" "forgejo.org/modules/graceful"
"forgejo.org/modules/log" "forgejo.org/modules/log"
@ -217,6 +218,13 @@ func serveInstalled(_ context.Context, ctx *cli.Command) error {
} }
} }
// Load themes
themes, tlerr := theme.GetThemeIds()
if (tlerr != nil) {
log.Error("Failed to load themes: ", tlerr)
}
setting.UI.Themes = themes
// Set up Chi routes // Set up Chi routes
webRoutes := routers.NormalRoutes() webRoutes := routers.NormalRoutes()
err := listen(webRoutes, true) err := listen(webRoutes, true)

View file

@ -19,6 +19,7 @@ import (
"forgejo.org/models/db" "forgejo.org/models/db"
"forgejo.org/models/organization" "forgejo.org/models/organization"
repo_model "forgejo.org/models/repo" repo_model "forgejo.org/models/repo"
"forgejo.org/models/theme"
user_model "forgejo.org/models/user" user_model "forgejo.org/models/user"
"forgejo.org/modules/base" "forgejo.org/modules/base"
"forgejo.org/modules/log" "forgejo.org/modules/log"
@ -335,15 +336,15 @@ func Repos(ctx *context.Context) {
func Appearance(ctx *context.Context) { func Appearance(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings.appearance") ctx.Data["Title"] = ctx.Tr("settings.appearance")
ctx.Data["PageIsSettingsAppearance"] = true ctx.Data["PageIsSettingsAppearance"] = true
ctx.Data["AllThemes"] = setting.UI.Themes
ctx.Data["ThemeName"] = func(themeName string) string { themes, err := theme.GetThemes()
fullThemeName := "themes.names." + themeName if err != nil {
if ctx.Locale.HasKey(fullThemeName) { ctx.ServerError("Failed to load themes", err)
return ctx.Locale.TrString(fullThemeName) return
}
return themeName
} }
ctx.Data["AllThemes"] = themes
var hiddenCommentTypes *big.Int var hiddenCommentTypes *big.Int
val, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes) val, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes)
if err != nil { if err != nil {