From 1179ca7bafdbf144ad94d918633f7931e33a8179 Mon Sep 17 00:00:00 2001 From: amsyarasyiq <82711525+amsyarasyiq@users.noreply.github.com> Date: Wed, 3 Apr 2024 01:50:13 +0800 Subject: [PATCH] [main] Hacky backwards compat :3 --- src/core/ui/settings/index.ts | 6 ++++ src/core/vendettaObject.ts | 30 ++++++++++++++----- src/lib/api/native/loader.ts | 10 ++++++- src/lib/managers/themes.ts | 2 +- src/lib/ui/color.ts | 2 +- .../discord/{Redesign.ts => Redesign.tsx} | 11 +++++-- src/lib/ui/settings/patches/tabs.tsx | 5 ++-- 7 files changed, 51 insertions(+), 15 deletions(-) rename src/lib/ui/components/discord/{Redesign.ts => Redesign.tsx} (87%) diff --git a/src/core/ui/settings/index.ts b/src/core/ui/settings/index.ts index 9b57cb6..918d83b 100644 --- a/src/core/ui/settings/index.ts +++ b/src/core/ui/settings/index.ts @@ -47,4 +47,10 @@ export default function initSettings() { } ] }); + + // Compat for plugins which injects into the settings + registerSection({ + name: "Vendetta", + items: [] + }); } diff --git a/src/core/vendettaObject.ts b/src/core/vendettaObject.ts index 8a66dae..72a9974 100644 --- a/src/core/vendettaObject.ts +++ b/src/core/vendettaObject.ts @@ -29,14 +29,28 @@ export const initVendettaObject = (): any => { modules: window.modules, find: (filter: (m: any) => boolean) => metro.find(filter), findAll: (filter: (m: any) => boolean) => metro.findAll(filter), - findByProps: (...props: any) => metro.findByProps(...props), + findByProps: (...props: any) => { + // TypingAvatars polyfill + if (props.length === 1 && props[0] === "KeyboardAwareScrollView") { + props.push("listenToKeyboardEvents"); + } + + return metro.findByProps(...props); + }, findByPropsAll: (...props: any) => metro.findByPropsAll(...props), - findByName: (name: string, defaultExp?: boolean | undefined) => metro.findByName(name, defaultExp), - findByNameAll: (name: string, defaultExp?: boolean | undefined) => metro.findByNameAll(name, defaultExp), - findByDisplayName: (displayName: string, defaultExp?: boolean | undefined) => metro.findByDisplayName(displayName, defaultExp), - findByDisplayNameAll: (displayName: string, defaultExp?: boolean | undefined) => metro.findByDisplayNameAll(displayName, defaultExp), - findByTypeName: (typeName: string, defaultExp?: boolean | undefined) => metro.findByTypeName(typeName, defaultExp), - findByTypeNameAll: (typeName: string, defaultExp?: boolean | undefined) => metro.findByTypeNameAll(typeName, defaultExp), + findByName: (name: string, defaultExp?: boolean | undefined) => { + // Decor polyfill + if (name === "create" && typeof defaultExp === "undefined") { + return metro.findByName("create", false).default; + } + + return metro.findByName(name, defaultExp ?? true); + }, + findByNameAll: (name: string, defaultExp: boolean = true) => metro.findByNameAll(name, defaultExp), + findByDisplayName: (displayName: string, defaultExp: boolean = true) => metro.findByDisplayName(displayName, defaultExp), + findByDisplayNameAll: (displayName: string, defaultExp: boolean = true) => metro.findByDisplayNameAll(displayName, defaultExp), + findByTypeName: (typeName: string, defaultExp: boolean = true) => metro.findByTypeName(typeName, defaultExp), + findByTypeNameAll: (typeName: string, defaultExp: boolean = true) => metro.findByTypeNameAll(typeName, defaultExp), findByStoreName: (name: string) => metro.findByStoreName(name), common: { constants: common.constants, @@ -79,7 +93,7 @@ export const initVendettaObject = (): any => { findInReactTree: (tree: { [key: string]: any; }, filter: any) => utils.findInReactTree(tree, filter), findInTree: (tree: any, filter: any, options: any) => utils.findInTree(tree, filter, options), safeFetch: (input: RequestInfo | URL, options?: RequestInit | undefined, timeout?: number | undefined) => utils.safeFetch(input, options, timeout), - unfreeze: (obj: object) => ({ ...obj }), + unfreeze: (obj: object) => Object.isFrozen(obj) ? ({ ...obj }) : obj, without: (object: any, ...keys: any) => utils.without(object, ...keys) }, debug: { diff --git a/src/lib/api/native/loader.ts b/src/lib/api/native/loader.ts index d43f461..05b8a66 100644 --- a/src/lib/api/native/loader.ts +++ b/src/lib/api/native/loader.ts @@ -52,7 +52,15 @@ function polyfillVendettaLoaderIdentity() { }; Object.defineProperty(globalThis, "__vendetta_theme", { - get: () => getStoredTheme(), + // get: () => getStoredTheme(), + get: () => { + // PyonXposed only returns keys it parses, making custom keys like Themes+' to gone + const id = getStoredTheme()?.id; + if (!id) return null; + + const { themes } = require("@lib/managers/themes"); + return themes[id] ?? getStoredTheme() ?? null; + }, configurable: true }); } diff --git a/src/lib/managers/themes.ts b/src/lib/managers/themes.ts index 14f9d4f..dd10409 100644 --- a/src/lib/managers/themes.ts +++ b/src/lib/managers/themes.ts @@ -42,7 +42,7 @@ export interface Theme { export const color = findByProps("SemanticColor"); const appearanceManager = findByProps("updateTheme"); -const mmkvStorage = findByProps("storage"); +const mmkvStorage = findByProps("storage")?.parseResolve ? findByProps("storage") : findByProps("impl").impl; const ThemeStore = findByStoreName("ThemeStore"); const formDividerModule = findByProps("DIVIDER_COLORS"); diff --git a/src/lib/ui/color.ts b/src/lib/ui/color.ts index 7765e91..81c9c34 100644 --- a/src/lib/ui/color.ts +++ b/src/lib/ui/color.ts @@ -18,7 +18,7 @@ export const semanticColors = (color?.default?.colors ?? constants?.ThemeColorMa export const rawColors = (color?.default?.unsafe_rawColors ?? constants?.Colors) as Record; const ThemeStore = findByStoreName("ThemeStore"); -const colorResolver = color.default.internal ??= color.default.meta; +const colorResolver = color.default.meta ??= color.default.internal; export function isSemanticColor(sym: any): boolean { return colorResolver.isSemanticColor(sym); diff --git a/src/lib/ui/components/discord/Redesign.ts b/src/lib/ui/components/discord/Redesign.tsx similarity index 87% rename from src/lib/ui/components/discord/Redesign.ts rename to src/lib/ui/components/discord/Redesign.tsx index 2b14e3b..5d23a4d 100644 --- a/src/lib/ui/components/discord/Redesign.ts +++ b/src/lib/ui/components/discord/Redesign.tsx @@ -1,5 +1,7 @@ import { find, findByProps } from "@lib/metro"; import { RedesignModuleKeys } from "@lib/ui/types"; +import { useEffect } from "react"; +import { View } from "react-native"; const findSingular = (prop: string) => find(m => m[prop] && Object.keys(m).length === 1)?.[prop]; @@ -10,6 +12,13 @@ export const CompatfulRedesign = findByProps("ActionSheetRow") as unknown as { [key: string]: any; }; +// Funny polyfill, hopefully same props :3 +CompatfulRedesign.ActionSheetTitleHeader ??= CompatfulRedesign.BottomSheetTitleHeader; +CompatfulRedesign.ActionSheetContentContainer ??= ({ children }: any) => { + useEffect(() => console.warn("Discord has removed 'ActionSheetContentContainer', please move into something else. It has been temporarily replaced with View"), []); + return {children}; +}; + export const FormSwitch = findSingular("FormSwitch"); export const FormRadio = findSingular("FormRadio"); export const FormCheckbox = findSingular("FormCheckbox"); @@ -111,12 +120,10 @@ export const { AccessibilityViewAnimated, ActionSheet, ActionSheetCloseButton, - ActionSheetContentContainer, ActionSheetIconHeader, ActionSheetPresenter, ActionSheetRow, ActionSheetSwitchRow, - ActionSheetTitleHeader, AnimatedEnterExitItem, BottomSheetTextInput, Dialog, diff --git a/src/lib/ui/settings/patches/tabs.tsx b/src/lib/ui/settings/patches/tabs.tsx index 9af415a..0fc167c 100644 --- a/src/lib/ui/settings/patches/tabs.tsx +++ b/src/lib/ui/settings/patches/tabs.tsx @@ -18,7 +18,7 @@ function useIsFirstRender() { export function patchTabsUI(unpatches: (() => void | boolean)[]) { settingConstants.SETTING_RENDERER_CONFIG.VendettaCustomPage = { type: "route", - title: () => "Bnuuy", + title: () => "Bunny", screen: { route: "VendettaCustomPage", getComponent: () => CustomPageRenderer @@ -29,7 +29,7 @@ export function patchTabsUI(unpatches: (() => void | boolean)[]) { .flatMap(sect => sect.map(row => ({ [row.key]: { type: "pressable", - title: row.title(), + title: row.title, icon: row.icon, usePredicate: row.usePredicate, onPress: wrapOnPress(row.onPress, null, row.render, row.title()), @@ -60,6 +60,7 @@ export function patchTabsUI(unpatches: (() => void | boolean)[]) { Object.keys(registeredSections).forEach(sect => { sections.splice(index++, 0, { label: sect, + title: sect, settings: registeredSections[sect].map(a => a.key) }); });