mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-08 06:03:03 -04:00
Fix initializing custom themes with ThemeStore too early
This commit is contained in:
parent
707d688887
commit
c1f19d5288
11 changed files with 42 additions and 32 deletions
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue