[Bugfix] Fix forced Hindi timestamps
This commit is contained in:
parent
293c256dc9
commit
2201ff3a1d
6 changed files with 38 additions and 42 deletions
|
@ -3,9 +3,9 @@ import { patchCommands } from "@lib/commands";
|
||||||
import { initPlugins } from "@lib/plugins";
|
import { initPlugins } from "@lib/plugins";
|
||||||
import { patchAssets } from "@ui/assets";
|
import { patchAssets } from "@ui/assets";
|
||||||
import initSettings from "@ui/settings";
|
import initSettings from "@ui/settings";
|
||||||
import fixTheme from "@ui/fixTheme";
|
import initFixes from "@lib/fixes";
|
||||||
import windowObject from "@lib/windowObject";
|
|
||||||
import logger from "@lib/logger";
|
import logger from "@lib/logger";
|
||||||
|
import windowObject from "@lib/windowObject";
|
||||||
|
|
||||||
// This logs in the native logging implementation, e.g. logcat
|
// This logs in the native logging implementation, e.g. logcat
|
||||||
console.log("Hello from Vendetta!");
|
console.log("Hello from Vendetta!");
|
||||||
|
@ -17,7 +17,7 @@ console.log("Hello from Vendetta!");
|
||||||
patchLogHook(),
|
patchLogHook(),
|
||||||
patchAssets(),
|
patchAssets(),
|
||||||
patchCommands(),
|
patchCommands(),
|
||||||
fixTheme(),
|
initFixes(),
|
||||||
initSettings(),
|
initSettings(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
33
src/lib/fixes.ts
Normal file
33
src/lib/fixes.ts
Normal file
|
@ -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);
|
|
@ -24,4 +24,4 @@ export const React = window.React as typeof import("react");
|
||||||
export { ReactNative } from "@metro/hoist";
|
export { ReactNative } from "@metro/hoist";
|
||||||
|
|
||||||
// Moment
|
// Moment
|
||||||
export { moment } from "@metro/hoist";
|
export const moment = findByProps("isMoment") as typeof import("moment");
|
|
@ -1,5 +1,4 @@
|
||||||
import { MetroModules, PropsFinder, PropsFinderAll } from "@types";
|
import { MetroModules, PropsFinder, PropsFinderAll } from "@types";
|
||||||
import { moment } from "@metro/hoist";
|
|
||||||
|
|
||||||
// Metro require
|
// Metro require
|
||||||
declare const __r: (moduleId: number) => any;
|
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 filterModules = (modules: MetroModules, single = false) => (filter: (m: any) => boolean) => {
|
||||||
const found = [];
|
const found = [];
|
||||||
|
|
||||||
// Get the previous moment locale
|
|
||||||
const previousLocale = moment?.locale();
|
|
||||||
|
|
||||||
for (const key in modules) {
|
for (const key in modules) {
|
||||||
const id = Number(key);
|
const id = Number(key);
|
||||||
const module = modules[id]?.publicModule?.exports;
|
const module = modules[id]?.publicModule?.exports;
|
||||||
|
|
||||||
if (!modules[id].isInitialized) try {
|
if (!modules[id].isInitialized) try {
|
||||||
__r(id);
|
__r(id);
|
||||||
// Set moment locale, sort of crappy fix but works I guess
|
|
||||||
if (previousLocale && previousLocale !== moment.locale()) moment.locale(previousLocale);
|
|
||||||
} catch {};
|
} catch {};
|
||||||
|
|
||||||
if (!module) {
|
if (!module) {
|
||||||
|
|
|
@ -12,6 +12,3 @@ export const ReactNative = basicFind("AppRegistry") as typeof import("react-nati
|
||||||
|
|
||||||
// Export Discord's constants
|
// Export Discord's constants
|
||||||
export const constants = basicFind("AbortCodes");
|
export const constants = basicFind("AbortCodes");
|
||||||
|
|
||||||
// Export moment
|
|
||||||
export const moment = basicFind("isMoment") as typeof import("moment");
|
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue