Fix initializing custom themes with ThemeStore too early

This commit is contained in:
Nuckyz 2025-05-14 17:08:56 -03:00
parent 707d688887
commit c1f19d5288
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
11 changed files with 42 additions and 32 deletions

View file

@ -19,7 +19,6 @@
import { Settings, SettingsStore } from "@api/Settings";
import { ThemeStore } from "@webpack/common";
let style: HTMLStyleElement;
let themesStyle: HTMLStyleElement;
@ -61,7 +60,10 @@ async function initThemes() {
const { themeLinks, enabledThemes } = Settings;
// "darker" and "midnight" both count as dark
const activeTheme = ThemeStore.theme === "light" ? "light" : "dark";
// This function is first called on DOMContentLoaded, so ThemeStore may not have been loaded yet
const activeTheme = ThemeStore == null
? undefined
: ThemeStore.theme === "light" ? "light" : "dark";
const links = themeLinks
.map(rawLink => {
@ -90,7 +92,6 @@ async function initThemes() {
document.addEventListener("DOMContentLoaded", () => {
initSystemValues();
initThemes();
toggle(Settings.useQuickCss);
SettingsStore.addChangeListener("useQuickCss", toggle);
@ -98,6 +99,16 @@ document.addEventListener("DOMContentLoaded", () => {
SettingsStore.addChangeListener("themeLinks", initThemes);
SettingsStore.addChangeListener("enabledThemes", initThemes);
if (!IS_WEB) {
VencordNative.quickCss.addThemeChangeListener(initThemes);
}
initThemes();
});
export function initQuickCssThemeStore() {
initThemes();
let currentTheme = ThemeStore.theme;
ThemeStore.addChangeListener(() => {
if (currentTheme === ThemeStore.theme) return;
@ -105,7 +116,4 @@ document.addEventListener("DOMContentLoaded", () => {
currentTheme = ThemeStore.theme;
initThemes();
});
if (!IS_WEB)
VencordNative.quickCss.addThemeChangeListener(initThemes);
});
}