Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
Implement You tab support
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Aug 13, 2023
1 parent 666fccf commit ac2fc19
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 13 deletions.
1 change: 0 additions & 1 deletion build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import swc from "@swc/core";
import { execSync } from "child_process";
import esbuild from "esbuild";
import globalsPlugin from "esbuild-plugin-globals";
import { argv } from "process";

const flags = argv.slice(2).filter(arg => arg.startsWith("--")).map(arg => arg.slice(2));
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/metro/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export const Styles = findByPropsLazy("createThemedStyleSheet");
export const Colors = findByPropsLazy("unsafe_rawColors");
export const Constants = findByPropsLazy("NODE_SIZE");
export const FluxDispatcher = findByPropsLazy("dispatch", "subscribe");
export const TabsNavigationRef = findByPropsLazy("getRootNavigationRef");
85 changes: 73 additions & 12 deletions src/patches/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import Patcher from "@api/Patcher";
import { filters } from "@metro";
import { Forms, I18n, NavigationNative } from "@metro/common";
import { filters, findByPropsLazy, waitForModule } from "@metro";
import { Forms, I18n, NavigationNative, TabsNavigationRef } from "@metro/common";
import { assets, findInReactTree, lazyNavigate } from "@utils";

const patcher = new Patcher("settings-patcher");

const CustomPageRenderer = React.memo(() => {
const navigation = NavigationNative.useNavigation();
const route = NavigationNative.useRoute();

const { render: PageComponent, ...args } = route.params;

React.useEffect(() => {
navigation.setOptions({ ...args });
}, []);

return <PageComponent />;
});

function SettingsSection() {
// This has to be destructured here, otherwise it will throw
const { FormSection, FormRow, FormIcon } = Forms;
Expand All @@ -30,20 +43,12 @@ function SettingsSection() {
);
}

export default function patchSettings() {
function patchPanelUI() {
patcher.patch(filters.byName("getScreens", false)).after("default", (_args, screens) => {
return Object.assign(screens, {
PyoncordCustomPage: {
title: "Pyoncord",
render: ({ render: PageComponent, ...args }: any) => {
const navigation = NavigationNative.useNavigation();

React.useEffect(() => {
navigation.setOptions({ ...args });
}, []);

return <PageComponent />;
},
render: () => <CustomPageRenderer />
}
});
});
Expand Down Expand Up @@ -81,6 +86,62 @@ export default function patchSettings() {

unpatch();
});
}

function patchTabsUI() {
const pyonSection = [
["PYONCORD", "Pyoncord", () => import("@ui/screens/General"), "Discord"],
["PYONCORD_PLUGINS", "Plugins", () => import("@ui/screens/Plugins"), "ic_progress_wrench_24px"]
] as [key: string, title: string, getRender: () => Promise<any>, icon: string][];

waitForModule("SETTING_RENDERER_CONFIGS", (module) => {

Check failure on line 97 in src/patches/settings.tsx

View workflow job for this annotation

GitHub Actions / Build

Unexpected parentheses around single function argument
module.SETTING_RENDERER_CONFIGS.PYONCORD_CUSTOM_PAGE = {
type: "route",
screen: {
route: "PyoncordCustomPage",
getComponent: () => CustomPageRenderer
}
};

pyonSection.forEach(([key, title, getRender, icon]) => {
module.SETTING_RELATIONSHIPS[key] = null;
module.PRESSABLE_SETTINGS_WITH_TRAILING_ARROW?.add(key);

module.SETTING_RENDERER_CONFIGS[key] = {
type: "pressable",
get icon() {
return typeof icon === "string"
? assets.getAssetIDByName(icon)
: icon;
},
onPress: () => {
const ref = TabsNavigationRef.getRootNavigationRef();
lazyNavigate(ref, getRender(), title);
}
};
});

patcher.after(module, "getSettingTitleConfig", (args, res) => {
pyonSection.forEach(([key, title]) => res[key] = title);
res.PYONCORD_CUSTOM_PAGE = "Pyon!";
});
});

waitForModule("useOverviewSettings", (module) => {

Check failure on line 130 in src/patches/settings.tsx

View workflow job for this annotation

GitHub Actions / Build

Unexpected parentheses around single function argument
patcher.after(module, "useOverviewSettings", (args, res) => {
if (!(res instanceof Array) || res.find(sect => sect.title === "Pyoncord")) return;

res.unshift({
title: "Pyoncord",
settings: pyonSection.map(a => a[0])
});
});
});
}

export default function patchSettings() {
patchPanelUI();
patchTabsUI();

return () => patcher.unpatchAllAndStop();
}

0 comments on commit ac2fc19

Please sign in to comment.