diff --git a/src/lib/managers/themes.ts b/src/lib/managers/themes.ts index a3897f5..2f77992 100644 --- a/src/lib/managers/themes.ts +++ b/src/lib/managers/themes.ts @@ -1,4 +1,7 @@ -// TODO: rewrite most of this +/** + * Theming system in Bunny is currently a prototype, expect an unreadable theme implementation below + */ + import { getStoredTheme, getThemeFilePath } from "@lib/api/native/loader"; import { ThemeManager } from "@lib/api/native/modules"; import { after, before, instead } from "@lib/api/patcher"; @@ -213,7 +216,7 @@ const origRawColor = { ...color.RawColor }; let inc = 0; let vdKey = "vd-theme"; -let vdThemeFallback = "darker"; +let vdThemeFallback = "dark"; let enabled = false; let currentTheme: Theme | null; @@ -222,6 +225,13 @@ function isDiscordTheme(name: string) { return discordThemes.has(name); } +const dMapThemeType = { + dark: "dark", + darker: "dark", + midnight: "dark", + light: "light" +}; + function patchColor() { const isThemeModule = find(m => m.isThemeDark && Object.getOwnPropertyDescriptor(m, "isThemeDark")?.value); const callback = ([theme]: any[]) => theme === vdKey ? [vdThemeFallback] : void 0; @@ -339,22 +349,23 @@ function getDefaultFallbackTheme(fallback: string = vdThemeFallback) { export function applyTheme(appliedTheme: Theme | null, fallbackTheme?: string, update = true) { if (!fallbackTheme) fallbackTheme = getDefaultFallbackTheme(); + fallbackTheme = (dMapThemeType as any)[fallbackTheme] ?? "dark"; currentTheme = appliedTheme; - vdThemeFallback = fallbackTheme; + vdThemeFallback = fallbackTheme!!; vdKey = `vd-theme-${inc++}-${fallbackTheme}`; if (appliedTheme) { color.Theme[vdKey.toUpperCase()] = vdKey; formDividerModule.DIVIDER_COLORS = new Proxy(formDividerModule.DIVIDER_COLORS, { - get: (t, p, r) => p === vdKey && fallbackTheme ? t[fallbackTheme] : Reflect.get(t, p, r) + get: (t, p, r) => p === vdKey ? t[vdThemeFallback] : Reflect.get(t, p, r) }); - Object.keys(color.Shadow).forEach(k => color.Shadow[k][vdKey] = color.Shadow[k][fallbackTheme!!]); + Object.keys(color.Shadow).forEach(k => color.Shadow[k][vdKey] = color.Shadow[k][vdThemeFallback]); Object.keys(color.SemanticColor).forEach(k => { color.SemanticColor[k][vdKey] = { - ...color.SemanticColor[k][fallbackTheme!!], + ...color.SemanticColor[k][vdThemeFallback], override: appliedTheme?.data?.semanticColors?.[k]?.[0] }; });