2025-12-07 20:10:01 +00:00
|
|
|
import { storage, manifest } from "@vendetta/plugin";
|
2025-08-17 22:35:01 +02:00
|
|
|
import { React, NavigationNative } from "@vendetta/metro/common";
|
|
|
|
|
import { getAssetIDByName } from "@vendetta/ui/assets";
|
|
|
|
|
import { after } from "@vendetta/patcher";
|
|
|
|
|
import { Forms } from "@vendetta/ui/components";
|
|
|
|
|
import { findInReactTree } from "@vendetta/utils";
|
|
|
|
|
import { findByProps } from "@vendetta/metro";
|
|
|
|
|
import { logger } from "@vendetta";
|
2025-08-19 08:35:21 +02:00
|
|
|
import AccountSwitcherSettings from "./Settings";
|
2025-08-17 22:35:01 +02:00
|
|
|
|
|
|
|
|
const { FormSection, FormRow } = Forms;
|
|
|
|
|
const { TableRowIcon } = findByProps("TableRowIcon");
|
|
|
|
|
|
|
|
|
|
const bunny = window.bunny;
|
|
|
|
|
|
|
|
|
|
const tabsNavigationRef = bunny?.metro?.findByPropsLazy("getRootNavigationRef");
|
2026-05-30 19:07:44 +01:00
|
|
|
const settingConstants = bunny?.metro?.findByPropsLazy(
|
|
|
|
|
"SETTING_RENDERER_CONFIG",
|
|
|
|
|
);
|
|
|
|
|
const SettingsOverviewScreen = bunny?.metro?.findByNameLazy(
|
|
|
|
|
"SettingsOverviewScreen",
|
|
|
|
|
false,
|
|
|
|
|
);
|
2025-12-07 20:10:01 +00:00
|
|
|
const createListModule = bunny.metro.findByPropsLazy("createList");
|
2025-08-17 22:35:01 +02:00
|
|
|
|
|
|
|
|
function Section({ tabs }) {
|
|
|
|
|
const navigation = NavigationNative.useNavigation();
|
|
|
|
|
|
|
|
|
|
return React.createElement(FormRow, {
|
|
|
|
|
label: tabs.title(),
|
|
|
|
|
leading: React.createElement(FormRow.Icon, { source: tabs.icon }),
|
|
|
|
|
trailing: React.createElement(React.Fragment, {}, [
|
|
|
|
|
tabs.trailing ? tabs.trailing() : null,
|
2026-05-30 19:07:44 +01:00
|
|
|
React.createElement(FormRow.Arrow, { key: "arrow" }),
|
2025-08-17 22:35:01 +02:00
|
|
|
]),
|
|
|
|
|
onPress: () => {
|
|
|
|
|
const Component = tabs.page;
|
|
|
|
|
navigation.navigate("VendettaCustomPage", {
|
|
|
|
|
title: tabs.title(),
|
2026-05-30 19:07:44 +01:00
|
|
|
render: () => React.createElement(Component),
|
2025-08-17 22:35:01 +02:00
|
|
|
});
|
2026-05-30 19:07:44 +01:00
|
|
|
},
|
2025-08-17 22:35:01 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function patchPanelUI(tabs, patches) {
|
|
|
|
|
try {
|
|
|
|
|
patches.push(
|
|
|
|
|
after(
|
|
|
|
|
"default",
|
2026-05-30 19:07:44 +01:00
|
|
|
bunny?.metro?.findByNameLazy(
|
|
|
|
|
"UserSettingsOverviewWrapper",
|
|
|
|
|
false,
|
|
|
|
|
),
|
2025-08-17 22:35:01 +02:00
|
|
|
(_, ret) => {
|
|
|
|
|
const UserSettingsOverview = findInReactTree(
|
|
|
|
|
ret.props.children,
|
2026-05-30 19:07:44 +01:00
|
|
|
(n) => n.type?.name === "UserSettingsOverview",
|
2025-08-17 22:35:01 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (UserSettingsOverview) {
|
|
|
|
|
patches.push(
|
|
|
|
|
after(
|
|
|
|
|
"render",
|
|
|
|
|
UserSettingsOverview.type.prototype,
|
|
|
|
|
(_args, res) => {
|
|
|
|
|
const sections = findInReactTree(
|
|
|
|
|
res.props.children,
|
2026-05-30 19:07:44 +01:00
|
|
|
(n) =>
|
|
|
|
|
n?.children?.[1]?.type ===
|
|
|
|
|
FormSection,
|
2025-08-17 22:35:01 +02:00
|
|
|
)?.children;
|
|
|
|
|
|
|
|
|
|
if (sections) {
|
|
|
|
|
const index = sections.findIndex((c) =>
|
2026-05-30 19:07:44 +01:00
|
|
|
[
|
|
|
|
|
"BILLING_SETTINGS",
|
|
|
|
|
"PREMIUM_SETTINGS",
|
|
|
|
|
].includes(c?.props?.label),
|
2025-08-17 22:35:01 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
sections.splice(
|
|
|
|
|
-~index || 4,
|
|
|
|
|
0,
|
2026-05-30 19:07:44 +01:00
|
|
|
React.createElement(Section, {
|
|
|
|
|
key: tabs.key,
|
|
|
|
|
tabs,
|
|
|
|
|
}),
|
2025-08-17 22:35:01 +02:00
|
|
|
);
|
|
|
|
|
}
|
2026-05-30 19:07:44 +01:00
|
|
|
},
|
|
|
|
|
),
|
2025-08-17 22:35:01 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-05-30 19:07:44 +01:00
|
|
|
true,
|
|
|
|
|
),
|
2025-08-17 22:35:01 +02:00
|
|
|
);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.info("Panel UI patch failed graciously 💔", error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function patchTabsUI(tabs, patches) {
|
|
|
|
|
if (!settingConstants || !SettingsOverviewScreen || !tabsNavigationRef) {
|
2026-05-30 19:07:44 +01:00
|
|
|
console.warn(
|
|
|
|
|
"[AccountSwitcher] Missing required constants for tabs UI patch",
|
|
|
|
|
);
|
2025-08-17 22:35:01 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const row = {};
|
|
|
|
|
row[tabs.key] = {
|
|
|
|
|
type: "pressable",
|
|
|
|
|
title: tabs.title,
|
2026-05-30 19:07:44 +01:00
|
|
|
useTitle: tabs.title,
|
2025-08-17 22:35:01 +02:00
|
|
|
icon: tabs.icon,
|
2026-05-30 19:07:44 +01:00
|
|
|
IconComponent:
|
|
|
|
|
tabs.icon &&
|
|
|
|
|
(() => {
|
|
|
|
|
const actualIconSource =
|
|
|
|
|
typeof tabs.icon === "object" && tabs.icon.uri !== undefined
|
|
|
|
|
? tabs.icon.uri
|
|
|
|
|
: tabs.icon;
|
|
|
|
|
return React.createElement(TableRowIcon, {
|
|
|
|
|
source: actualIconSource,
|
|
|
|
|
});
|
|
|
|
|
}),
|
2025-08-17 22:35:01 +02:00
|
|
|
usePredicate: tabs.predicate,
|
|
|
|
|
useTrailing: tabs.trailing,
|
|
|
|
|
onPress: () => {
|
|
|
|
|
const navigation = tabsNavigationRef.getRootNavigationRef();
|
|
|
|
|
const Component = tabs.page;
|
|
|
|
|
|
|
|
|
|
navigation.navigate("VendettaCustomPage", {
|
|
|
|
|
title: tabs.title(),
|
2026-05-30 19:07:44 +01:00
|
|
|
render: () => React.createElement(Component),
|
2025-08-17 22:35:01 +02:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
withArrow: true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let rendererConfigValue = settingConstants.SETTING_RENDERER_CONFIG;
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(settingConstants, "SETTING_RENDERER_CONFIG", {
|
|
|
|
|
enumerable: true,
|
|
|
|
|
configurable: true,
|
|
|
|
|
get: () => ({
|
|
|
|
|
...rendererConfigValue,
|
|
|
|
|
...row,
|
|
|
|
|
}),
|
2026-05-30 19:07:44 +01:00
|
|
|
set: (v) => (rendererConfigValue = v),
|
2025-08-17 22:35:01 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const firstRender = Symbol("AccountSwitcher-pinToSettings");
|
|
|
|
|
|
2025-12-07 20:10:01 +00:00
|
|
|
try {
|
2026-05-30 19:07:44 +01:00
|
|
|
if (!createListModule) return;
|
2025-12-07 20:10:01 +00:00
|
|
|
|
|
|
|
|
patches.push(
|
|
|
|
|
after("createList", createListModule, (args, ret) => {
|
2026-05-30 19:07:44 +01:00
|
|
|
if (!args[0][firstRender]) {
|
2025-12-07 20:10:01 +00:00
|
|
|
args[0][firstRender] = true;
|
|
|
|
|
|
|
|
|
|
const [config] = args;
|
|
|
|
|
const sections = config.sections;
|
|
|
|
|
|
2025-12-11 15:57:03 +00:00
|
|
|
const section = sections?.find((x) =>
|
2026-05-30 19:07:44 +01:00
|
|
|
["Bunny", "Kettu", "Revenge"].includes(x?.label),
|
2025-12-11 15:57:03 +00:00
|
|
|
);
|
2025-12-07 20:10:01 +00:00
|
|
|
|
|
|
|
|
// If unable to find a section
|
2026-05-30 19:07:44 +01:00
|
|
|
if (!section) {
|
2025-12-07 20:10:01 +00:00
|
|
|
const isMainSettings = Boolean(
|
2026-05-30 19:07:44 +01:00
|
|
|
sections?.find((x) =>
|
|
|
|
|
x.settings.includes("ACCOUNT"),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (isMainSettings) {
|
2025-12-07 20:10:01 +00:00
|
|
|
// Add a new section to the top
|
|
|
|
|
sections.unshift({
|
|
|
|
|
label: manifest.name,
|
|
|
|
|
title: manifest.name,
|
2026-05-30 19:07:44 +01:00
|
|
|
settings: [tabs.key],
|
2025-12-07 20:10:01 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (section?.settings) {
|
|
|
|
|
section.settings = [...section.settings, tabs.key];
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-30 19:07:44 +01:00
|
|
|
}),
|
|
|
|
|
);
|
2025-12-07 20:10:01 +00:00
|
|
|
} catch {
|
|
|
|
|
patches.push(
|
2026-05-30 19:07:44 +01:00
|
|
|
after("default", SettingsOverviewScreen, (args, ret) => {
|
|
|
|
|
if (!args[0][firstRender]) {
|
|
|
|
|
args[0][firstRender] = true;
|
|
|
|
|
|
|
|
|
|
const { sections } = findInReactTree(
|
|
|
|
|
ret,
|
|
|
|
|
(i) => i.props?.sections,
|
|
|
|
|
).props;
|
|
|
|
|
|
|
|
|
|
const section = sections?.find((x) =>
|
|
|
|
|
["Bunny", "Kettu", "Revenge"].includes(x?.label),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// If unable to find a section
|
|
|
|
|
if (!section) {
|
2025-12-07 20:10:01 +00:00
|
|
|
const isMainSettings = Boolean(
|
2026-05-30 19:07:44 +01:00
|
|
|
sections?.find((x) =>
|
|
|
|
|
x.settings.includes("ACCOUNT"),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (isMainSettings) {
|
2025-12-07 20:10:01 +00:00
|
|
|
// Add a new section to the top
|
|
|
|
|
sections.unshift({
|
|
|
|
|
label: manifest.name,
|
|
|
|
|
title: manifest.name,
|
2026-05-30 19:07:44 +01:00
|
|
|
settings: [tabs.key],
|
2025-12-07 20:10:01 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-30 19:07:44 +01:00
|
|
|
if (section?.settings) {
|
|
|
|
|
section.settings = [...section.settings, tabs.key];
|
|
|
|
|
}
|
2025-08-17 22:35:01 +02:00
|
|
|
}
|
2026-05-30 19:07:44 +01:00
|
|
|
}),
|
|
|
|
|
);
|
2025-12-07 20:10:01 +00:00
|
|
|
}
|
2025-08-17 22:35:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function patchSettingsPin(tabs) {
|
|
|
|
|
const patches = [];
|
|
|
|
|
|
|
|
|
|
let disabled = false;
|
|
|
|
|
|
|
|
|
|
const realPredicate = tabs.predicate || (() => true);
|
|
|
|
|
tabs.predicate = () => (disabled ? false : realPredicate());
|
|
|
|
|
|
|
|
|
|
patchPanelUI(tabs, patches);
|
|
|
|
|
patchTabsUI(tabs, patches);
|
|
|
|
|
patches.push(() => (disabled = true));
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
for (const x of patches) {
|
|
|
|
|
x();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function patchSidebar() {
|
|
|
|
|
if (!storage.settings?.addToSidebar) {
|
|
|
|
|
console.log("[AccountSwitcher] Sidebar disabled in settings");
|
|
|
|
|
return () => {};
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-30 19:07:44 +01:00
|
|
|
console.log(
|
|
|
|
|
"[AccountSwitcher] Patching sidebar using custom patchSettingsPin...",
|
|
|
|
|
);
|
2025-08-17 22:35:01 +02:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const unpatch = patchSettingsPin({
|
|
|
|
|
key: "AccountSwitcher",
|
|
|
|
|
icon: getAssetIDByName("UserIcon"),
|
|
|
|
|
title: () => "Account Switcher",
|
|
|
|
|
predicate: () => storage.settings?.addToSidebar === true,
|
|
|
|
|
page: AccountSwitcherSettings,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log("[AccountSwitcher] Successfully patched sidebar");
|
|
|
|
|
return unpatch;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("[AccountSwitcher] Failed to patch sidebar:", error);
|
|
|
|
|
return () => {};
|
|
|
|
|
}
|
2025-08-19 08:35:21 +02:00
|
|
|
}
|