diff --git a/src/utils/quickCss.ts b/src/utils/quickCss.ts index e69e3c09d..04a00de9c 100644 --- a/src/utils/quickCss.ts +++ b/src/utils/quickCss.ts @@ -66,26 +66,43 @@ async function initThemes() { const links: string[] = [...themeLinks]; + const enabledThemesClone = enabledThemes.slice(); + if (IS_WEB) { - for (const theme of enabledThemes) { + // make copy so we can remove themes that are missing + for (const theme of enabledThemesClone) { try { var themeData = await VencordNative.themes.getThemeData(theme); } 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" }); links.push(URL.createObjectURL(blob)); } } 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()}`); } } 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 const css = await compileUsercss(theme); if (!css) { @@ -98,6 +115,7 @@ async function initThemes() { position: Toasts.Position.BOTTOM } }); + Settings.enabledThemes = enabledThemes.splice(enabledThemes.indexOf(theme), 1); continue; } diff --git a/src/utils/themes/usercss/compiler.ts b/src/utils/themes/usercss/compiler.ts index 0d9305be5..059b789ab 100644 --- a/src/utils/themes/usercss/compiler.ts +++ b/src/utils/themes/usercss/compiler.ts @@ -58,7 +58,7 @@ export async function compileUsercss(fileName: string) { try { var themeData = await VencordNative.themes.getThemeData(fileName); } 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;