Merge pull request #8 from tralwdwd/master
Some checks failed
Build and deploy / deploy (push) Failing after 52s

fix: crash when opening settings
Merged.
This commit is contained in:
Win8.1VMUser 2026-06-03 07:04:37 +02:00 • committed by GitHub
commit b01130e837
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,8 +14,13 @@ const { TableRowIcon } = findByProps("TableRowIcon");
const bunny = window.bunny;
const tabsNavigationRef = bunny?.metro?.findByPropsLazy("getRootNavigationRef");
const settingConstants = bunny?.metro?.findByPropsLazy("SETTING_RENDERER_CONFIG");
const SettingsOverviewScreen = bunny?.metro?.findByNameLazy("SettingsOverviewScreen", false);
const settingConstants = bunny?.metro?.findByPropsLazy(
"SETTING_RENDERER_CONFIG",
);
const SettingsOverviewScreen = bunny?.metro?.findByNameLazy(
"SettingsOverviewScreen",
false,
);
const createListModule = bunny.metro.findByPropsLazy("createList");
function Section({ tabs }) {
@ -26,15 +31,15 @@ function Section({ tabs }) {
leading: React.createElement(FormRow.Icon, { source: tabs.icon }),
trailing: React.createElement(React.Fragment, {}, [
tabs.trailing ? tabs.trailing() : null,
React.createElement(FormRow.Arrow, { key: "arrow" })
React.createElement(FormRow.Arrow, { key: "arrow" }),
]),
onPress: () => {
const Component = tabs.page;
navigation.navigate("VendettaCustomPage", {
title: tabs.title(),
render: () => React.createElement(Component)
render: () => React.createElement(Component),
});
}
},
});
}
@ -43,11 +48,14 @@ function patchPanelUI(tabs, patches) {
patches.push(
after(
"default",
bunny?.metro?.findByNameLazy("UserSettingsOverviewWrapper", false),
bunny?.metro?.findByNameLazy(
"UserSettingsOverviewWrapper",
false,
),
(_, ret) => {
const UserSettingsOverview = findInReactTree(
ret.props.children,
n => n.type?.name === "UserSettingsOverview"
(n) => n.type?.name === "UserSettingsOverview",
);
if (UserSettingsOverview) {
@ -58,27 +66,35 @@ function patchPanelUI(tabs, patches) {
(_args, res) => {
const sections = findInReactTree(
res.props.children,
n => n?.children?.[1]?.type === FormSection
(n) =>
n?.children?.[1]?.type ===
FormSection,
)?.children;
if (sections) {
const index = sections.findIndex((c) =>
["BILLING_SETTINGS", "PREMIUM_SETTINGS"].includes(c?.props?.label)
[
"BILLING_SETTINGS",
"PREMIUM_SETTINGS",
].includes(c?.props?.label),
);
sections.splice(
-~index || 4,
0,
React.createElement(Section, { key: tabs.key, tabs })
);
}
}
)
React.createElement(Section, {
key: tabs.key,
tabs,
}),
);
}
},
true
)
),
);
}
},
true,
),
);
} catch (error) {
logger.info("Panel UI patch failed graciously 💔", error);
@ -87,7 +103,9 @@ function patchPanelUI(tabs, patches) {
function patchTabsUI(tabs, patches) {
if (!settingConstants || !SettingsOverviewScreen || !tabsNavigationRef) {
console.warn("[AccountSwitcher] Missing required constants for tabs UI patch");
console.warn(
"[AccountSwitcher] Missing required constants for tabs UI patch",
);
return;
}
@ -95,12 +113,18 @@ function patchTabsUI(tabs, patches) {
row[tabs.key] = {
type: "pressable",
title: tabs.title,
useTitle: tabs.title,
icon: tabs.icon,
IconComponent: tabs.icon && (() => {
const actualIconSource = (typeof tabs.icon === 'object' && tabs.icon.uri !== undefined)
IconComponent:
tabs.icon &&
(() => {
const actualIconSource =
typeof tabs.icon === "object" && tabs.icon.uri !== undefined
? tabs.icon.uri
: tabs.icon;
return React.createElement(TableRowIcon, { source: actualIconSource });
return React.createElement(TableRowIcon, {
source: actualIconSource,
});
}),
usePredicate: tabs.predicate,
useTrailing: tabs.trailing,
@ -110,7 +134,7 @@ function patchTabsUI(tabs, patches) {
navigation.navigate("VendettaCustomPage", {
title: tabs.title(),
render: () => React.createElement(Component)
render: () => React.createElement(Component),
});
},
withArrow: true,
@ -125,7 +149,7 @@ function patchTabsUI(tabs, patches) {
...rendererConfigValue,
...row,
}),
set: v => (rendererConfigValue = v),
set: (v) => (rendererConfigValue = v),
});
const firstRender = Symbol("AccountSwitcher-pinToSettings");
@ -142,23 +166,23 @@ function patchTabsUI(tabs, patches) {
const sections = config.sections;
const section = sections?.find((x) =>
["Bunny", "Kettu", "Revenge"].includes(x?.label)
["Bunny", "Kettu", "Revenge"].includes(x?.label),
);
// If unable to find a section
if (!section) {
const isMainSettings = Boolean(
sections?.find((x) =>
x.settings.includes("ACCOUNT")
)
)
x.settings.includes("ACCOUNT"),
),
);
if (isMainSettings) {
// Add a new section to the top
sections.unshift({
label: manifest.name,
title: manifest.name,
settings: [tabs.key]
settings: [tabs.key],
});
}
}
@ -167,8 +191,8 @@ function patchTabsUI(tabs, patches) {
section.settings = [...section.settings, tabs.key];
}
}
})
)
}),
);
} catch {
patches.push(
after("default", SettingsOverviewScreen, (args, ret) => {
@ -177,27 +201,27 @@ function patchTabsUI(tabs, patches) {
const { sections } = findInReactTree(
ret,
i => i.props?.sections,
(i) => i.props?.sections,
).props;
const section = sections?.find((x) =>
["Bunny", "Kettu", "Revenge"].includes(x?.label)
["Bunny", "Kettu", "Revenge"].includes(x?.label),
);
// If unable to find a section
if (!section) {
const isMainSettings = Boolean(
sections?.find((x) =>
x.settings.includes("ACCOUNT")
)
)
x.settings.includes("ACCOUNT"),
),
);
if (isMainSettings) {
// Add a new section to the top
sections.unshift({
label: manifest.name,
title: manifest.name,
settings: [tabs.key]
settings: [tabs.key],
});
}
}
@ -206,7 +230,7 @@ function patchTabsUI(tabs, patches) {
section.settings = [...section.settings, tabs.key];
}
}
})
}),
);
}
}
@ -236,7 +260,9 @@ export default function patchSidebar() {
return () => {};
}
console.log("[AccountSwitcher] Patching sidebar using custom patchSettingsPin...");
console.log(
"[AccountSwitcher] Patching sidebar using custom patchSettingsPin...",
);
try {
const unpatch = patchSettingsPin({
@ -249,7 +275,6 @@ export default function patchSidebar() {
console.log("[AccountSwitcher] Successfully patched sidebar");
return unpatch;
} catch (error) {
console.error("[AccountSwitcher] Failed to patch sidebar:", error);
return () => {};