refactor(metro): rename find*Proxy -> find*Lazy

This commit is contained in:
amsyarasyiq 2024-07-20 10:48:49 +08:00
parent 820249b6b3
commit 06a852639f
20 changed files with 75 additions and 75 deletions

View file

@ -1,7 +1,7 @@
import { getProxyFactory } from "@lib/utils/lazy";
import { findByPropsProxy } from "@metro/utils";
import { findByPropsLazy } from "@metro/utils";
const jsxRuntime = findByPropsProxy("jsx", "jsxs", "Fragment");
const jsxRuntime = findByPropsLazy("jsx", "jsxs", "Fragment");
function unproxyFirstArg<T>(args: T[]) {
const factory = getProxyFactory(args[0]);

View file

@ -2,9 +2,9 @@ import { Strings } from "@core/i18n";
import { ApplicationCommand, ApplicationCommandOptionType } from "@lib/api/commands/types";
import { settings } from "@lib/settings";
import { messageUtil } from "@metro/common";
import { findByPropsProxy } from "@metro/utils";
import { findByPropsLazy } from "@metro/utils";
const util = findByPropsProxy("inspect");
const util = findByPropsLazy("inspect");
const AsyncFunction = (async () => void 0).constructor;
const ZERO_WIDTH_SPACE_CHARACTER = "\u200B";

View file

@ -1,10 +1,10 @@
import { FluxDispatcher } from "@metro/common";
import { findByNameProxy } from "@metro/utils";
import { findByNameLazy } from "@metro/utils";
import { PrimitiveType } from "intl-messageformat";
import langDefault from "./default.json";
const IntlMessageFormat = findByNameProxy("MessageFormat") as typeof import("intl-messageformat").default;
const IntlMessageFormat = findByNameLazy("MessageFormat") as typeof import("intl-messageformat").default;
type I18nKey = keyof typeof langDefault;

View file

@ -8,7 +8,7 @@ import { installTheme, removeTheme, themes } from "@lib/managers/themes";
import { DISCORD_SERVER_ID, HTTP_REGEX_MULTI, PLUGINS_CHANNEL_ID, THEMES_CHANNEL_ID, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { lazyDestructure } from "@lib/utils/lazy";
import { Button } from "@metro/common/components";
import { findByProps, findByPropsProxy } from "@metro/utils";
import { findByProps, findByPropsLazy } from "@metro/utils";
import { ErrorBoundary } from "@ui/components";
import { showToast } from "@ui/toasts";
@ -17,7 +17,7 @@ type PostType = "Plugin" | "Theme";
// const ForumPostLongPressActionSheet = findByNameProxy("ForumPostLongPressActionSheet", false);
// const { ActionSheetRow } = findByPropsProxy("ActionSheetRow");
const { useFirstForumPostMessage } = lazyDestructure(() => findByProps("useFirstForumPostMessage"));
const forumReactions = findByPropsProxy("MostCommonForumPostReaction");
const forumReactions = findByPropsLazy("MostCommonForumPostReaction");
const postMap = {
Plugin: {

View file

@ -9,12 +9,12 @@ import { lazyDestructure } from "@lib/utils/lazy";
import { channels, url } from "@metro/common";
import { byMutableProp } from "@metro/filters";
import { findExports } from "@metro/finders";
import { findByProps, findByPropsProxy } from "@metro/utils";
import { findByProps, findByPropsLazy } from "@metro/utils";
import { showConfirmationAlert } from "@ui/alerts";
import { showToast } from "@ui/toasts";
const showSimpleActionSheet = findExports(byMutableProp("showSimpleActionSheet"));
const handleClick = findByPropsProxy("handleClick");
const handleClick = findByPropsLazy("handleClick");
const { openURL } = lazyDestructure(() => url);
const { getChannelId } = lazyDestructure(() => channels);
const { getChannel } = lazyDestructure(() => findByProps("getChannel"));

View file

@ -6,12 +6,12 @@ import { getCurrentTheme } from "@lib/managers/themes";
import { safeFetch } from "@lib/utils";
import { NavigationNative } from "@metro/common";
import { ActionSheet, BottomSheetTitleHeader, Button, IconButton, Stack, TableRow, TableRowGroup, Text, TextInput } from "@metro/common/components";
import { findByPropsProxy } from "@metro/utils";
import { findByPropsLazy } from "@metro/utils";
import { ErrorBoundary } from "@ui/components";
import { useMemo, useRef, useState } from "react";
import { ScrollView, View } from "react-native";
const actionSheet = findByPropsProxy("hideActionSheet");
const actionSheet = findByPropsLazy("hideActionSheet");
function guessFontName(urls: string[]) {
const fileNames = urls.map(url => {

View file

@ -13,7 +13,7 @@ import { Author } from "@lib/utils/types";
import { chroma } from "@metro/common";
import { byMutableProp } from "@metro/filters";
import { createLazyModule } from "@metro/lazy";
import { findByNameProxy, findByProps, findByPropsProxy, findByStoreNameProxy } from "@metro/utils";
import { findByNameLazy, findByProps, findByPropsLazy, findByStoreNameLazy } from "@metro/utils";
import { ImageBackground, Platform, processColor } from "react-native";
export interface ThemeData {
@ -42,7 +42,7 @@ export interface Theme {
//! As of 173.10, early-finding this does not work.
// Somehow, this is late enough, though?
export const color = findByPropsProxy("SemanticColor");
export const color = findByPropsLazy("SemanticColor");
const mmkvStorage = proxyLazy(() => {
const newModule = findByProps("impl");
@ -50,10 +50,10 @@ const mmkvStorage = proxyLazy(() => {
return findByProps("storage");
});
const appearanceManager = findByPropsProxy("updateTheme");
const ThemeStore = findByStoreNameProxy("ThemeStore");
const formDividerModule = findByPropsProxy("DIVIDER_COLORS");
const MessagesWrapperConnected = findByNameProxy("MessagesWrapperConnected", false);
const appearanceManager = findByPropsLazy("updateTheme");
const ThemeStore = findByStoreNameLazy("ThemeStore");
const formDividerModule = findByPropsLazy("DIVIDER_COLORS");
const MessagesWrapperConnected = findByNameLazy("MessagesWrapperConnected", false);
const { MessagesWrapper } = lazyDestructure(() => findByProps("MessagesWrapper"));
const isThemeModule = createLazyModule(byMutableProp("isThemeDark"));

View file

@ -1,8 +1,8 @@
import { ButtonColors } from "@lib/utils/types";
import { findByPropsProxy } from "@metro/utils";
import { findByPropsLazy } from "@metro/utils";
import InputAlert, { InputAlertProps } from "@ui/components/InputAlert";
const Alerts = findByPropsProxy("openLazy", "close");
const Alerts = findByPropsLazy("openLazy", "close");
interface InternalConfirmationAlertOptions extends Omit<ConfirmationAlertOptions, "content"> {
content?: ConfirmationAlertOptions["content"];

View file

@ -1,6 +1,6 @@
import { color } from "@lib/managers/themes";
import { constants } from "@metro/common";
import { findByStoreNameProxy } from "@metro/utils";
import { findByStoreNameLazy } from "@metro/utils";
//! 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.
@ -17,7 +17,7 @@ export const semanticColors = (color?.default?.colors ?? constants?.ThemeColorMa
//* Note that constants.Colors does still appear to exist on newer versions despite Discord not internally using it - what the fuck?
export const rawColors = (color?.default?.unsafe_rawColors ?? constants?.Colors) as Record<string, string>;
const ThemeStore = findByStoreNameProxy("ThemeStore");
const ThemeStore = findByStoreNameLazy("ThemeStore");
const colorResolver = color.default.meta ??= color.default.internal;
export function isSemanticColor(sym: any): boolean {

View file

@ -1,8 +1,8 @@
import { ButtonColors } from "@lib/utils/types";
import { LegacyAlert, LegacyFormInput } from "@metro/common/components";
import { findByPropsProxy } from "@metro/utils";
import { findByPropsLazy } from "@metro/utils";
const Alerts = findByPropsProxy("openLazy", "close");
const Alerts = findByPropsLazy("openLazy", "close");
export interface InputAlertProps {
title?: string;

View file

@ -7,13 +7,13 @@ import { lazyDestructure } from "@lib/utils/lazy";
import { ButtonColors } from "@lib/utils/types";
import { Button, CompatButton, SafeAreaView } from "@metro/common/components";
import { _lazyContextSymbol, LazyModuleContext } from "@metro/lazy";
import { findByNameProxy, findByProps } from "@metro/utils";
import { findByNameLazy, findByProps } from "@metro/utils";
import { semanticColors } from "@ui/color";
import { Codeblock, ErrorBoundary as _ErrorBoundary } from "@ui/components";
import { createThemedStyleSheet, TextStyleSheet } from "@ui/styles";
import { Text, View } from "react-native";
const ErrorBoundary = findByNameProxy("ErrorBoundary");
const ErrorBoundary = findByNameLazy("ErrorBoundary");
// Let's just pray they have this.
const { BadgableTabBar } = lazyDestructure(() => findByProps("BadgableTabBar"));
@ -70,7 +70,7 @@ const tabs: Tab[] = [
];
function getErrorBoundaryContext() {
const ctxt: LazyModuleContext = findByNameProxy("ErrorBoundary")[_lazyContextSymbol];
const ctxt: LazyModuleContext = findByNameLazy("ErrorBoundary")[_lazyContextSymbol];
return new Promise(resolve => {
ctxt.getExports(exp => {
resolve(exp.prototype);

View file

@ -2,7 +2,7 @@ import { after } from "@lib/api/patcher";
import { findInReactTree } from "@lib/utils";
import { i18n, NavigationNative } from "@metro/common";
import { LegacyFormIcon, LegacyFormRow, LegacyFormSection } from "@metro/common/components";
import { findByNameProxy } from "@metro/utils";
import { findByNameLazy } from "@metro/utils";
import { registeredSections } from "@ui/settings";
import { CustomPageRenderer, wrapOnPress } from "./shared";
@ -28,7 +28,7 @@ function SettingsSection() {
}
export function patchPanelUI(unpatches: (() => void | boolean)[]) {
unpatches.push(after("default", findByNameProxy("getScreens", false), (_a, screens) => ({
unpatches.push(after("default", findByNameLazy("getScreens", false), (_a, screens) => ({
...screens,
VendettaCustomPage: {
title: "Bnuuy",
@ -36,7 +36,7 @@ export function patchPanelUI(unpatches: (() => void | boolean)[]) {
}
})));
const unpatch = after("default", findByNameProxy("UserSettingsOverviewWrapper", false), (_a, ret) => {
const unpatch = after("default", findByNameLazy("UserSettingsOverviewWrapper", false), (_a, ret) => {
const UserSettingsOverview = findInReactTree(ret.props.children, n => n.type?.name === "UserSettingsOverview");
unpatches.push(after("renderSupportAndAcknowledgements", UserSettingsOverview.type.prototype, (_args, { props: { children } }) => {

View file

@ -1,9 +1,9 @@
import { NavigationNative } from "@metro/common";
import { findByPropsProxy } from "@metro/utils";
import { findByPropsLazy } from "@metro/utils";
import { ErrorBoundary } from "@ui/components";
import { RowConfig } from "@ui/settings";
const tabsNavigationRef = findByPropsProxy("getRootNavigationRef");
const tabsNavigationRef = findByPropsLazy("getRootNavigationRef");
export const CustomPageRenderer = React.memo(() => {
const navigation = NavigationNative.useNavigation();

View file

@ -1,13 +1,13 @@
import { after } from "@lib/api/patcher";
import { findInReactTree } from "@lib/utils";
import { i18n } from "@metro/common";
import { findByNameProxy, findByPropsProxy } from "@metro/utils";
import { findByNameLazy, findByPropsLazy } from "@metro/utils";
import { registeredSections } from "@ui/settings";
import { CustomPageRenderer, wrapOnPress } from "./shared";
const settingConstants = findByPropsProxy("SETTING_RENDERER_CONFIG");
const SettingsOverviewScreen = findByNameProxy("SettingsOverviewScreen", false);
const settingConstants = findByPropsLazy("SETTING_RENDERER_CONFIG");
const SettingsOverviewScreen = findByNameLazy("SettingsOverviewScreen", false);
function useIsFirstRender() {
let firstRender = false;

View file

@ -1,6 +1,6 @@
import { findByPropsProxy } from "@metro/utils";
import { findByPropsLazy } from "@metro/utils";
const actionSheet = findByPropsProxy("openLazy", "hideActionSheet");
const actionSheet = findByPropsLazy("openLazy", "hideActionSheet");
export function showSheet<T extends React.ComponentType<any>>(
key: string,

View file

@ -1,12 +1,12 @@
import { lazyDestructure, proxyLazy } from "@lib/utils/lazy";
import { findByProps, findByPropsProxy } from "@metro/utils";
import { findByProps, findByPropsLazy } from "@metro/utils";
import { isSemanticColor, resolveSemanticColor } from "@ui/color";
import { DiscordTextStyles } from "@ui/types";
import { ImageStyle, StyleSheet, TextStyle, ViewStyle } from "react-native";
type NamedStyles<T> = { [P in keyof T]: ViewStyle | TextStyle | ImageStyle };
const CompatfulRedesign = findByPropsProxy("createStyles");
const CompatfulRedesign = findByPropsLazy("createStyles");
export const { TextStyleSheet } = lazyDestructure(() => findByProps("TextStyleSheet")) as unknown as {
TextStyleSheet: { [key in DiscordTextStyles]: TextStyle; };

View file

@ -1,4 +1,4 @@
import { findByNameProxy } from "@metro/utils";
import { findByNameLazy } from "@metro/utils";
export type LoggerFunction = (...messages: any[]) => void;
export interface Logger {
@ -11,5 +11,5 @@ export interface Logger {
verbose: LoggerFunction;
}
export const DiscordLogger = findByNameProxy("Logger");
export const DiscordLogger = findByNameLazy("Logger");
export const logger: Logger = new DiscordLogger("Bunny");

View file

@ -1,7 +1,7 @@
/* eslint-disable prefer-destructuring */
import { lazyDestructure, proxyLazy } from "@lib/utils/lazy";
import { findExports } from "@metro/finders";
import { createFilterDefinition, findByDisplayNameProxy, findByNameProxy, findByProps, findByPropsProxy } from "@metro/utils";
import { createFilterDefinition, findByDisplayNameLazy, findByNameLazy, findByProps, findByPropsLazy } from "@metro/utils";
import * as t from "./types/components";
@ -14,9 +14,9 @@ const findSingular = (prop: string) => proxyLazy(() => findExports(bySingularPro
const findProp = (prop: string) => proxyLazy(() => findByProps(prop)[prop]);
// Discord
export const LegacyAlert = findByDisplayNameProxy("FluxContainer(Alert)");
export const CompatButton = findByPropsProxy("Looks", "Colors", "Sizes");
export const HelpMessage = findByNameProxy("HelpMessage");
export const LegacyAlert = findByDisplayNameLazy("FluxContainer(Alert)");
export const CompatButton = findByPropsLazy("Looks", "Colors", "Sizes");
export const HelpMessage = findByNameLazy("HelpMessage");
// React Native's included SafeAreaView only adds padding on iOS.
export const SafeAreaView = proxyLazy(() => findByProps("useSafeAreaInsets").SafeAreaView);
@ -64,10 +64,10 @@ export const FloatingActionButton = findProp("FloatingActionButton") as t.Floati
export const ActionSheet = findProp("ActionSheet") as t.ActionSheet;
export const BottomSheetTitleHeader = findProp("BottomSheetTitleHeader");
const textsModule = findByPropsProxy("Text", "LegacyText");
const textsModule = findByPropsLazy("Text", "LegacyText");
export const Text = proxyLazy(() => textsModule.Text) as t.Text;
export const Forms = findByPropsProxy("Form", "FormSection");
export const Forms = findByPropsLazy("Form", "FormSection");
export const {
Form: LegacyForm,

View file

@ -1,44 +1,44 @@
import { proxyLazy } from "@lib/utils/lazy";
import { Dispatcher } from "@metro/types";
import { findByFilePath, findByProps, findByPropsProxy } from "@metro/utils";
import { findByFilePath, findByProps, findByPropsLazy } from "@metro/utils";
// Discord
export const constants = findByPropsProxy("Fonts", "Permissions");
export const channels = findByPropsProxy("getVoiceChannelId");
export const i18n = findByPropsProxy("Messages");
export const url = findByPropsProxy("openURL", "openDeeplink");
export const clipboard = findByPropsProxy("setString", "getString", "hasString") as typeof import("@react-native-clipboard/clipboard").default;
export const assets = findByPropsProxy("registerAsset");
export const invites = findByPropsProxy("acceptInviteAndTransitionToInviteChannel");
export const commands = findByPropsProxy("getBuiltInCommands");
export const navigation = findByPropsProxy("pushLazy");
export const constants = findByPropsLazy("Fonts", "Permissions");
export const channels = findByPropsLazy("getVoiceChannelId");
export const i18n = findByPropsLazy("Messages");
export const url = findByPropsLazy("openURL", "openDeeplink");
export const clipboard = findByPropsLazy("setString", "getString", "hasString") as typeof import("@react-native-clipboard/clipboard").default;
export const assets = findByPropsLazy("registerAsset");
export const invites = findByPropsLazy("acceptInviteAndTransitionToInviteChannel");
export const commands = findByPropsLazy("getBuiltInCommands");
export const navigation = findByPropsLazy("pushLazy");
export const toasts = proxyLazy(() => findByFilePath("modules/toast/native/ToastActionCreators.tsx").default);
export const messageUtil = findByPropsProxy("sendBotMessage");
export const navigationStack = findByPropsProxy("createStackNavigator");
export const NavigationNative = findByPropsProxy("NavigationContainer");
export const tokens = findByPropsProxy("colors", "unsafe_rawColors");
export const messageUtil = findByPropsLazy("sendBotMessage");
export const navigationStack = findByPropsLazy("createStackNavigator");
export const NavigationNative = findByPropsLazy("NavigationContainer");
export const tokens = findByPropsLazy("colors", "unsafe_rawColors");
// Flux
export const Flux = findByPropsProxy("connectStores");
export const Flux = findByPropsLazy("connectStores");
// TODO: Making this a proxy/lazy fuck things up for some reason
export const FluxDispatcher = findByProps("_interceptors") as Dispatcher;
// React
export const React = window.React = findByPropsProxy("createElement") as typeof import("react");
export const ReactNative = window.ReactNative = findByPropsProxy("AppRegistry") as typeof import("react-native");
export const React = window.React = findByPropsLazy("createElement") as typeof import("react");
export const ReactNative = window.ReactNative = findByPropsLazy("AppRegistry") as typeof import("react-native");
// Moment
export const moment = findByPropsProxy("isMoment") as typeof import("moment");
export const moment = findByPropsLazy("isMoment") as typeof import("moment");
// chroma.js
export const chroma = findByPropsProxy("brewer") as typeof import("chroma-js");
export const chroma = findByPropsLazy("brewer") as typeof import("chroma-js");
// Lodash
export const lodash = findByPropsProxy("forEachRight") as typeof import("lodash");
export const lodash = findByPropsLazy("forEachRight") as typeof import("lodash");
// Skia
export const Skia = findByPropsProxy("useFont") as typeof import("@shopify/react-native-skia");
export const Skia = findByPropsLazy("useFont") as typeof import("@shopify/react-native-skia");
// The node:util polyfill for RN
// TODO: Find types for this
export const util = findByPropsProxy("inspect", "isNullOrUndefined");
export const util = findByPropsLazy("inspect", "isNullOrUndefined");

View file

@ -42,24 +42,24 @@ export function createSimpleFilter(
}
export const findByProps = (...props: string[]) => findExports(byProps(...props));
export const findByPropsProxy = (...props: string[]) => createLazyModule(byProps(...props));
export const findByPropsLazy = (...props: string[]) => createLazyModule(byProps(...props));
export const findByPropsAll = (...props: string[]) => findAllExports(byProps(...props));
export const findByName = (name: string, expDefault = true) => findExports(expDefault ? byName(name) : byName.byRaw(name));
export const findByNameProxy = (name: string, expDefault = true) => createLazyModule(expDefault ? byName(name) : byName.byRaw(name));
export const findByNameLazy = (name: string, expDefault = true) => createLazyModule(expDefault ? byName(name) : byName.byRaw(name));
export const findByNameAll = (name: string, expDefault = true) => findAllExports(expDefault ? byName(name) : byName.byRaw(name));
export const findByDisplayName = (name: string, expDefault = true) => findExports(expDefault ? byDisplayName(name) : byDisplayName.byRaw(name));
export const findByDisplayNameProxy = (name: string, expDefault = true) => createLazyModule(expDefault ? byDisplayName(name) : byDisplayName.byRaw(name));
export const findByDisplayNameLazy = (name: string, expDefault = true) => createLazyModule(expDefault ? byDisplayName(name) : byDisplayName.byRaw(name));
export const findByDisplayNameAll = (name: string, expDefault = true) => findAllExports(expDefault ? byDisplayName(name) : byDisplayName.byRaw(name));
export const findByTypeName = (name: string, expDefault = true) => findExports(expDefault ? byTypeName(name) : byTypeName.byRaw(name));
export const findByTypeNameProxy = (name: string, expDefault = true) => createLazyModule(expDefault ? byTypeName(name) : byTypeName.byRaw(name));
export const findByTypeNameLazy = (name: string, expDefault = true) => createLazyModule(expDefault ? byTypeName(name) : byTypeName.byRaw(name));
export const findByTypeNameAll = (name: string, expDefault = true) => findAllExports(expDefault ? byTypeName(name) : byTypeName.byRaw(name));
export const findByStoreName = (name: string) => findExports(byStoreName(name));
export const findByStoreNameProxy = (name: string) => createLazyModule(byStoreName(name));
export const findByStoreNameLazy = (name: string) => createLazyModule(byStoreName(name));
export const findByFilePath = (path: string) => findExports(byFilePath(path));
export const findByFilePathProxy = (path: string) => createLazyModule(byFilePath(path));
export const findByFilePathLazy = (path: string) => createLazyModule(byFilePath(path));