Load themes using the utilities

This commit is contained in:
Minecon724 2025-06-03 13:50:53 +02:00
commit 30c94deeaa
Signed by: Minecon724
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
"forgejo.org/models/theme"
"forgejo.org/modules/container"
"forgejo.org/modules/graceful"
"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
webRoutes := routers.NormalRoutes()
err := listen(webRoutes, true)

View file

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