This commit is contained in:
thororen1234 2024-06-21 16:43:31 -04:00
parent 2960e9a74a
commit 5fbb3698f4
3 changed files with 7 additions and 35 deletions

View file

@ -30,13 +30,13 @@ import { openInviteModal } from "@utils/discord";
import { openModal } from "@utils/modal"; import { openModal } from "@utils/modal";
import { showItemInFolder } from "@utils/native"; import { showItemInFolder } from "@utils/native";
import { useAwaiter } from "@utils/react"; import { useAwaiter } from "@utils/react";
import { ThemeHeader } from "@utils/themes"; import type { ThemeHeader } from "@utils/themes";
import { getThemeInfo, stripBOM, type UserThemeHeader } from "@utils/themes/bd"; import { getThemeInfo, stripBOM, type UserThemeHeader } from "@utils/themes/bd";
import { usercssParse } from "@utils/themes/usercss"; import { usercssParse } from "@utils/themes/usercss";
import { findByPropsLazy, findLazy } from "@webpack"; import { findByPropsLazy, findLazy } from "@webpack";
import { Button, Card, Forms, React, showToast, TabBar, TextInput, Tooltip, useEffect, useMemo, useRef, useState } from "@webpack/common"; import { Button, Card, Forms, React, showToast, TabBar, TextInput, Tooltip, useEffect, useMemo, useRef, useState } from "@webpack/common";
import type { ComponentType, Ref, SyntheticEvent } from "react"; import type { ComponentType, Ref, SyntheticEvent } from "react";
import { UserstyleHeader } from "usercss-meta"; import type { UserstyleHeader } from "usercss-meta";
import { isPluginEnabled } from "../../plugins"; import { isPluginEnabled } from "../../plugins";
import { UserCSSSettingsModal } from "./UserCSSModal"; import { UserCSSSettingsModal } from "./UserCSSModal";

View file

@ -68,39 +68,15 @@ async function initThemes() {
const links: string[] = [...enabledThemeLinks]; const links: string[] = [...enabledThemeLinks];
if (IS_WEB) { if (IS_WEB) {
for (let i = enabledThemes.length - 1; i >= 0; i--) { for (const theme of enabledThemes) {
const theme = enabledThemes[i]; const themeData = await VencordNative.themes.getThemeData(theme);
if (!themeData) continue;
try {
var themeData = await VencordNative.themes.getThemeData(theme);
} catch (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;
}
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 (let i = enabledThemes.length - 1; i >= 0; i--) { for (const theme of enabledThemes) if (!theme.endsWith(".user.css")) {
const theme = enabledThemes[i];
if (theme.endsWith(".user.css")) continue;
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()}`);
} }
} }

View file

@ -55,11 +55,7 @@ const preprocessors: { [preprocessor: string]: (text: string, vars: Record<strin
}; };
export async function compileUsercss(fileName: string) { export async function compileUsercss(fileName: string) {
try { const themeData = await VencordNative.themes.getThemeData(fileName);
var themeData = await VencordNative.themes.getThemeData(fileName);
} catch (e) {
UserCSSLogger.warn("Failed to get theme data for", fileName, "(has it gone missing?)", e);
}
if (!themeData) return null; if (!themeData) return null;
// UserCSS preprocessor order look like this: // UserCSS preprocessor order look like this: