From 6b66856b5c38d7993165a366433559459f22d2bf Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 7 Oct 2025 16:06:40 +0200 Subject: [PATCH] BetterSettings: fix context menu organising --- src/plugins/betterSettings/index.tsx | 69 ++++++++++++++-------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/src/plugins/betterSettings/index.tsx b/src/plugins/betterSettings/index.tsx index 8fecb2623..4e04b4df4 100644 --- a/src/plugins/betterSettings/index.tsx +++ b/src/plugins/betterSettings/index.tsx @@ -32,7 +32,8 @@ const settings = definePluginSettings({ organizeMenu: { description: "Organizes the settings cog context menu into categories", type: OptionType.BOOLEAN, - default: true + default: true, + restartNeeded: true }, eagerLoad: { description: "Removes the loading delay when opening the menu for the first time", @@ -119,12 +120,14 @@ export default definePlugin({ }, predicate: () => settings.store.eagerLoad }, - { // Settings cog context menu + { + // Settings cog context menu find: "#{intl::USER_SETTINGS_ACTIONS_MENU_LABEL}", replacement: [ { - match: /(\(0,\i.\i\)\(\))(?=\.filter\(\i=>\{let\{section:\i\}=)/, - replace: "$self.wrapMenu($1)" + match: /=\[\];return (\i)(?=\.forEach)/, + replace: "=$self.wrapMap([]);return $self.transformSettingsEntries($1)", + predicate: () => settings.store.organizeMenu }, { match: /case \i\.\i\.DEVELOPER_OPTIONS:return \i;/, @@ -151,9 +154,7 @@ export default definePlugin({ return ; }, - wrapMenu(list: SettingsEntry[]) { - if (!settings.store.organizeMenu) return list; - + transformSettingsEntries(list: SettingsEntry[]) { const items = [{ label: null as string | null, items: [] as SettingsEntry[] }]; for (const item of list) { @@ -166,34 +167,32 @@ export default definePlugin({ } } - return { - filter(predicate: (item: SettingsEntry) => boolean) { - for (const category of items) { - category.items = category.items.filter(predicate); - } - return this; - }, - map(render: (item: SettingsEntry) => ReactElement) { - return items - .filter(a => a.items.length > 0) - .map(({ label, items }) => { - const children = items.map(render); - if (label) { - return ( - - {children} - - ); - } else { - return children; - } - }); - } + return items; + }, + + wrapMap(toWrap: any[]) { + // @ts-expect-error + toWrap.map = function (render: (item: SettingsEntry) => ReactElement) { + return this + .filter(a => a.items.length > 0) + .map(({ label, items }) => { + const children = items.map(render); + if (label) { + return ( + + {children} + + ); + } else { + return children; + } + }); }; + + return toWrap; } });