feat/betterGifPicker (#558)

* Keep gif picker open setting

* fixes

* Fixes x2

* fix patches

* Update index.ts

* Update index.ts

* range

---------

Co-authored-by: thororen1234 <78185467+thororen1234@users.noreply.github.com>
This commit is contained in:
Jake 2025-12-15 06:22:04 +00:00 • committed by GitHub
parent cc5e757540
commit 991d9f5f53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 81 additions and 7 deletions

View file

@ -63,7 +63,8 @@ function ButtonsInnerComponent({ buttons }: { buttons: ReactNode[]; }) {
<div key="chat-bar-buttons-menu" id="chat-bar-buttons-menu" style={{
display: "flex",
flexWrap: "nowrap",
overflowX: "auto"
overflowX: "auto",
overflowY: "hidden"
}}>
{open && buttons.map((b, i) => <React.Fragment key={i}>{b}</React.Fragment>)}
<HideToggleButton onClick={() => setOpen(!open)} open={open} />
@ -89,7 +90,10 @@ export default definePlugin({
buttonsInner(buttons: ReactNode[]) {
return <ButtonsInnerComponent buttons={buttons} />;
},
async start() {
start() {
hidechatbuttonsopen = settings.store.Open;
},
stop() {
hidechatbuttonsopen = undefined;
}
});

View file

@ -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;
}
});

View file

@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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();
}
}
}
});