+ Some plugins require a restart to fully disable. +
+Would you like to restart now?
+ > + ), + confirmText: "Restart Now", + cancelText: "Later", + onConfirm: () => resolve(true), + onCancel: () => resolve(false), + }); + }); +} + + +export async function toggleEnabled(name: string) { + let restartNeeded = false; + function onRestartNeeded() { + restartNeeded = true; + } + + async function beforeReturn(settings: any, wasEnabled: boolean) { + if (restartNeeded) { + const confirmed = await restartPrompt(); + if (!confirmed) return false; + + settings.enabled = !wasEnabled; + location.reload(); + return true; + } + + return true; + } + + const plugin = Vencord.Plugins.plugins[name]; + const settings = Settings.plugins[plugin.name]; + const isEnabled = () => settings.enabled ?? false; + const wasEnabled = isEnabled(); + + if (!wasEnabled) { + const { restartNeeded, failures } = Vencord.Plugins.startDependenciesRecursive(plugin); + if (failures.length) { + console.error(`Failed to start dependencies for ${plugin.name}: ${failures.join(", ")}`); + showNotice("Failed to start dependencies: " + failures.join(", "), "Close", () => null); + return; + } else if (restartNeeded) { + settings.enabled = true; + onRestartNeeded(); + return await beforeReturn(settings, wasEnabled); + } + } + + if (plugin.patches?.length) { + onRestartNeeded(); + return await beforeReturn(settings, wasEnabled); + } + + if (wasEnabled && !plugin.started) { + settings.enabled = !wasEnabled; + return false; + } + + const result = wasEnabled ? Vencord.Plugins.stopPlugin(plugin) : Vencord.Plugins.startPlugin(plugin); + + if (!result) { + settings.enabled = false; + const msg = `Error while ${wasEnabled ? "stopping" : "starting"} plugin ${plugin.name}`; + console.error(msg); + showErrorToast(msg); + return await beforeReturn(settings, wasEnabled); + } + + settings.enabled = !wasEnabled; + return await beforeReturn(settings, wasEnabled); +} diff --git a/src/plugins/_core/supportHelper.tsx b/src/plugins/_core/supportHelper.tsx index bc594b365..2efdc8efc 100644 --- a/src/plugins/_core/supportHelper.tsx +++ b/src/plugins/_core/supportHelper.tsx @@ -22,6 +22,7 @@ import ErrorBoundary from "@components/ErrorBoundary"; import { Flex } from "@components/Flex"; import { Link } from "@components/Link"; import { openUpdaterModal } from "@components/VencordSettings/UpdaterTab"; +import { toggleEnabled } from "@equicordplugins/equicordHelper/utils"; import { CONTRIB_ROLE_ID, Devs, DONOR_ROLE_ID, EQUCORD_HELPERS, EQUIBOP_CONTRIB_ROLE_ID, EQUICORD_TEAM, GUILD_ID, SUPPORT_CHANNEL_ID, SUPPORT_CHANNEL_IDS, VC_CONTRIB_ROLE_ID, VC_DONOR_ROLE_ID, VC_GUILD_ID, VC_REGULAR_ROLE_ID, VC_SUPPORT_CHANNEL_IDS, VENCORD_CONTRIB_ROLE_ID } from "@utils/constants"; import { sendMessage } from "@utils/discord"; import { Logger } from "@utils/Logger"; @@ -295,11 +296,14 @@ export default definePlugin({ const shouldAddUpdateButton = !IS_UPDATER_DISABLED - && ( - (props.channel.id === SUPPORT_CHANNEL_ID && equicordSupport) - ) + && ((props.channel.id === SUPPORT_CHANNEL_ID && equicordSupport)) && props.message.content?.includes("update"); + const matchedPlugins = Object.keys(Vencord.Plugins.plugins).filter(name => (props.message.content?.toLowerCase() ?? "").includes(name.toLowerCase())); + const matchedPlugin = matchedPlugins.sort((a, b) => b.length - a.length)[0]; + const equicordGuild = ChannelStore.getChannel(props.channel.id)?.guild_id === GUILD_ID; + const shouldAddPluginButtons = equicordGuild && equicordSupport && matchedPlugin; + if (shouldAddUpdateButton) { buttons.push( + ); + } + if (props.channel.id === SUPPORT_CHANNEL_ID && PermissionStore.can(PermissionsBits.SEND_MESSAGES, props.channel)) { if (props.message.content.includes("/equicord-debug") || props.message.content.includes("/equicord-plugins")) { buttons.push( From 3df2582053b2a14852e400fc6c405f3dcb632ccc Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Mon, 7 Jul 2025 16:06:11 -0400 Subject: [PATCH 6/6] Misc Fixes --- src/equicordplugins/equicordHelper/utils.tsx | 6 +++--- src/plugins/_core/supportHelper.tsx | 7 +------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/equicordplugins/equicordHelper/utils.tsx b/src/equicordplugins/equicordHelper/utils.tsx index 5840844e2..03ba6e8cd 100644 --- a/src/equicordplugins/equicordHelper/utils.tsx +++ b/src/equicordplugins/equicordHelper/utils.tsx @@ -69,7 +69,7 @@ export async function toggleEnabled(name: string) { if (failures.length) { console.error(`Failed to start dependencies for ${plugin.name}: ${failures.join(", ")}`); showNotice("Failed to start dependencies: " + failures.join(", "), "Close", () => null); - return; + return false; } else if (restartNeeded) { settings.enabled = true; onRestartNeeded(); @@ -84,7 +84,7 @@ export async function toggleEnabled(name: string) { if (wasEnabled && !plugin.started) { settings.enabled = !wasEnabled; - return false; + return await beforeReturn(settings, wasEnabled); } const result = wasEnabled ? Vencord.Plugins.stopPlugin(plugin) : Vencord.Plugins.startPlugin(plugin); @@ -94,7 +94,7 @@ export async function toggleEnabled(name: string) { const msg = `Error while ${wasEnabled ? "stopping" : "starting"} plugin ${plugin.name}`; console.error(msg); showErrorToast(msg); - return await beforeReturn(settings, wasEnabled); + return false; } settings.enabled = !wasEnabled; diff --git a/src/plugins/_core/supportHelper.tsx b/src/plugins/_core/supportHelper.tsx index 2efdc8efc..23a197020 100644 --- a/src/plugins/_core/supportHelper.tsx +++ b/src/plugins/_core/supportHelper.tsx @@ -336,12 +336,7 @@ export default definePlugin({ onClick={async () => { try { const success = await toggleEnabled(matchedPlugin); - if (success) { - showToast( - `${isEnabled ? "Disabled" : "Enabled"} ${matchedPlugin}`, - Toasts.Type.SUCCESS - ); - } + if (success) showToast(`${isEnabled ? "Disabled" : "Enabled"} ${matchedPlugin}`, Toasts.Type.SUCCESS); } catch (e) { new Logger(this.name).error("Error while toggling:", e); showToast(`Failed to toggle ${matchedPlugin}`, Toasts.Type.FAILURE);