diff --git a/src/api/ChatButtons.tsx b/src/api/ChatButtons.tsx index 3c5e59a73..52052a528 100644 --- a/src/api/ChatButtons.tsx +++ b/src/api/ChatButtons.tsx @@ -9,11 +9,15 @@ import "./ChatButton.css"; import ErrorBoundary from "@components/ErrorBoundary"; import { Logger } from "@utils/Logger"; import { classes } from "@utils/misc"; +import { IconComponent } from "@utils/types"; import { Channel } from "@vencord/discord-types"; import { waitFor } from "@webpack"; -import { ButtonWrapperClasses, Clickable, Tooltip } from "@webpack/common"; +import { ButtonWrapperClasses, Clickable, Menu, Tooltip } from "@webpack/common"; import { HTMLProps, JSX, MouseEventHandler, ReactNode } from "react"; +import { addContextMenuPatch, findGroupChildrenByChildId } from "./ContextMenu"; +import { useSettings } from "./Settings"; + let ChannelTextAreaClasses: Record<"button" | "buttonContainer", string>; waitFor(["buttonContainer", "channelTextArea"], m => ChannelTextAreaClasses = m); @@ -76,26 +80,51 @@ export interface ChatBarProps { } export type ChatBarButtonFactory = (props: ChatBarProps & { isMainChat: boolean; }) => JSX.Element | null; +export type ChatBarButtonData = { + render: ChatBarButtonFactory; + /** + * This icon is used only for Settings UI. Your render function must still render an icon, + * and it can be different from this one. + */ + icon: IconComponent; +}; -const buttonFactories = new Map(); +/** + * Don't use this directly, use {@link addChatBarButton} and {@link removeChatBarButton} instead. + */ +export const ChatBarButtonMap = new Map(); const logger = new Logger("ChatButtons"); +function VencordChatBarButtons(props: ChatBarProps) { + const { chatBarButtons } = useSettings(["uiElements.chatBarButtons.*"]).uiElements; + + return ( + <> + {Array.from(ChatBarButtonMap) + .filter(([key]) => chatBarButtons[key]?.enabled !== false) + .map(([key, { render: Button }]) => ( + logger.error(`Failed to render ${key}`, e.error)}> +