From a8975e76c89892cb9ab15b96d065b52105aad7a5 Mon Sep 17 00:00:00 2001 From: "Yasmin Seidel (JasminDreasond)" Date: Sat, 1 Jun 2024 00:18:05 -0300 Subject: [PATCH] getSystemTheme --- .env | 3 --- src/client/state/settings.js | 12 +++++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.env b/.env index f67c2464f..1091ecb2f 100644 --- a/.env +++ b/.env @@ -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 diff --git a/src/client/state/settings.js b/src/client/state/settings.js index ee61c267c..8224911b7 100644 --- a/src/client/state/settings.js +++ b/src/client/state/settings.js @@ -115,6 +115,7 @@ class Settings extends EventEmitter { }, ); + this.systemIsDark = null; this.useSystemTheme = this.getUseSystemTheme(); this.isMarkdown = this.getIsMarkdown(); this.isPeopleDrawer = this.getIsPeopleDrawer(); @@ -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; @@ -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);