Skip to content

Commit

Permalink
QoL You settings changes
Browse files Browse the repository at this point in the history
Co-authored-by: nexpid <poggerschampersqwq@gmail.com>
  • Loading branch information
pylixonly and nexpid committed Feb 28, 2024
1 parent d633f4e commit 8b33faa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/core/i18n/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"MANUFACTURER": "Manufacturer",
"MODAL_THEME_REFETCHED": "Theme refetched",
"MODAL_THEME_REFETCHED_DESC": "A reload is required to see the changes. Do you want to reload now?",
"MODAL_UNPROXIED_PLUGIN_DESC": "The plugin you are trying to install has not been proxied/verified by Vendetta staff. Are you sure you want to continue?",
"MODAL_UNPROXIED_PLUGIN_DESC": "The plugin you are trying to install has not been proxied/verified by staffs. Are you sure you want to continue?",
"MODAL_UNPROXIED_PLUGIN_HEADER": "Unproxied Plugin",
"OPEN_IN_BROWSER": "Open in Browser",
"OPERATING_SYSTEM": "Operating System",
Expand Down Expand Up @@ -67,7 +67,7 @@
"UNINSTALL": "Uninstall",
"UNINSTALL_TITLE": "Uninstall {title}",
"VERSIONS": "Versions",
"COMMAND_DEBUG_DESC": "Send Vendetta debug info.",
"COMMAND_DEBUG_DESC": "Send Bunny debug info.",
"COMMAND_DEBUG_OPT_EPHEMERALLY": "Send debug info ephemerally.",
"COMMAND_EVAL_DESC": "Evaluate JavaScript code.",
"COMMAND_EVAL_OPT_CODE": "The code to evaluate.",
Expand Down
6 changes: 3 additions & 3 deletions src/lib/ui/settings/components/SettingsSection.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NavigationNative } from "@metro/common";
import { useProxy } from "@/lib/api/storage";
import { getAssetIDByName } from "@/lib/api/assets";
import { getRenderableScreens } from "@ui/settings/data";
import { getScreens } from "@ui/settings/data";
import { ErrorBoundary, Forms } from "@ui/components";
import { settings } from "@lib/settings";
import { Strings } from "@/core/i18n";
Expand All @@ -12,12 +12,12 @@ export default function SettingsSection() {
const navigation = NavigationNative.useNavigation();
useProxy(settings);

const screens = getRenderableScreens()
const screens = getScreens()

return (
<ErrorBoundary>
<FormSection key="Vendetta" title={`${Strings.BUNNY}${settings.safeMode?.enabled ? ` (${Strings.SAFE_MODE})` : ""}`}>
{screens.map((s, i) => (
{screens.filter(s => (s.shouldRender?.() ?? true)).map((s, i) => (
<>
<FormRow
label={s.title}
Expand Down
27 changes: 13 additions & 14 deletions src/lib/ui/settings/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { PROXY_PREFIX } from "@/lib/utils/constants";
import { findByProps } from "@/lib/metro/filters";
import { isThemeSupported } from "@/lib/api/native/loader";
import { Strings } from "@/core/i18n";
import { useProxy } from "@/lib/api/storage";

const { useSafeAreaInsets } = findByProps("useSafeAreaInsets");

Expand All @@ -37,21 +38,20 @@ const useStyles = stylesheet.createStyles({
}
});

const formatKey = (key: string, youKeys: boolean) => youKeys ? lodash.snakeCase(key).toUpperCase() : key;
// If a function is passed, it is called with the screen object, and the return value is mapped. If a string is passed, we map to the value of the property with that name on the screen. Else, just map to the given data.
// Question: Isn't this overengineered?
// Answer: Maybe.
const keyMap = (screens: Screen[], data: string | ((s: Screen) => any) | null) => Object.fromEntries(screens.map(s => [s.key, typeof data === "function" ? data(s) : typeof data === "string" ? s[data] : data]));

export const getScreens = (youKeys = false): Screen[] => [
export const getScreens = (): Screen[] => [
{
key: formatKey("VendettaSettings", youKeys),
key: "VendettaSettings",
title: Strings.GENERAL,
icon: "settings",
render: General,
},
{
key: formatKey("VendettaPlugins", youKeys),
key: "VendettaPlugins",
title: Strings.PLUGINS,
icon: "debug",
options: {
Expand All @@ -78,7 +78,7 @@ export const getScreens = (youKeys = false): Screen[] => [
render: Plugins,
},
{
key: formatKey("VendettaThemes", youKeys),
key: "VendettaThemes",
title: Strings.THEMES,
icon: "ic_theme_24px",
// TODO: bad
Expand All @@ -89,14 +89,14 @@ export const getScreens = (youKeys = false): Screen[] => [
render: Themes,
},
{
key: formatKey("VendettaDeveloper", youKeys),
key: "VendettaDeveloper",
title: Strings.DEVELOPER,
icon: "ic_progress_wrench_24px",
shouldRender: () => settings.developerSettings ?? false,
render: Developer,
},
{
key: formatKey("VendettaCustomPage", youKeys),
key: "VendettaCustomPage",
title: "Vendetta Page",
shouldRender: () => false,
render: ({ render: PageView, noErrorBoundary, ...options }: { render: React.ComponentType; noErrorBoundary: boolean } & Record<string, object>) => {
Expand All @@ -108,23 +108,23 @@ export const getScreens = (youKeys = false): Screen[] => [
},
];

export const getRenderableScreens = (youKeys = false) => getScreens(youKeys).filter(s => s.shouldRender?.() ?? true);

export const getPanelsScreens = () => keyMap(getScreens(), (s) => ({
title: s.title,
render: s.render,
...s.options,
}));

export const getYouData = () => {
const screens = getScreens(true);
const screens = getScreens();

return {
getLayout: () => ({
// This is an old key, keeping it as "Vendetta" is good as some plugins actually checks
// to determine if this section is Vendetta's
title: "Vendetta",
label: Strings.BUNNY,
// We can't use our keyMap function here since `settings` is an array not an object
settings: getRenderableScreens(true).map(s => s.key)
settings: screens.map(s => s.key)
}),
titleConfig: keyMap(screens, "title"),
relationships: keyMap(screens, null),
Expand All @@ -140,10 +140,9 @@ export const getYouData = () => {
type: "route",
title: () => s.title,
icon: s.icon ? getAssetIDByName(s.icon) : null,
usePredicate: s.shouldRender && (() => useProxy(settings) && s.shouldRender!!()),
screen: {
// TODO: This is bad, we should not re-convert the key casing
// For some context, just using the key here would make the route key be VENDETTA_CUSTOM_PAGE in you tab, which breaks compat with panels UI navigation
route: lodash.chain(s.key).camelCase().upperFirst().value(),
route: s.key,
getComponent: () => WrappedComponent,
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/lib/ui/settings/patches/you.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { findByProps } from "@metro/filters";
import { after, before } from "@lib/api/patcher";
import { getRenderableScreens, getScreens, getYouData } from "@ui/settings/data";
import { getScreens, getYouData } from "@ui/settings/data";
import { i18n } from "@lib/metro/common";
import { Strings } from "@/core/i18n";

Expand Down Expand Up @@ -28,8 +28,7 @@ function oldYouPatch(patches: Function[]) {

if (!gettersModule || !layoutModule) return;

const screens = getScreens(true);
const renderableScreens = getRenderableScreens(true);
const screens = getScreens();
const data = getYouData();

patches.push(after("useOverviewSettings", layoutModule, (_, ret) => manipulateSections(ret, data.getLayout())));
Expand All @@ -40,7 +39,7 @@ function oldYouPatch(patches: Function[]) {
})));

patches.push(after(getterFunctionName, gettersModule, ([settings], ret) => [
...(renderableScreens.filter(s => settings.includes(s.key))).map(s => ({
...(screens.filter(s => settings.includes(s.key) && (s.shouldRender?.() ?? true))).map(s => ({
type: "setting_search_result",
ancestorRendererData: data.rendererConfigs[s.key],
setting: s.key,
Expand Down Expand Up @@ -73,7 +72,7 @@ function newYouPatch(patches: Function[]) {

if (!gettersModule || !settingsListComponents || !settingConstantsModule) return false;

const screens = getScreens(true);
const screens = getScreens();
const data = getYouData();

patches.push(before("type", settingsListComponents.SearchableSettingsList, ([{ sections }]) => manipulateSections(sections, data.getLayout())));
Expand Down

0 comments on commit 8b33faa

Please sign in to comment.