fix: failsafe panel UI settings patching

This commit is contained in:
pylixonly 2025-01-11 19:41:18 +08:00
parent 78c303b5f5
commit 46a2c6eaa1

View file

@ -31,41 +31,47 @@ function SettingsSection() {
}
export function patchPanelUI(unpatches: (() => void | boolean)[]) {
unpatches.push(after("default", findByNameLazy("getScreens", false), (_a, screens) => ({
...screens,
VendettaCustomPage: {
title: "Bunny",
render: () => <CustomPageRenderer />
},
BUNNY_CUSTOM_PAGE: {
title: "Bunny",
render: () => <CustomPageRenderer />
}
})));
try {
unpatches.push(
after("default", findByNameLazy("getScreens", false), (_a, screens) => ({
...screens,
VendettaCustomPage: {
title: "Bunny",
render: () => <CustomPageRenderer />
},
BUNNY_CUSTOM_PAGE: {
title: "Bunny",
render: () => <CustomPageRenderer />
}
}))
);
const unpatch = after("default", findByNameLazy("UserSettingsOverviewWrapper", false), (_a, ret) => {
const UserSettingsOverview = findInReactTree(ret.props.children, n => n.type?.name === "UserSettingsOverview");
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 } }) => {
const index = children.findIndex((c: any) => c?.type?.name === "UploadLogsButton");
if (index !== -1) children.splice(index, 1);
}));
unpatches.push(after("renderSupportAndAcknowledgements", UserSettingsOverview.type.prototype, (_args, { props: { children } }) => {
const index = children.findIndex((c: any) => c?.type?.name === "UploadLogsButton");
if (index !== -1) children.splice(index, 1);
}));
unpatches.push(after("render", UserSettingsOverview.type.prototype, (_args, res) => {
const titles = [i18n.Messages.BILLING_SETTINGS, i18n.Messages.PREMIUM_SETTINGS];
unpatches.push(after("render", UserSettingsOverview.type.prototype, (_args, res) => {
const titles = [i18n.Messages.BILLING_SETTINGS, i18n.Messages.PREMIUM_SETTINGS];
const sections = findInReactTree(
res.props.children,
n => n?.children?.[1]?.type === LegacyFormSection
)?.children || res.props.children;
const sections = findInReactTree(
res.props.children,
n => n?.children?.[1]?.type === LegacyFormSection
)?.children || res.props.children;
if (sections) {
const index = sections.findIndex((c: any) => titles.includes(c?.props.label));
sections.splice(-~index || 4, 0, <SettingsSection />);
}
}));
}, true);
if (sections) {
const index = sections.findIndex((c: any) => titles.includes(c?.props.label));
sections.splice(-~index || 4, 0, <SettingsSection />);
}
}));
}, true);
unpatches.push(unpatch);
unpatches.push(unpatch);
} catch {
}
}