diff --git a/src/lib/metro/common.ts b/src/lib/metro/common.ts index 3ea726a..1f3ad0b 100644 --- a/src/lib/metro/common.ts +++ b/src/lib/metro/common.ts @@ -1,7 +1,7 @@ import { find, findByProps } from "@metro/filters"; // Discord -export { constants } from "@lib/preinit"; +export const constants = findByProps("API_HOST"); export const channels = findByProps("getVoiceChannelId"); export const i18n = findByProps("Messages"); export const url = findByProps("openURL", "openDeeplink"); diff --git a/src/lib/preinit.ts b/src/lib/preinit.ts index 0fde06a..b05a109 100644 --- a/src/lib/preinit.ts +++ b/src/lib/preinit.ts @@ -12,12 +12,6 @@ window.React = basicFind("createElement") as typeof import("react"); // Export ReactNative export const ReactNative = basicFind("AppRegistry") as typeof import("react-native"); -// Export Discord's constants -export const constants = basicFind("AbortCodes"); - -// Export Discord's color module -export const color = basicFind("SemanticColor"); - // Export chroma.js export const chroma = basicFind("brewer") as typeof import("chroma-js"); diff --git a/src/lib/storage/backends.ts b/src/lib/storage/backends.ts index e36cb2c..40af37a 100644 --- a/src/lib/storage/backends.ts +++ b/src/lib/storage/backends.ts @@ -2,7 +2,8 @@ import { DCDFileManager, MMKVManager, StorageBackend } from "@types"; import { ReactNative as RN } from "@metro/common"; const MMKVManager = window.nativeModuleProxy.MMKVManager as MMKVManager; -const DCDFileManager = window.nativeModuleProxy.DCDFileManager as DCDFileManager; +//! 173.10 renamed this to RTNFileManager. +const DCDFileManager = (window.nativeModuleProxy.DCDFileManager ?? window.nativeModuleProxy.RTNFileManager) as DCDFileManager; export const createMMKVBackend = (store: string): StorageBackend => ({ get: async () => JSON.parse((await MMKVManager.getItem(store)) ?? "{}"), diff --git a/src/lib/themes.ts b/src/lib/themes.ts index c2d97d4..2a3c757 100644 --- a/src/lib/themes.ts +++ b/src/lib/themes.ts @@ -1,10 +1,14 @@ import { DCDFileManager, Indexable, Theme, ThemeData } from "@types"; +import { findByProps } from "@metro/filters"; import { ReactNative, chroma } from "@metro/common"; import { instead } from "@lib/patcher"; -import { color } from "@lib/preinit"; import { createFileBackend, createMMKVBackend, createStorage, wrapSync, awaitSyncWrapper } from "@lib/storage"; import { safeFetch } from "@utils"; +//! As of 173.10, early-finding this does not work. +// Somehow, this is late enough, though? +export const color = findByProps("SemanticColor"); + const DCDFileManager = window.nativeModuleProxy.DCDFileManager as DCDFileManager; export const themes = wrapSync(createStorage>(createMMKVBackend("VENDETTA_THEMES"))); diff --git a/src/ui/color.ts b/src/ui/color.ts index 76159cb..84dd916 100644 --- a/src/ui/color.ts +++ b/src/ui/color.ts @@ -1,17 +1,17 @@ -import { findByProps } from "@metro/filters"; import { constants } from "@metro/common"; +import { color } from "@lib/themes"; //! This module is only found on 165.0+, under the assumption that iOS 165.0 is the same as Android 165.0. //* In 167.1, most if not all traces of the old color modules were removed. //* In 168.6, Discord restructured EVERYTHING again. SemanticColor on this module no longer works when passed to a stylesheet. We must now use what you see below. -//? However, this is not all bad. The changes made in 168.6 do allow for better native-less theming. -const colorModule = findByProps("colors", "meta"); - -//* For both below, SemanticColor and RawColor are seemingly not used. Once again, what are Discord doing? +//* In 173.10, Discord restructured a lot of the app. These changes included making the color module impossible to early-find. +//? To stop duplication, it is now exported in our theming code. +//? These comments are preserved for historical purposes. +// const colorModule = findByProps("colors", "meta"); //? SemanticColor and default.colors are effectively ThemeColorMap -export const semanticColors = (constants.ThemeColorMap ?? colorModule?.colors); +export const semanticColors = (color?.default?.colors ?? constants?.ThemeColorMap); //? RawColor and default.unsafe_rawColors are effectively Colors //* Note that constants.Colors does still appear to exist on newer versions despite Discord not internally using it - what the fuck? -export const rawColors = (constants.Colors ?? colorModule?.unsafe_rawColors); \ No newline at end of file +export const rawColors = (color?.default?.unsafe_rawColors ?? constants?.Colors); \ No newline at end of file