BetterSettings: Fix For New Menu
This commit is contained in:
parent
d613793dc4
commit
2ae503d930
2 changed files with 24 additions and 75 deletions
|
|
@ -152,14 +152,6 @@ export default definePlugin({
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
find: "#{intl::USER_SETTINGS_ACTIONS_MENU_LABEL}",
|
||||
replacement: {
|
||||
// Skip the check Discord performs to make sure the section being selected in the user settings context menu is valid
|
||||
match: /null!=\(\i=Object.values\(\i\.\i\).{0,50}?&&(?=\(0,\i\.openUserSettings\)\(\i,\{section:\i)/,
|
||||
replace: ""
|
||||
}
|
||||
},
|
||||
{
|
||||
find: ".buildLayout().map",
|
||||
replacement: {
|
||||
|
|
|
|||
|
|
@ -7,14 +7,13 @@
|
|||
import { definePluginSettings } from "@api/Settings";
|
||||
import { disableStyle, enableStyle } from "@api/Styles";
|
||||
import { buildPluginMenuEntries, buildThemeMenuEntries } from "@equicordplugins/equicordToolbox/menu";
|
||||
import SettingsPlugin from "@plugins/_core/settings";
|
||||
import { Devs } from "@utils/constants";
|
||||
import { classNameFactory } from "@utils/css";
|
||||
import { Logger } from "@utils/Logger";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { findCssClassesLazy } from "@webpack";
|
||||
import { ComponentDispatch, FocusLock, Menu, useEffect, useRef } from "@webpack/common";
|
||||
import type { HTMLAttributes, ReactElement } from "react";
|
||||
import type { HTMLAttributes } from "react";
|
||||
|
||||
import fullHeightStyle from "./fullHeightContext.css?managed";
|
||||
|
||||
|
|
@ -171,13 +170,9 @@ export default definePlugin({
|
|||
find: "#{intl::USER_SETTINGS_ACTIONS_MENU_LABEL}",
|
||||
replacement: [
|
||||
{
|
||||
match: /=\[\];(\i)(?=\.forEach.{0,200}?"logout"===\i.{0,100}?(\i)\.get\(\i\))/,
|
||||
replace: "=$self.wrapMap([]);$self.transformSettingsEntries($1,$2)",
|
||||
match: /(\i)=(.{0,20}openUserSettings\)\(\i\)\));/,
|
||||
replace: "$1=$self.transformSettingsElements($2);",
|
||||
},
|
||||
{
|
||||
match: /case \i\.\i\.DEVELOPER_OPTIONS:return \i;/,
|
||||
replace: "$&case 'EquicordPlugins':return $self.buildPluginMenuEntries(true);case 'EquicordThemes':return $self.buildThemeMenuEntries();"
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
|
|
@ -200,72 +195,34 @@ export default definePlugin({
|
|||
return <Layer {...props} />;
|
||||
},
|
||||
|
||||
transformSettingsEntries(list: SettingsEntry[], keyMap: Map<string, string>) {
|
||||
transformSettingsElements(list) {
|
||||
const items: any[] = [];
|
||||
const equicordItems: SettingsEntry[] = [
|
||||
{ section: "EquicordSettings", label: "Settings" },
|
||||
{ section: "EquicordPlugins", label: "Plugins" },
|
||||
{ section: "EquicordThemes", label: "Themes" },
|
||||
{ section: "EquicordUpdater", label: "Updater" },
|
||||
{ section: "EquicordChangelog", label: "Changelog" },
|
||||
{ section: "EquicordCloud", label: "Cloud" },
|
||||
{ section: "EquicordBackupAndRestore", label: "Backup & Restore" },
|
||||
{ section: "EquicordPatchHelper", label: "Patch Helper" },
|
||||
];
|
||||
|
||||
for (const [section, key] of SettingsPlugin.settingsSectionMap) {
|
||||
const entry = SettingsPlugin.customEntries.find(e => key.endsWith(e.key));
|
||||
if (entry) equicordItems.push({ section, label: entry.title });
|
||||
}
|
||||
for (const item of list) {
|
||||
const { key, props } = item;
|
||||
if (!props) continue;
|
||||
|
||||
if (settings.store.organizeMenu) {
|
||||
for (const item of list) {
|
||||
if (!item.label || item.predicate != null && !item.predicate()) continue;
|
||||
if (key === "equicord_plugins" || key === "equicord_themes") {
|
||||
const children = key === "equicord_plugins"
|
||||
? buildPluginMenuEntries()
|
||||
: buildThemeMenuEntries();
|
||||
|
||||
if (item.section === "HEADER") {
|
||||
keyMap.set(item.label, item.label);
|
||||
items.push({ section: item.label, items: [] });
|
||||
} else if (item.section !== "DIVIDER" && keyMap.has(item.section)) {
|
||||
items.at(-1)?.items.push(item);
|
||||
}
|
||||
items.push(
|
||||
<Menu.MenuItem key={key} label={props.label} id={props.label} {...props}>
|
||||
{children}
|
||||
</Menu.MenuItem>
|
||||
);
|
||||
} else if (key.endsWith("_section") && props.label) {
|
||||
items.push(
|
||||
<Menu.MenuItem key={key} label={props.label} id={props.label}>
|
||||
{this.transformSettingsElements(props.children)}
|
||||
</Menu.MenuItem>
|
||||
);
|
||||
} else {
|
||||
items.push(item);
|
||||
}
|
||||
|
||||
keyMap.set("Equicord", "Equicord");
|
||||
items.push({
|
||||
section: "Equicord",
|
||||
items: equicordItems
|
||||
});
|
||||
} else {
|
||||
items.push(...list, ...equicordItems);
|
||||
}
|
||||
|
||||
return items;
|
||||
},
|
||||
|
||||
wrapMap(toWrap: TransformedSettingsEntry[]) {
|
||||
if (!settings.store.organizeMenu) return toWrap;
|
||||
// @ts-expect-error
|
||||
toWrap.map = function (render: (item: SettingsEntry) => ReactElement<any>) {
|
||||
return this
|
||||
.filter(a => a.items.length > 0)
|
||||
.map(({ section, items }) => {
|
||||
const children = items.map(render);
|
||||
if (section) {
|
||||
return (
|
||||
<Menu.MenuItem
|
||||
key={section}
|
||||
id={section.replace(/\W/, "_")}
|
||||
label={section}
|
||||
>
|
||||
{children}
|
||||
</Menu.MenuItem>
|
||||
);
|
||||
} else {
|
||||
return children;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return toWrap;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue