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

Commit cf09dbc

Browse files
aliernfrogmaisymoe
andauthored
[UI] Fix You tab settings on 189.4+ (#118)
* [UI] Fix You tab settings on 189.4+ * [UI > YouTab] Formatting --------- Co-authored-by: Beef <[email protected]>
1 parent d0f8815 commit cf09dbc

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/ui/settings/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { findByProps } from "@metro/filters";
21
import patchPanels from "@ui/settings/patches/panels";
32
import patchYou from "@ui/settings/patches/you";
43

54
export default function initSettings() {
65
const patches = [
76
patchPanels(),
8-
...(findByProps("getSettingSearchListItems") ? [patchYou()] : []),
7+
patchYou(),
98
]
109

1110
return () => patches.forEach(p => p());

src/ui/settings/patches/you.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,21 @@ import { getRenderableScreens, getScreens, getYouData } from "@ui/settings/data"
55

66
const layoutModule = findByProps("useOverviewSettings");
77
const titleConfigModule = findByProps("getSettingTitleConfig");
8-
const gettersModule = findByProps("getSettingSearchListItems");
98
const miscModule = findByProps("SETTING_RELATIONSHIPS", "SETTING_RENDERER_CONFIGS");
109

10+
// Checks for 189.4 and above
11+
// When dropping support for 189.3 and below, following can be done: (unless Discord changes things again)
12+
// const gettersModule = findByProps("getSettingListItems");
13+
const OLD_GETTER_FUNCTION = "getSettingSearchListItems";
14+
const NEW_GETTER_FUNCTION = "getSettingListItems";
15+
const oldGettersModule = findByProps(OLD_GETTER_FUNCTION);
16+
const usingNewGettersModule = !oldGettersModule;
17+
const getterFunctionName = usingNewGettersModule ? NEW_GETTER_FUNCTION : OLD_GETTER_FUNCTION;
18+
const gettersModule = oldGettersModule ?? findByProps(NEW_GETTER_FUNCTION);
19+
1120
export default function patchYou() {
21+
if (!gettersModule) return;
22+
1223
const patches = new Array<Function>;
1324
const screens = getScreens(true);
1425
const renderableScreens = getRenderableScreens(true);
@@ -29,7 +40,7 @@ export default function patchYou() {
2940
...data.titleConfig,
3041
})));
3142

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

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

0 commit comments

Comments
 (0)