fix(ui): unlazify FluxDispatcher, repair patchTabsUI

This commit is contained in:
amsyarasyiq 2024-05-23 03:09:10 +08:00
parent de79efe1dd
commit b0acf895e4
2 changed files with 29 additions and 18 deletions

View file

@ -16,15 +16,6 @@ function useIsFirstRender() {
}
export function patchTabsUI(unpatches: (() => void | boolean)[]) {
settingConstants.SETTING_RENDERER_CONFIG.VendettaCustomPage = {
type: "route",
title: () => "Bunny",
screen: {
route: "VendettaCustomPage",
getComponent: () => CustomPageRenderer
}
};
const getRows = () => Object.values(registeredSections)
.flatMap(sect => sect.map(row => ({
[row.key]: {
@ -40,15 +31,33 @@ export function patchTabsUI(unpatches: (() => void | boolean)[]) {
.reduce((a, c) => Object.assign(a, c));
const origRendererConfig = settingConstants.SETTING_RENDERER_CONFIG;
settingConstants.SETTING_RENDERER_CONFIG = new Proxy(origRendererConfig, {
get: (target, prop: string, reciever) => Reflect.get({ ...target, ...getRows() }, prop, reciever),
getOwnPropertyDescriptor: (target, prop: string) => Reflect.getOwnPropertyDescriptor({ ...target, ...getRows() }, prop),
ownKeys: target => [...Reflect.ownKeys(target), ...Object.keys(getRows())]
let rendererConfigValue = settingConstants.SETTING_RENDERER_CONFIG;
Object.defineProperty(settingConstants, "SETTING_RENDERER_CONFIG", {
enumerable: true,
configurable: true,
get: () => ({
...rendererConfigValue,
VendettaCustomPage: {
type: "route",
title: () => "Bunny",
screen: {
route: "VendettaCustomPage",
getComponent: () => CustomPageRenderer
}
},
...getRows()
}),
set: v => rendererConfigValue = v,
});
unpatches.push(() => {
settingConstants.SETTING_RENDERER_CONFIG = origRendererConfig;
delete settingConstants.SETTING_RENDERER_CONFIG.VendettaCustomPage;
Object.defineProperty(settingConstants, "SETTING_RENDERER_CONFIG", {
value: origRendererConfig,
writable: true,
get: undefined,
set: undefined
});
});
unpatches.push(after("default", SettingsOverviewScreen, (_, ret) => {

View file

@ -1,5 +1,6 @@
import { proxyLazy } from "@lib/utils/lazy";
import { Dispatcher } from "@metro/types";
import { findByFilePathProxy, findByPropsProxy } from "@metro/utils";
import { findByFilePath, findByProps, findByPropsProxy } from "@metro/utils";
// Discord
export const constants = findByPropsProxy("Fonts", "Permissions");
@ -11,14 +12,15 @@ export const assets = findByPropsProxy("registerAsset");
export const invites = findByPropsProxy("acceptInviteAndTransitionToInviteChannel");
export const commands = findByPropsProxy("getBuiltInCommands");
export const navigation = findByPropsProxy("pushLazy");
export const toasts = findByFilePathProxy("modules/toast/native/ToastActionCreators.tsx").default;
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");
// Flux
export const Flux = findByPropsProxy("connectStores");
export const FluxDispatcher = findByPropsProxy("_interceptors") as Dispatcher;
// 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");