From 2eb8ba18410188715ecdeea80b4b5b046204e153 Mon Sep 17 00:00:00 2001 From: Im_Banana <67657872+ImBonana@users.noreply.github.com> Date: Sat, 11 May 2024 23:49:00 +0300 Subject: [PATCH] SilentTyping: add chat input context menu option to toggle (#2386) Co-authored-by: vee --- src/plugins/silentTyping/index.tsx | 36 +++++++++++++++++++++++++++--- src/utils/constants.ts | 4 ++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/plugins/silentTyping/index.tsx b/src/plugins/silentTyping/index.tsx index 8b59c6ac..2a6a6428 100644 --- a/src/plugins/silentTyping/index.tsx +++ b/src/plugins/silentTyping/index.tsx @@ -18,10 +18,11 @@ import { addChatBarButton, ChatBarButton, removeChatBarButton } from "@api/ChatButtons"; import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; +import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu"; import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { FluxDispatcher, React } from "@webpack/common"; +import { FluxDispatcher, Menu, React } from "@webpack/common"; const settings = definePluginSettings({ showIcon: { @@ -30,6 +31,11 @@ const settings = definePluginSettings({ description: "Show an icon for toggling the plugin", restartNeeded: true, }, + contextMenu: { + type: OptionType.BOOLEAN, + description: "Add option to toggle the functionality in the chat input context menu", + default: true + }, isEnabled: { type: OptionType.BOOLEAN, description: "Toggle functionality", @@ -56,13 +62,37 @@ const SilentTypingToggle: ChatBarButton = ({ isMainChat }) => { ); }; + +const ChatBarContextCheckbox: NavContextMenuPatchCallback = children => { + const { isEnabled, contextMenu } = settings.use(["isEnabled", "contextMenu"]); + if (!contextMenu) return; + + const group = findGroupChildrenByChildId("submit-button", children); + + if (!group) return; + + const idx = group.findIndex(c => c?.props?.id === "submit-button"); + + group.splice(idx + 1, 0, + settings.store.isEnabled = !settings.store.isEnabled} + /> + ); +}; + + export default definePlugin({ name: "SilentTyping", - authors: [Devs.Ven, Devs.Rini], + authors: [Devs.Ven, Devs.Rini, Devs.ImBanana], description: "Hide that you are typing", dependencies: ["CommandsAPI", "ChatInputButtonAPI"], settings, - + contextMenus: { + "textarea-context": ChatBarContextCheckbox + }, patches: [ { find: '.dispatch({type:"TYPING_START_LOCAL"', diff --git a/src/utils/constants.ts b/src/utils/constants.ts index a0c4752d..6d9950a9 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -461,6 +461,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ GabiRP: { name: "GabiRP", id: 507955112027750401n + }, + ImBanana: { + name: "Im_Banana", + id: 635250116688871425n } } satisfies Record);