diff options
author | Nuckyz <61953774+Nuckyz@users.noreply.github.com> | 2023-04-18 01:54:21 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-18 04:54:21 +0000 |
commit | c0ac6a4b8696c3506e7b900cbac11b6b984495d8 (patch) | |
tree | b30250c750a311b22ad4d9c57e5883bb9f714b03 /src | |
parent | 29749e93c7ecf67160aed316438f5b9f669cca98 (diff) | |
download | Vencord-c0ac6a4b8696c3506e7b900cbac11b6b984495d8.tar.gz Vencord-c0ac6a4b8696c3506e7b900cbac11b6b984495d8.tar.bz2 Vencord-c0ac6a4b8696c3506e7b900cbac11b6b984495d8.zip |
SilentMessageToggle: Option to persist state (#941)
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/silentMessageToggle.tsx | 28 |
1 files changed, 24 insertions, 4 deletions
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: { <div style={{ display: "flex" }}> <Button {...tooltipProps} - onClick={() => setEnabled(prev => !prev)} + onClick={() => setEnabledValue(!enabled)} size="" look={ButtonLooks.BLANK} innerClassName={ButtonWrapperClasses.button} @@ -79,6 +98,7 @@ export default definePlugin({ name: "SilentMessageToggle", authors: [Devs.Nuckyz], description: "Adds a button to the chat bar to toggle sending a silent message.", + settings, patches: [ { find: ".activeCommandOption", |