Skip to content

Commit

Permalink
[main] Hacky backwards compat :3
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Apr 2, 2024
1 parent 7d77a34 commit 1179ca7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/core/ui/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ export default function initSettings() {
}
]
});

// Compat for plugins which injects into the settings
registerSection({
name: "Vendetta",
items: []
});
}
30 changes: 22 additions & 8 deletions src/core/vendettaObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down
10 changes: 9 additions & 1 deletion src/lib/api/native/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/managers/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion src/lib/ui/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const semanticColors = (color?.default?.colors ?? constants?.ThemeColorMa
export const rawColors = (color?.default?.unsafe_rawColors ?? constants?.Colors) as Record<string, string>;

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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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];

Expand All @@ -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 <View>{children}</View>;
};

export const FormSwitch = findSingular("FormSwitch");
export const FormRadio = findSingular("FormRadio");
export const FormCheckbox = findSingular("FormCheckbox");
Expand Down Expand Up @@ -111,12 +120,10 @@ export const {
AccessibilityViewAnimated,
ActionSheet,
ActionSheetCloseButton,
ActionSheetContentContainer,
ActionSheetIconHeader,
ActionSheetPresenter,
ActionSheetRow,
ActionSheetSwitchRow,
ActionSheetTitleHeader,
AnimatedEnterExitItem,
BottomSheetTextInput,
Dialog,
Expand Down
5 changes: 3 additions & 2 deletions src/lib/ui/settings/patches/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()),
Expand Down Expand Up @@ -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)
});
});
Expand Down

0 comments on commit 1179ca7

Please sign in to comment.