fix: hacky way of checking if themes are valid

This commit is contained in:
Lewis Crichton 2023-12-31 00:29:00 +00:00
parent 1c0dff3666
commit 6a3c592d5f
No known key found for this signature in database
2 changed files with 24 additions and 6 deletions

View file

@ -66,26 +66,43 @@ async function initThemes() {
const links: string[] = [...themeLinks]; const links: string[] = [...themeLinks];
const enabledThemesClone = enabledThemes.slice();
if (IS_WEB) { if (IS_WEB) {
for (const theme of enabledThemes) { // make copy so we can remove themes that are missing
for (const theme of enabledThemesClone) {
try { try {
var themeData = await VencordNative.themes.getThemeData(theme); var themeData = await VencordNative.themes.getThemeData(theme);
} catch (e) { } catch (e) {
logger.error("Failed to get theme data for", theme, e); logger.warn("Failed to get theme data for", theme, "(has it gone missing?)", e);
}
if (!themeData) {
// disable the theme since it has problems
Settings.enabledThemes = enabledThemes.splice(enabledThemes.indexOf(theme), 1);
continue;
} }
if (!themeData) continue;
const blob = new Blob([themeData], { type: "text/css" }); const blob = new Blob([themeData], { type: "text/css" });
links.push(URL.createObjectURL(blob)); links.push(URL.createObjectURL(blob));
} }
} else { } else {
for (const theme of enabledThemes) if (!theme.endsWith(".user.css")) { for (const theme of enabledThemesClone) if (!theme.endsWith(".user.css")) {
try {
// whilst this is unnecessary here, we're doing it to make sure the theme is valid
await VencordNative.themes.getThemeData(theme);
} catch (e) {
logger.warn("Failed to get theme data for", theme, "(has it gone missing?)", e);
Settings.enabledThemes = enabledThemes.splice(enabledThemes.indexOf(theme), 1);
continue;
}
links.push(`vencord:///themes/${theme}?v=${Date.now()}`); links.push(`vencord:///themes/${theme}?v=${Date.now()}`);
} }
} }
if (!IS_WEB || "armcord" in window) { if (!IS_WEB || "armcord" in window) {
for (const theme of enabledThemes) if (theme.endsWith(".user.css")) { for (const theme of enabledThemesClone) if (theme.endsWith(".user.css")) {
// UserCSS goes through a compile step first // UserCSS goes through a compile step first
const css = await compileUsercss(theme); const css = await compileUsercss(theme);
if (!css) { if (!css) {
@ -98,6 +115,7 @@ async function initThemes() {
position: Toasts.Position.BOTTOM position: Toasts.Position.BOTTOM
} }
}); });
Settings.enabledThemes = enabledThemes.splice(enabledThemes.indexOf(theme), 1);
continue; continue;
} }

View file

@ -58,7 +58,7 @@ export async function compileUsercss(fileName: string) {
try { try {
var themeData = await VencordNative.themes.getThemeData(fileName); var themeData = await VencordNative.themes.getThemeData(fileName);
} catch (e) { } catch (e) {
UserCSSLogger.error("Failed to get theme data for", fileName, e); UserCSSLogger.warn("Failed to get theme data for", fileName, "(has it gone missing?)", e);
} }
if (!themeData) return null; if (!themeData) return null;