BetterFolders Fix For Themes

This commit is contained in:
thororen1234 2025-04-04 09:39:22 -04:00
parent d938ad3a87
commit 2db53146c4
No known key found for this signature in database

View file

@ -80,12 +80,10 @@ async function initThemes() {
themesStyle ??= createStyle("vencord-themes"); themesStyle ??= createStyle("vencord-themes");
const { enabledThemeLinks, enabledThemes } = Settings; const { enabledThemeLinks, enabledThemes } = Settings;
const enabledlinks: string[] = [...enabledThemeLinks]; const enabledlinks: string[] = [...enabledThemeLinks];
// "darker" and "midnight" both count as dark
const activeTheme = ThemeStore.theme === "light" ? "light" : "dark"; const activeTheme = ThemeStore.theme === "light" ? "light" : "dark";
const links = enabledlinks const rawLinks = enabledlinks
.map(rawLink => { .map(rawLink => {
const match = /^@(light|dark) (.*)/.exec(rawLink); const match = /^@(light|dark) (.*)/.exec(rawLink);
if (!match) return rawLink; if (!match) return rawLink;
@ -93,19 +91,30 @@ async function initThemes() {
const [, mode, link] = match; const [, mode, link] = match;
return mode === activeTheme ? link : null; return mode === activeTheme ? link : null;
}) })
.filter(link => link !== null); .filter((link): link is string => link !== null);
const links: string[] = [];
for (const url of rawLinks) {
try {
const res = await fetch(url);
const css = await res.text();
const patched = patchSidebar(css);
const blob = new Blob([patched], { type: "text/css" });
links.push(URL.createObjectURL(blob));
} catch (e) {
console.warn(`Failed to fetch theme from ${url}`, e);
}
}
if (IS_WEB) {
for (const theme of enabledThemes) { for (const theme of enabledThemes) {
const themeData = await VencordNative.themes.getThemeData(theme); const themeData = await VencordNative.themes.getThemeData(theme);
if (!themeData) continue; if (!themeData) continue;
const blob = new Blob([themeData], { type: "text/css" });
const patchedTheme = patchSidebar(themeData);
const blob = new Blob([patchedTheme], { type: "text/css" });
links.push(URL.createObjectURL(blob)); links.push(URL.createObjectURL(blob));
} }
} else {
const localThemes = enabledThemes.map(theme => `vencord:///themes/${theme}?v=${Date.now()}`);
links.push(...localThemes);
}
themesStyle.textContent = links.map(link => `@import url("${link.trim()}");`).join("\n"); themesStyle.textContent = links.map(link => `@import url("${link.trim()}");`).join("\n");
} }