From 2201ff3a1dce06c77afae537654a279f2bc2626e Mon Sep 17 00:00:00 2001 From: Beef Date: Tue, 7 Mar 2023 23:12:41 +0000 Subject: [PATCH] [Bugfix] Fix forced Hindi timestamps --- src/index.ts | 6 +++--- src/lib/fixes.ts | 33 +++++++++++++++++++++++++++++++++ src/lib/metro/common.ts | 2 +- src/lib/metro/filters.ts | 6 ------ src/lib/metro/hoist.ts | 5 +---- src/ui/fixTheme.ts | 28 ---------------------------- 6 files changed, 38 insertions(+), 42 deletions(-) create mode 100644 src/lib/fixes.ts delete mode 100644 src/ui/fixTheme.ts diff --git a/src/index.ts b/src/index.ts index 09892eb..4432600 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,9 +3,9 @@ import { patchCommands } from "@lib/commands"; import { initPlugins } from "@lib/plugins"; import { patchAssets } from "@ui/assets"; import initSettings from "@ui/settings"; -import fixTheme from "@ui/fixTheme"; -import windowObject from "@lib/windowObject"; +import initFixes from "@lib/fixes"; import logger from "@lib/logger"; +import windowObject from "@lib/windowObject"; // This logs in the native logging implementation, e.g. logcat console.log("Hello from Vendetta!"); @@ -17,7 +17,7 @@ console.log("Hello from Vendetta!"); patchLogHook(), patchAssets(), patchCommands(), - fixTheme(), + initFixes(), initSettings(), ]); diff --git a/src/lib/fixes.ts b/src/lib/fixes.ts new file mode 100644 index 0000000..f1ebbd0 --- /dev/null +++ b/src/lib/fixes.ts @@ -0,0 +1,33 @@ +import { FluxDispatcher, moment } from "@metro/common"; +import { findByProps, findByStoreName } from "@metro/filters"; +import logger from "@lib/logger"; + +const ThemeManager = findByProps("updateTheme", "overrideTheme"); +const AMOLEDThemeManager = findByProps("setAMOLEDThemeEnabled"); +const ThemeStore = findByStoreName("ThemeStore"); +const UnsyncedUserSettingsStore = findByStoreName("UnsyncedUserSettingsStore"); + +function onDispatch({ locale }: { locale: string }) { + // Theming + // Based on https://github.com/Aliucord/AliucordRN/blob/main/src/ui/patchTheme.ts + try { + const theme = ThemeStore.theme || "dark"; + ThemeManager.overrideTheme(theme); + if (AMOLEDThemeManager && UnsyncedUserSettingsStore.useAMOLEDTheme === 2) AMOLEDThemeManager.setAMOLEDThemeEnabled(true); + } catch(e) { + logger.error("Failed to fix theme...", e); + } + + // Timestamps + try { + // TODO: Test if this works with all locales + moment.locale(locale.toLowerCase()); + } catch(e) { + logger.error("Failed to fix timestamps...", e); + } + + // We're done here! + FluxDispatcher.unsubscribe("I18N_LOAD_START", onDispatch); +} + +export default () => FluxDispatcher.subscribe("I18N_LOAD_START", onDispatch); \ No newline at end of file diff --git a/src/lib/metro/common.ts b/src/lib/metro/common.ts index 20eb0d2..7ac2069 100644 --- a/src/lib/metro/common.ts +++ b/src/lib/metro/common.ts @@ -24,4 +24,4 @@ export const React = window.React as typeof import("react"); export { ReactNative } from "@metro/hoist"; // Moment -export { moment } from "@metro/hoist"; \ No newline at end of file +export const moment = findByProps("isMoment") as typeof import("moment"); \ No newline at end of file diff --git a/src/lib/metro/filters.ts b/src/lib/metro/filters.ts index 32fcd11..ca00b47 100644 --- a/src/lib/metro/filters.ts +++ b/src/lib/metro/filters.ts @@ -1,5 +1,4 @@ import { MetroModules, PropsFinder, PropsFinderAll } from "@types"; -import { moment } from "@metro/hoist"; // Metro require declare const __r: (moduleId: number) => any; @@ -29,17 +28,12 @@ for (const key in window.modules) { const filterModules = (modules: MetroModules, single = false) => (filter: (m: any) => boolean) => { const found = []; - // Get the previous moment locale - const previousLocale = moment?.locale(); - for (const key in modules) { const id = Number(key); const module = modules[id]?.publicModule?.exports; if (!modules[id].isInitialized) try { __r(id); - // Set moment locale, sort of crappy fix but works I guess - if (previousLocale && previousLocale !== moment.locale()) moment.locale(previousLocale); } catch {}; if (!module) { diff --git a/src/lib/metro/hoist.ts b/src/lib/metro/hoist.ts index fa06c3a..cfe5d86 100644 --- a/src/lib/metro/hoist.ts +++ b/src/lib/metro/hoist.ts @@ -11,7 +11,4 @@ window.React = basicFind("createElement") as typeof import("react"); export const ReactNative = basicFind("AppRegistry") as typeof import("react-native"); // Export Discord's constants -export const constants = basicFind("AbortCodes"); - -// Export moment -export const moment = basicFind("isMoment") as typeof import("moment"); +export const constants = basicFind("AbortCodes"); \ No newline at end of file diff --git a/src/ui/fixTheme.ts b/src/ui/fixTheme.ts deleted file mode 100644 index 4e42589..0000000 --- a/src/ui/fixTheme.ts +++ /dev/null @@ -1,28 +0,0 @@ -// Based on https://github.com/Aliucord/AliucordRN/blob/main/src/ui/patchTheme.ts -// Literally could not figure this out, many thanks - -import { FluxDispatcher } from "@metro/common"; -import { findByProps, findByStoreName } from "@metro/filters"; -import logger from "@lib/logger"; - -// TODO: Move these to common modules? -const ThemeManager = findByProps("updateTheme", "overrideTheme"); -const AMOLEDThemeManager = findByProps("setAMOLEDThemeEnabled"); -const ThemeStore = findByStoreName("ThemeStore"); -const UnsyncedUserSettingsStore = findByStoreName("UnsyncedUserSettingsStore"); - -function override() { - const theme = ThemeStore.theme || "dark"; - ThemeManager.overrideTheme(theme); - - if (AMOLEDThemeManager && UnsyncedUserSettingsStore.useAMOLEDTheme === 2) AMOLEDThemeManager.setAMOLEDThemeEnabled(true); - FluxDispatcher.unsubscribe("I18N_LOAD_START", override); -} - -export default function fixTheme() { - try { - if (ThemeStore) FluxDispatcher.subscribe("I18N_LOAD_START", override); - } catch(e) { - logger.error("Failed to fix theme...", e) - } -} \ No newline at end of file