From 6140b9581496a1102839cbefbd2fa1b41a6f4c12 Mon Sep 17 00:00:00 2001 From: Kyuuhachi <1547062+Kyuuhachi@users.noreply.github.com> Date: Sat, 16 Mar 2024 02:19:26 +0100 Subject: [PATCH 01/42] new plugin: BetterSettings ~ improves Discord's settings (#2222) - makes opening settings much faster - removes the scuffed transition animation - organises the settings cog context menu into categories Co-authored-by: Vendicated --- src/plugins/_core/settings.tsx | 26 +--- src/plugins/betterSettings/README.md | 9 ++ src/plugins/betterSettings/index.tsx | 177 +++++++++++++++++++++++ src/webpack/common/components.ts | 3 +- src/webpack/common/types/components.d.ts | 4 + 5 files changed, 199 insertions(+), 20 deletions(-) create mode 100644 src/plugins/betterSettings/README.md create mode 100644 src/plugins/betterSettings/index.tsx diff --git a/src/plugins/_core/settings.tsx b/src/plugins/_core/settings.tsx index 01220eb4e..569c3f0ac 100644 --- a/src/plugins/_core/settings.tsx +++ b/src/plugins/_core/settings.tsx @@ -16,11 +16,10 @@ * along with this program. If not, see . */ -import { findGroupChildrenByChildId } from "@api/ContextMenu"; import { Settings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { React, SettingsRouter } from "@webpack/common"; +import { React } from "@webpack/common"; import gitHash from "~git-hash"; @@ -30,23 +29,6 @@ export default definePlugin({ authors: [Devs.Ven, Devs.Megu], required: true, - contextMenus: { - // The settings shortcuts in the user settings cog context menu - // read the elements from a hardcoded map which for obvious reason - // doesn't contain our sections. This patches the actions of our - // sections to manually use SettingsRouter (which only works on desktop - // but the context menu is usually not available on mobile anyway) - "user-settings-cog"(children) { - const section = findGroupChildrenByChildId("VencordSettings", children); - section?.forEach(c => { - const id = c?.props?.id; - if (id?.startsWith("Vencord") || id?.startsWith("Vesktop")) { - c!.props.action = () => SettingsRouter.open(id); - } - }); - } - }, - patches: [{ find: ".versionHash", replacement: [ @@ -75,6 +57,12 @@ export default definePlugin({ }, replace: "...$self.makeSettingsCategories($1),$&" } + }, { + find: "Messages.USER_SETTINGS_ACTIONS_MENU_LABEL", + replacement: { + match: /(?<=function\((\i),\i\)\{)(?=let \i=Object.values\(\i.UserSettingsSections\).*?(\i)\.default\.open\()/, + replace: "$2.default.open($1);return;" + } }], customSections: [] as ((SectionTypes: Record) => any)[], diff --git a/src/plugins/betterSettings/README.md b/src/plugins/betterSettings/README.md new file mode 100644 index 000000000..127c6ce76 --- /dev/null +++ b/src/plugins/betterSettings/README.md @@ -0,0 +1,9 @@ +# BetterSettings + +Improves Discord's Settings via multiple (toggleable) changes: +- makes opening settings much faster +- removes the scuffed transition animation +- organises the settings cog context menu into categories + +![](https://github.com/Vendicated/Vencord/assets/45497981/e8d67a95-3909-4be5-8281-8cf9d2f1c30e) + diff --git a/src/plugins/betterSettings/index.tsx b/src/plugins/betterSettings/index.tsx new file mode 100644 index 000000000..6d3c8798e --- /dev/null +++ b/src/plugins/betterSettings/index.tsx @@ -0,0 +1,177 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { definePluginSettings } from "@api/Settings"; +import { classNameFactory } from "@api/Styles"; +import ErrorBoundary from "@components/ErrorBoundary"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import { findByPropsLazy } from "@webpack"; +import { ComponentDispatch, FocusLock, i18n, Menu, useEffect, useRef } from "@webpack/common"; +import type { HTMLAttributes, ReactElement } from "react"; + +type SettingsEntry = { section: string, label: string; }; + +const cl = classNameFactory(""); +const Classes = findByPropsLazy("animating", "baseLayer", "bg", "layer", "layers"); + +const settings = definePluginSettings({ + disableFade: { + description: "Disable the crossfade animation", + type: OptionType.BOOLEAN, + default: true, + restartNeeded: true + }, + organizeMenu: { + description: "Organizes the settings cog context menu into categories", + type: OptionType.BOOLEAN, + default: true + }, + eagerLoad: { + description: "Removes the loading delay when opening the menu for the first time", + type: OptionType.BOOLEAN, + default: true, + restartNeeded: true + } +}); + +interface LayerProps extends HTMLAttributes { + mode: "SHOWN" | "HIDDEN"; + baseLayer?: boolean; +} + +function Layer({ mode, baseLayer = false, ...props }: LayerProps) { + const hidden = mode === "HIDDEN"; + const containerRef = useRef(null); + + useEffect(() => () => { + ComponentDispatch.dispatch("LAYER_POP_START"); + ComponentDispatch.dispatch("LAYER_POP_COMPLETE"); + }, []); + + const node = ( +