diff --git a/src/plugins/silentMessageToggle.tsx b/src/plugins/silentMessageToggle.tsx index df52f41..f90ba8a 100644 --- a/src/plugins/silentMessageToggle.tsx +++ b/src/plugins/silentMessageToggle.tsx @@ -17,22 +17,41 @@ */ import { addPreSendListener, removePreSendListener, SendListener } from "@api/MessageEvents"; +import { definePluginSettings } from "@api/settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; -import definePlugin from "@utils/types"; +import definePlugin, { OptionType } from "@utils/types"; import { Button, ButtonLooks, ButtonWrapperClasses, React, Tooltip } from "@webpack/common"; +let lastState = false; + +const settings = definePluginSettings({ + persistState: { + type: OptionType.BOOLEAN, + description: "Whether to persist the state of the silent message toggle when changing channels", + default: false, + onChange(newValue: boolean) { + if (newValue === false) lastState = false; + } + } +}); + function SilentMessageToggle(chatBoxProps: { type: { analyticsName: string; }; }) { - const [enabled, setEnabled] = React.useState(false); + const [enabled, setEnabled] = React.useState(lastState); + + function setEnabledValue(value: boolean) { + if (settings.store.persistState) lastState = value; + setEnabled(value); + } React.useEffect(() => { const listener: SendListener = (_, message) => { if (enabled) { - setEnabled(false); + setEnabledValue(false); if (!message.content.startsWith("@silent ")) message.content = "@silent " + message.content; } }; @@ -49,7 +68,7 @@ function SilentMessageToggle(chatBoxProps: {