Skip to content

Commit 35204c5

Browse files
committed
Merge main into ini2ui
1 parent 4bd63b6 commit 35204c5

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

models/user/user.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"encoding/hex"
1010
"fmt"
11-
_ "image/jpeg" // Needed for jpeg support
1211
"mime"
1312
"net/mail"
1413
"net/url"
@@ -19,6 +18,8 @@ import (
1918
"time"
2019
"unicode"
2120

21+
_ "image/jpeg" // Needed for jpeg support
22+
2223
"code.gitea.io/gitea/models/auth"
2324
"code.gitea.io/gitea/models/db"
2425
"code.gitea.io/gitea/modules/auth/openid"

routers/web/user/setting/profile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func Repos(ctx *context.Context) {
338338
func Appearance(ctx *context.Context) {
339339
ctx.Data["Title"] = ctx.Tr("settings.appearance")
340340
ctx.Data["PageIsSettingsAppearance"] = true
341-
ctx.Data["AllThemes"] = webtheme.GetAvailableThemes()
341+
ctx.Data["AllThemes"] = webtheme.GetAvailableThemes(ctx)
342342
ctx.Data["UserDisabledFeatures"] = user_model.DisabledFeaturesWithLoginType(ctx.Doer)
343343

344344
var hiddenCommentTypes *big.Int
@@ -368,7 +368,7 @@ func UpdateUIThemePost(ctx *context.Context) {
368368
return
369369
}
370370

371-
if !webtheme.IsThemeAvailable(form.Theme) {
371+
if !webtheme.IsThemeAvailable(ctx, form.Theme) {
372372
ctx.Flash.Error(ctx.Tr("settings.theme_update_error"))
373373
ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")
374374
return

services/gitdiff/gitdiff.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ func getDiffLineSectionInfo(treePath, line string, lastLeftIdx, lastRightIdx int
192192
}
193193

194194
// escape a line's content or return <br> needed for copy/paste purposes
195-
func getLineContent(content string, locale translation.Locale) DiffInline {
195+
func getLineContent(ctx context.Context, content string, locale translation.Locale) DiffInline {
196196
if len(content) > 0 {
197-
return DiffInlineWithUnicodeEscape(template.HTML(html.EscapeString(content)), locale)
197+
return DiffInlineWithUnicodeEscape(ctx, template.HTML(html.EscapeString(content)), locale)
198198
}
199199
return DiffInline{EscapeStatus: &charset.EscapeStatus{}, Content: "<br>"}
200200
}
@@ -271,8 +271,8 @@ type DiffInline struct {
271271
}
272272

273273
// DiffInlineWithUnicodeEscape makes a DiffInline with hidden Unicode characters escaped
274-
func DiffInlineWithUnicodeEscape(s template.HTML, locale translation.Locale) DiffInline {
275-
status, content := charset.EscapeControlHTML(s, locale)
274+
func DiffInlineWithUnicodeEscape(ctx context.Context, s template.HTML, locale translation.Locale) DiffInline {
275+
status, content := charset.EscapeControlHTML(ctx, s, locale)
276276
return DiffInline{EscapeStatus: status, Content: content}
277277
}
278278

@@ -291,7 +291,7 @@ func (diffSection *DiffSection) getLineContentForRender(lineIdx int, diffLine *D
291291
return h
292292
}
293293

294-
func (diffSection *DiffSection) getDiffLineForRender(diffLineType DiffLineType, leftLine, rightLine *DiffLine, locale translation.Locale) DiffInline {
294+
func (diffSection *DiffSection) getDiffLineForRender(ctx context.Context, diffLineType DiffLineType, leftLine, rightLine *DiffLine, locale translation.Locale) DiffInline {
295295
var fileLanguage string
296296
var highlightedLeftLines, highlightedRightLines map[int]template.HTML
297297
// when a "diff section" is manually prepared by ExcerptBlob, it doesn't have "file" information
@@ -326,25 +326,25 @@ func (diffSection *DiffSection) getDiffLineForRender(diffLineType DiffLineType,
326326
lineHTML = util.Iif(diffLineType == DiffLineDel, diff1, diff2)
327327
}
328328
}
329-
return DiffInlineWithUnicodeEscape(lineHTML, locale)
329+
return DiffInlineWithUnicodeEscape(ctx, lineHTML, locale)
330330
}
331331

332332
// GetComputedInlineDiffFor computes inline diff for the given line.
333-
func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine, locale translation.Locale) DiffInline {
333+
func (diffSection *DiffSection) GetComputedInlineDiffFor(ctx context.Context, diffLine *DiffLine, locale translation.Locale) DiffInline {
334334
// try to find equivalent diff line. ignore, otherwise
335335
switch diffLine.Type {
336336
case DiffLineSection:
337-
return getLineContent(diffLine.Content[1:], locale)
337+
return getLineContent(ctx, diffLine.Content[1:], locale)
338338
case DiffLineAdd:
339339
compareDiffLine := diffSection.GetLine(diffLine.Match)
340-
return diffSection.getDiffLineForRender(DiffLineAdd, compareDiffLine, diffLine, locale)
340+
return diffSection.getDiffLineForRender(ctx, DiffLineAdd, compareDiffLine, diffLine, locale)
341341
case DiffLineDel:
342342
compareDiffLine := diffSection.GetLine(diffLine.Match)
343-
return diffSection.getDiffLineForRender(DiffLineDel, diffLine, compareDiffLine, locale)
343+
return diffSection.getDiffLineForRender(ctx, DiffLineDel, diffLine, compareDiffLine, locale)
344344
default: // Plain
345345
// TODO: there was an "if" check: `if diffLine.Content >strings.IndexByte(" +-", diffLine.Content[0]) > -1 { ... } else { ... }`
346346
// no idea why it needs that check, it seems that the "if" should be always true, so try to simplify the code
347-
return diffSection.getDiffLineForRender(DiffLinePlain, nil, diffLine, locale)
347+
return diffSection.getDiffLineForRender(ctx, DiffLinePlain, nil, diffLine, locale)
348348
}
349349
}
350350

services/webtheme/webtheme.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package webtheme
55

66
import (
7+
"context"
78
"regexp"
89
"sort"
910
"strings"
@@ -105,7 +106,7 @@ func parseThemeMetaInfo(fileName, cssContent string) *ThemeMetaInfo {
105106
return themeInfo
106107
}
107108

108-
func initThemes() {
109+
func initThemes(ctx context.Context) {
109110
availableThemes = nil
110111
defer func() {
111112
availableThemeInternalNames = container.Set[string]{}
@@ -133,8 +134,8 @@ func initThemes() {
133134
foundThemes = append(foundThemes, parseThemeMetaInfo(fileName, util.UnsafeBytesToString(content)))
134135
}
135136
}
136-
if len(setting.UI.Themes) > 0 {
137-
allowedThemes := container.SetOf(setting.UI.Themes...)
137+
if len(setting.Config().UI.Themes.Value(ctx)) > 0 {
138+
allowedThemes := container.SetOf(setting.Config().UI.Themes.Value(ctx)...)
138139
for _, theme := range foundThemes {
139140
if allowedThemes.Contains(theme.InternalName) {
140141
availableThemes = append(availableThemes, theme)
@@ -155,12 +156,16 @@ func initThemes() {
155156
}
156157
}
157158

158-
func GetAvailableThemes() []*ThemeMetaInfo {
159-
themeOnce.Do(initThemes)
159+
func GetAvailableThemes(ctx context.Context) []*ThemeMetaInfo {
160+
themeOnce.Do(func() {
161+
initThemes(ctx)
162+
})
160163
return availableThemes
161164
}
162165

163-
func IsThemeAvailable(internalName string) bool {
164-
themeOnce.Do(initThemes)
166+
func IsThemeAvailable(ctx context.Context, internalName string) bool {
167+
themeOnce.Do(func() {
168+
initThemes(ctx)
169+
})
165170
return availableThemeInternalNames.Contains(internalName)
166171
}

0 commit comments

Comments
 (0)