diff --git a/src/equicordplugins/hideChatButtons/index.tsx b/src/equicordplugins/hideChatButtons/index.tsx index 0c9dd37f5..cfb366b27 100644 --- a/src/equicordplugins/hideChatButtons/index.tsx +++ b/src/equicordplugins/hideChatButtons/index.tsx @@ -63,7 +63,8 @@ function ButtonsInnerComponent({ buttons }: { buttons: ReactNode[]; }) {
{open && buttons.map((b, i) => {b})} setOpen(!open)} open={open} /> @@ -89,7 +90,10 @@ export default definePlugin({ buttonsInner(buttons: ReactNode[]) { return ; }, - async start() { + start() { hidechatbuttonsopen = settings.store.Open; + }, + stop() { + hidechatbuttonsopen = undefined; } }); diff --git a/src/plugins/betterGifPicker/index.ts b/src/plugins/betterGifPicker/index.ts index 9d7d8db41..184664b5a 100644 --- a/src/plugins/betterGifPicker/index.ts +++ b/src/plugins/betterGifPicker/index.ts @@ -4,13 +4,32 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -import { Devs } from "@utils/constants"; -import definePlugin from "@utils/types"; +import { definePluginSettings } from "@api/Settings"; +import { Devs, EquicordDevs } from "@utils/constants"; +import definePlugin, { makeRange, OptionType } from "@utils/types"; + +let closeSuppressCount = 0; +const settings = definePluginSettings({ + keepOpen: { + description: "Keeps the gif picker open after selecting a gif", + type: OptionType.BOOLEAN, + default: false + }, + gifAmount: { + description: "Keeps the gif picker open after selecting a gif", + type: OptionType.SLIDER, + default: 2, + markers: makeRange(1, 20, 1), + stickToMarkers: true + } +}); export default definePlugin({ name: "BetterGifPicker", description: "Makes the gif picker open the favourite category by default", - authors: [Devs.Samwich], + authors: [Devs.Samwich, EquicordDevs.justjxke], + isModified: true, + settings, patches: [ { find: '"state",{resultType:', @@ -18,6 +37,52 @@ export default definePlugin({ match: /(?<="state",{resultType:)null/, replace: '"Favorites"' }] + }, + { + find: "#{intl::NO_GIF_FAVORITES_HOW_TO_FAVORITE}", + predicate: () => settings.store.keepOpen, + replacement: [ + { + match: /null!=\i&&\i\(\i\),/, + replace: "$self.onGifSelect(),$&" + }, + { + match: /\i\.scrollIntoViewRect\(\{/, + replace: "$self.shouldSuppressGifFocusScroll()||$&" + }, + { + match: /this.renderGIF\(\).{0,50}\]/, + replace: "$&,onMouseDown:e=>{$self.shouldSuppressGifFocusScroll()&&e.preventDefault()}" + } + ] + }, + { + find: "expression-picker-last-active-view", + replacement: { + match: /\i\.setState\(\{activeView:null/, + replace: "$self.consumeCloseSuppress()||$&" + } + }, + ], + + onGifSelect() { + if (!settings.store.keepOpen) return; + + closeSuppressCount = settings.store.gifAmount; + }, + + consumeCloseSuppress() { + if (!settings.store.keepOpen) { + closeSuppressCount = 0; + return false; } - ] + + if (closeSuppressCount <= 0) return false; + closeSuppressCount--; + return true; + }, + + shouldSuppressGifFocusScroll() { + return settings.store.keepOpen; + } }); diff --git a/src/plugins/gifPaste/index.ts b/src/plugins/gifPaste/index.ts index b2b4305d8..97fed9613 100644 --- a/src/plugins/gifPaste/index.ts +++ b/src/plugins/gifPaste/index.ts @@ -16,6 +16,8 @@ * along with this program. If not, see . */ +import { isPluginEnabled } from "@api/PluginManager"; +import betterGifPicker from "@plugins/betterGifPicker"; import { Devs } from "@utils/constants"; import { insertTextIntoChatInputBox } from "@utils/discord"; import definePlugin from "@utils/types"; @@ -37,7 +39,10 @@ export default definePlugin({ handleSelect(gif?: { url: string; }) { if (gif) { insertTextIntoChatInputBox(gif.url + " "); - ExpressionPickerStore.closeExpressionPicker(); + + if (!(isPluginEnabled(betterGifPicker.name) && betterGifPicker.settings.store.keepOpen)) { + ExpressionPickerStore.closeExpressionPicker(); + } } } });