diff --git a/src/core/fixes.ts b/src/core/fixes.ts index 2f01cf4..1791066 100644 --- a/src/core/fixes.ts +++ b/src/core/fixes.ts @@ -1,20 +1,29 @@ -import { instead } from "spitroast"; // Assuming you have this from entry.ts setup +/** + * Why do we need this exactly? It's simple, to fight the side effects caused by when you + * initialize modules not in the right time or when you're not supposed to. + * Back then, we had major bugs like the mixing of light and dark themes and AMOLED option getting ignored. + * Nowadays, there are only three which I can spot: Hindi timestamps, crashing on some native components and slower startup time. + * - @pylixonly + */ -// Find the module with scoreCommand (use your mod's finder utils, like findByCode if you have one) -const searchModule = /* Your finder here, e.g., findByCode("toLocaleLowerCase", "scoreCommand") or similar */; +import { logger } from "@lib/utils/logger"; +import { FluxDispatcher } from "@metro/common"; -if (searchModule) { - instead(searchModule.scoreCommand, (args, orig) => { - // Add null check before the lowercase call - const [command, query] = args; // Assuming args structure based on typical Discord code - if (query === undefined || query === null) { - return 0; // Or some safe default score to skip - } - // Or target the exact line: wrap the string op - // e.g., if the buggy line is something like str.toLocaleLowerCase(), replace with str?.toLocaleLowerCase() ?? "" - return orig(...args); - }); - logger.log("Patched scoreCommand to handle undefined values!"); -} else { - logger.warn("Couldn't find scoreCommand module to patch."); +function onDispatch({ locale }: { locale: string }) { + // Timestamps - require moment lazily so we avoid top-level import cost + try { + // require at runtime (lazy) to keep startup/bundle lighter + // eslint-disable-next-line @typescript-eslint/no-var-requires + const moment = require("moment"); + moment.locale(locale.toLowerCase()); + } catch (e) { + logger.error("Failed to fix timestamps (lazy moment)...", e); + } + + // We're done here! + FluxDispatcher.unsubscribe("I18N_LOAD_SUCCESS", onDispatch); } + +export default () => { + FluxDispatcher.subscribe("I18N_LOAD_SUCCESS", onDispatch); +};