Skip to content

Commit

Permalink
Make theme based on base themes
Browse files Browse the repository at this point in the history
third elements of `semanticColors` themes are now ALWAYS ignored
  • Loading branch information
pylixonly committed Mar 11, 2024
1 parent 67e4934 commit dd5cfc7
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/lib/managers/themes.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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]
};
});
Expand Down

0 comments on commit dd5cfc7

Please sign in to comment.