Merge branch 'main' into github

This commit is contained in:
cocobo1 2025-10-15 21:41:38 +03:00
commit d46ab73b93
4 changed files with 31 additions and 14 deletions

View file

@ -74,7 +74,7 @@ const config = {
constModules: {
globals: {
"bunny-build-info": {
version: `"v1.3.4"`
version: `"v1.3.5"`
}
}
},

View file

@ -22,6 +22,20 @@ const SEMANTIC_FALLBACK_MAP: Record<string, string> = {
"BG_SURFACE_RAISED": "BACKGROUND_MOBILE_PRIMARY"
};
const origRawColor = { ...tokenReference.RawColor };
function getRawFallback(key: string): string | undefined {
const isDark = isThemeModule.isThemeDark?.(_colorRef.current?.reference);
if (!isDark) return undefined;
const DARK_MODE_RAW_FALLBACK: Record<string, string> = {
"PRIMARY_230": origRawColor.PRIMARY_700 || "#000000"
};
return DARK_MODE_RAW_FALLBACK[key];
}
export default function patchDefinitionAndResolver() {
const callback = ([theme]: any[]) => theme === _colorRef.key ? [_colorRef.current!.reference] : void 0;
@ -31,7 +45,12 @@ export default function patchDefinitionAndResolver() {
enumerable: true,
get: () => {
const ret = _colorRef.current?.raw[key];
return ret || _colorRef.origRaw[key];
if (ret) return ret;
const fallback = getRawFallback(key);
if (fallback) return fallback;
return origRawColor[key];
}
});
});
@ -64,15 +83,19 @@ export default function patchDefinitionAndResolver() {
return colorDef.opacity === 1 ? rawValue : chroma(rawValue).alpha(colorDef.opacity).hex();
}
const fallbackValue = getRawFallback(colorDef.raw);
if (fallbackValue) {
return colorDef.opacity === 1 ? fallbackValue : chroma(fallbackValue).alpha(colorDef.opacity).hex();
}
// Fallback to default
return orig(...args);
}),
() => {
// Not the actual module but.. yeah.
Object.defineProperty(tokenReference, "RawColor", {
configurable: true,
writable: true,
value: _colorRef.origRaw
value: origRawColor
});
}
];
@ -86,4 +109,4 @@ function extractInfo(themeName: string, colorObj: any): [name: string, colorDef:
const colorDef = tokenReference.SemanticColor[propName];
return [propName, colorDef[themeName]];
}
}

View file

@ -27,7 +27,7 @@ export const _colorRef: InternalColorRef = {
lastSetDiscordTheme: "darker"
};
export function updateBunnyColor(colorManifest: ColorManifest | null, { update = true, startup = true } ) {
export function updateBunnyColor(colorManifest: ColorManifest | null, { update = true } ) {
if (settings.safeMode?.enabled) return;
const internalDef = colorManifest ? parseColorManifest(colorManifest) : null;
@ -55,11 +55,5 @@ export function updateBunnyColor(colorManifest: ColorManifest | null, { update =
AppearanceManager.setShouldSyncAppearanceSettings(false);
AppearanceManager.updateTheme(internalDef != null ? ref.key : ref.lastSetDiscordTheme);
}
if (startup) {
// scuffed but it works
AppearanceManager.setShouldSyncAppearanceSettings(true);
AppearanceManager.updateTheme(internalDef != null ? ref.key : ref.lastSetDiscordTheme);
}
}

View file

@ -104,10 +104,10 @@ export function selectTheme(theme: VdThemeInfo | null, write = true) {
);
if (theme == null && write) {
updateBunnyColor(null, { update: false, startup: true });
updateBunnyColor(null, { update: true });
return writeThemeToNative({});
} else if (theme) {
updateBunnyColor(theme.data, { update: true, startup: false });
updateBunnyColor(theme.data, { update: true });
return writeThemeToNative(theme);
}
}