Skip to content

Commit

Permalink
fix: failsafe panel UI settings patching
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Jan 14, 2025
1 parent 78c303b commit 46a2c6e
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions src/lib/ui/settings/patches/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

}
}

0 comments on commit 46a2c6e

Please sign in to comment.