|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | import { definePluginSettings } from "@api/Settings"; |
8 | | -import { classNameFactory } from "@api/Styles"; |
| 8 | +import { classNameFactory, disableStyle, enableStyle } from "@api/Styles"; |
9 | 9 | import { buildPluginMenuEntries, buildThemeMenuEntries } from "@plugins/vencordToolbox/menu"; |
10 | 10 | import { Devs } from "@utils/constants"; |
11 | | -import { getIntlMessage } from "@utils/discord"; |
12 | 11 | import { Logger } from "@utils/Logger"; |
13 | 12 | import definePlugin, { OptionType } from "@utils/types"; |
14 | 13 | import { waitFor } from "@webpack"; |
15 | 14 | import { ComponentDispatch, FocusLock, Menu, useEffect, useRef } from "@webpack/common"; |
16 | 15 | import type { HTMLAttributes, ReactElement } from "react"; |
17 | 16 |
|
| 17 | +import fullHeightStyle from "./fullHeightContext.css?managed"; |
| 18 | + |
18 | 19 | type SettingsEntry = { section: string, label: string; }; |
19 | 20 |
|
20 | 21 | const cl = classNameFactory(""); |
@@ -42,6 +43,11 @@ const settings = definePluginSettings({ |
42 | 43 | } |
43 | 44 | }); |
44 | 45 |
|
| 46 | +interface TransformedSettingsEntry { |
| 47 | + section: string; |
| 48 | + items: SettingsEntry[]; |
| 49 | +} |
| 50 | + |
45 | 51 | interface LayerProps extends HTMLAttributes<HTMLDivElement> { |
46 | 52 | mode: "SHOWN" | "HIDDEN"; |
47 | 53 | baseLayer?: boolean; |
@@ -81,6 +87,15 @@ export default definePlugin({ |
81 | 87 | authors: [Devs.Kyuuhachi], |
82 | 88 | settings, |
83 | 89 |
|
| 90 | + start() { |
| 91 | + if (settings.store.organizeMenu) |
| 92 | + enableStyle(fullHeightStyle); |
| 93 | + }, |
| 94 | + |
| 95 | + stop() { |
| 96 | + disableStyle(fullHeightStyle); |
| 97 | + }, |
| 98 | + |
84 | 99 | patches: [ |
85 | 100 | { |
86 | 101 | find: "this.renderArtisanalHack()", |
@@ -124,8 +139,8 @@ export default definePlugin({ |
124 | 139 | find: "#{intl::USER_SETTINGS_ACTIONS_MENU_LABEL}", |
125 | 140 | replacement: [ |
126 | 141 | { |
127 | | - match: /=\[\];if\((\i)(?=\.forEach)/, |
128 | | - replace: "=$self.wrapMap([]);if($self.transformSettingsEntries($1)", |
| 142 | + match: /=\[\];if\((\i)(?=\.forEach.{0,100}"logout"!==\i.{0,30}(\i)\.get\(\i\))/, |
| 143 | + replace: "=$self.wrapMap([]);if($self.transformSettingsEntries($1,$2)", |
129 | 144 | predicate: () => settings.store.organizeMenu |
130 | 145 | }, |
131 | 146 | { |
@@ -154,36 +169,34 @@ export default definePlugin({ |
154 | 169 | return <Layer {...props} />; |
155 | 170 | }, |
156 | 171 |
|
157 | | - transformSettingsEntries(list: SettingsEntry[]) { |
158 | | - const items = [{ label: null as string | null, items: [] as SettingsEntry[] }]; |
| 172 | + transformSettingsEntries(list: SettingsEntry[], keyMap: Map<string, string>) { |
| 173 | + const items = [] as TransformedSettingsEntry[]; |
159 | 174 |
|
160 | 175 | for (const item of list) { |
161 | 176 | if (item.section === "HEADER") { |
162 | | - items.push({ label: item.label, items: [] }); |
163 | | - } else if (item.section === "DIVIDER") { |
164 | | - items.push({ label: getIntlMessage("OTHER_OPTIONS"), items: [] }); |
165 | | - } else { |
166 | | - items.at(-1)!.items.push(item); |
| 177 | + keyMap.set(item.label, item.label); |
| 178 | + items.push({ section: item.label, items: [] }); |
| 179 | + } else if (item.section !== "DIVIDER" && keyMap.has(item.section)) { |
| 180 | + items.at(-1)?.items.push(item); |
167 | 181 | } |
168 | 182 | } |
169 | 183 |
|
170 | 184 | return items; |
171 | 185 | }, |
172 | 186 |
|
173 | | - wrapMap(toWrap: any[]) { |
174 | | - const otherOptions = getIntlMessage("OTHER_OPTIONS"); |
| 187 | + wrapMap(toWrap: TransformedSettingsEntry[]) { |
175 | 188 | // @ts-expect-error |
176 | 189 | toWrap.map = function (render: (item: SettingsEntry) => ReactElement<any>) { |
177 | 190 | return this |
178 | | - .filter(a => a.items.length > 0 && a.label !== otherOptions) |
179 | | - .map(({ label, items }) => { |
| 191 | + .filter(a => a.items.length > 0) |
| 192 | + .map(({ section, items }) => { |
180 | 193 | const children = items.map(render); |
181 | | - if (label) { |
| 194 | + if (section) { |
182 | 195 | return ( |
183 | 196 | <Menu.MenuItem |
184 | | - key={label} |
185 | | - id={label.replace(/\W/, "_")} |
186 | | - label={label} |
| 197 | + key={section} |
| 198 | + id={section.replace(/\W/, "_")} |
| 199 | + label={section} |
187 | 200 | > |
188 | 201 | {children} |
189 | 202 | </Menu.MenuItem> |
|
0 commit comments