Skip to content

Commit

Permalink
getSystemTheme
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminDreasond committed Jun 1, 2024
1 parent e1d56cc commit a8975e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ NAVIGATION_SIDEBAR_HIDDEN=false

# Limit items rows on emojiboard.
FAV_EMOJI_ROWS_LIMIT=50

RECENT_EMOJI_ROWS_LIMIT=3

FAV_STICKER_ROWS_LIMIT=3

RECENT_STICKER_ROWS_LIMIT=50

### Homeserver list
Expand Down
12 changes: 11 additions & 1 deletion src/client/state/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Settings extends EventEmitter {
},
);

this.systemIsDark = null;
this.useSystemTheme = this.getUseSystemTheme();
this.isMarkdown = this.getIsMarkdown();
this.isPeopleDrawer = this.getIsPeopleDrawer();
Expand All @@ -128,6 +129,13 @@ class Settings extends EventEmitter {
'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
}

getSystemTheme() {
return {
enabled: this.useSystemTheme,
isDark: this.systemIsDark,
};
}

getThemeIndex() {
if (typeof this.themeIndex === 'number') return this.themeIndex;

Expand Down Expand Up @@ -246,10 +254,12 @@ class Settings extends EventEmitter {
body.addClass('discord-style');
}

this.systemIsDark =
window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
if (useSystemTheme) {
body.addClass('system-theme');

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
if (this.systemIsDark) {
body.addClass(this.defaultSystemThemeType.dark);
} else {
body.addClass(this.defaultSystemThemeType.light);
Expand Down

0 comments on commit a8975e7

Please sign in to comment.