diff --git a/scripts/build.mjs b/scripts/build.mjs index 787124c..d4a3640 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -74,7 +74,7 @@ const config = { constModules: { globals: { "bunny-build-info": { - version: `"v1.3.4"` + version: `"v1.3.5"` } } }, diff --git a/src/lib/addons/themes/colors/patches/resolver.ts b/src/lib/addons/themes/colors/patches/resolver.ts index 103f5ce..610e56a 100644 --- a/src/lib/addons/themes/colors/patches/resolver.ts +++ b/src/lib/addons/themes/colors/patches/resolver.ts @@ -22,6 +22,20 @@ const SEMANTIC_FALLBACK_MAP: Record = { "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 = { + "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]]; -} +} \ No newline at end of file diff --git a/src/lib/addons/themes/colors/updater.ts b/src/lib/addons/themes/colors/updater.ts index b7d0e3f..c7b265b 100644 --- a/src/lib/addons/themes/colors/updater.ts +++ b/src/lib/addons/themes/colors/updater.ts @@ -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); - } } diff --git a/src/lib/addons/themes/index.ts b/src/lib/addons/themes/index.ts index 6efffa9..546c040 100644 --- a/src/lib/addons/themes/index.ts +++ b/src/lib/addons/themes/index.ts @@ -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); } }