Skip to content

Commit dc56dfa

Browse files
committed
Use light/dark theme based on system preference
Add a new default theme `auto`, which will automatically switch between `gitea` (light) and `arc-green` (dark) themes depending on the user's operating system settings. Closes: #8183
1 parent 87505a9 commit dc56dfa

File tree

8 files changed

+19
-9
lines changed

8 files changed

+19
-9
lines changed

.stylelintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ rules:
1313
rule-empty-line-before: null
1414
selector-pseudo-element-colon-notation: double
1515
shorthand-property-no-redundant-values: true
16+
no-invalid-position-at-import-rule: null

custom/conf/app.example.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,10 +1035,10 @@ PATH =
10351035
;SHOW_USER_EMAIL = true
10361036
;;
10371037
;; Set the default theme for the Gitea install
1038-
;DEFAULT_THEME = gitea
1038+
;DEFAULT_THEME = auto
10391039
;;
10401040
;; All available themes. Allow users select personalized themes regardless of the value of `DEFAULT_THEME`.
1041-
;THEMES = gitea,arc-green
1041+
;THEMES = auto,gitea,arc-green
10421042
;;
10431043
;; All available reactions users can choose on issues/prs and comments.
10441044
;; Values can be emoji alias (:smile:) or a unicode emoji.

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ The following configuration set `Content-Type: application/vnd.android.package-a
173173
- `FEED_PAGING_NUM`: **20**: Number of items that are displayed in home feed.
174174
- `GRAPH_MAX_COMMIT_NUM`: **100**: Number of maximum commits shown in the commit graph.
175175
- `CODE_COMMENT_LINES`: **4**: Number of line of codes shown for a code comment.
176-
- `DEFAULT_THEME`: **gitea**: \[gitea, arc-green\]: Set the default theme for the Gitea install.
176+
- `DEFAULT_THEME`: **auto**: \[auto, gitea, arc-green\]: Set the default theme for the Gitea install.
177177
- `SHOW_USER_EMAIL`: **true**: Whether the email of the user should be shown in the Explore Users page.
178-
- `THEMES`: **gitea,arc-green**: All available themes. Allow users select personalized themes.
178+
- `THEMES`: **auto,gitea,arc-green**: All available themes. Allow users select personalized themes.
179179
regardless of the value of `DEFAULT_THEME`.
180180
- `THEME_COLOR_META_TAG`: **#6cc644**: Value of `theme-color` meta tag, used by Android >= 5.0. An invalid color like "none" or "disable" will have the default style. More info: https://developers.google.com/web/updates/2014/11/Support-for-theme-color-in-Chrome-39-for-Android
181181
- `MAX_DISPLAY_FILE_SIZE`: **8388608**: Max size of files to be displayed (default is 8MiB)

docs/content/doc/advanced/customizing-gitea.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ A full list of supported emoji's is at [emoji list](https://gitea.com/gitea/gite
321321

322322
## Customizing the look of Gitea
323323

324-
The default built-in themes are `gitea` (light) and `arc-green` (dark).
324+
The default built-in themes are `gitea` (light), `arc-green` (dark), and `auto` (chooses light or dark depending on operating system settings).
325325
The default theme can be changed via `DEFAULT_THEME` in the [ui](https://docs.gitea.io/en-us/config-cheat-sheet/#ui-ui) section of `app.ini`.
326326

327327
Gitea also has support for user themes, which means every user can select which theme should be used.

docs/content/doc/help/faq.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Use [Fail2Ban]({{< relref "doc/usage/fail2ban-setup.en-us.md" >}}) to monitor an
158158

159159
## How to add/use custom themes
160160

161-
Gitea supports two official themes right now, `gitea` and `arc-green` (`light` and `dark` respectively)
161+
Gitea supports three official themes right now, `gitea` (light), `arc-green` (dark), and `auto` (automatically switches between the previous two depending on operating system settings).
162162
To add your own theme, currently the only way is to provide a complete theme (not just color overrides)
163163

164164
As an example, let's say our theme is `arc-blue` (this is a real theme, and can be found [in this issue](https://github.com/go-gitea/gitea/issues/6011))

modules/setting/setting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ var (
256256
ReactionMaxUserNum: 10,
257257
ThemeColorMetaTag: `#6cc644`,
258258
MaxDisplayFileSize: 8388608,
259-
DefaultTheme: `gitea`,
260-
Themes: []string{`gitea`, `arc-green`},
259+
DefaultTheme: `auto`,
260+
Themes: []string{`auto`, `gitea`, `arc-green`},
261261
Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`},
262262
CustomEmojis: []string{`git`, `gitea`, `codeberg`, `gitlab`, `github`, `gogs`},
263263
CustomEmojisMap: map[string]string{"git": ":git:", "gitea": ":gitea:", "codeberg": ":codeberg:", "gitlab": ":gitlab:", "github": ":github:", "gogs": ":gogs:"},

web_src/js/utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ export function isObject(obj) {
2626

2727
// returns whether a dark theme is enabled
2828
export function isDarkTheme() {
29-
return document.documentElement.classList.contains('theme-arc-green');
29+
if (document.documentElement.classList.contains('theme-auto')) {
30+
return window.matchMedia('(prefers-color-scheme: dark)').matches;
31+
}
32+
if (document.documentElement.classList.contains('theme-arc-green')) {
33+
return true;
34+
}
35+
return false;
3036
}
3137

3238
// removes duplicate elements in an array

web_src/less/themes/theme-auto.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@media (prefers-color-scheme: dark) {
2+
@import "theme-arc-green.less";
3+
}

0 commit comments

Comments
 (0)