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

Commit

Permalink
[UI] Fix You tab settings on 189.4+ (#118)
Browse files Browse the repository at this point in the history
* [UI] Fix You tab settings on 189.4+

* [UI > YouTab] Formatting

---------

Co-authored-by: Beef <[email protected]>
  • Loading branch information
aliernfrog and maisymoe authored Jul 23, 2023
1 parent d0f8815 commit cf09dbc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/ui/settings/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { findByProps } from "@metro/filters";
import patchPanels from "@ui/settings/patches/panels";
import patchYou from "@ui/settings/patches/you";

export default function initSettings() {
const patches = [
patchPanels(),
...(findByProps("getSettingSearchListItems") ? [patchYou()] : []),
patchYou(),
]

return () => patches.forEach(p => p());
Expand Down
20 changes: 16 additions & 4 deletions src/ui/settings/patches/you.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ import { getRenderableScreens, getScreens, getYouData } from "@ui/settings/data"

const layoutModule = findByProps("useOverviewSettings");
const titleConfigModule = findByProps("getSettingTitleConfig");
const gettersModule = findByProps("getSettingSearchListItems");
const miscModule = findByProps("SETTING_RELATIONSHIPS", "SETTING_RENDERER_CONFIGS");

// Checks for 189.4 and above
// When dropping support for 189.3 and below, following can be done: (unless Discord changes things again)
// const gettersModule = findByProps("getSettingListItems");
const OLD_GETTER_FUNCTION = "getSettingSearchListItems";
const NEW_GETTER_FUNCTION = "getSettingListItems";
const oldGettersModule = findByProps(OLD_GETTER_FUNCTION);
const usingNewGettersModule = !oldGettersModule;
const getterFunctionName = usingNewGettersModule ? NEW_GETTER_FUNCTION : OLD_GETTER_FUNCTION;
const gettersModule = oldGettersModule ?? findByProps(NEW_GETTER_FUNCTION);

export default function patchYou() {
if (!gettersModule) return;

const patches = new Array<Function>;
const screens = getScreens(true);
const renderableScreens = getRenderableScreens(true);
Expand All @@ -29,7 +40,7 @@ export default function patchYou() {
...data.titleConfig,
})));

patches.push(after("getSettingSearchListItems", gettersModule, ([settings], ret) => [
patches.push(after(getterFunctionName, gettersModule, ([settings], ret) => [
...(renderableScreens.filter(s => settings.includes(s.key))).map(s => ({
type: "setting_search_result",
ancestorRendererData: data.rendererConfigs[s.key],
Expand All @@ -38,7 +49,8 @@ export default function patchYou() {
breadcrumbs: ["Vendetta"],
icon: data.rendererConfigs[s.key].icon,
})),
...ret.filter((i: any) => !screens.map(s => s.key).includes(i.setting)),
// .filter can be removed when dropping support for 189.3 and below (unless Discord changes things again)
...ret.filter((i: any) => (usingNewGettersModule || !screens.map(s => s.key).includes(i.setting)))
].map((item, index, parent) => ({ ...item, index, total: parent.length }))));

// TODO: We could use a proxy for these
Expand All @@ -53,4 +65,4 @@ export default function patchYou() {
miscModule.SETTING_RENDERER_CONFIGS = oldRendererConfigs;
patches.forEach(p => p());
};
}
}

0 comments on commit cf09dbc

Please sign in to comment.