VCDoubleClick: Fix applying to non voice channels (#572)

This commit is contained in:
Nuckyz 2023-03-05 22:39:53 -03:00 committed by GitHub
parent 95db6c32a3
commit 36c27f1111
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,7 +19,7 @@
import { migratePluginSettings } from "@api/settings"; import { migratePluginSettings } from "@api/settings";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { SelectedChannelStore } from "@webpack/common"; import { ChannelStore, SelectedChannelStore } from "@webpack/common";
const timers = {} as Record<string, { const timers = {} as Record<string, {
timeout?: NodeJS.Timeout; timeout?: NodeJS.Timeout;
@ -50,12 +50,19 @@ export default definePlugin({
// channel mentions // channel mentions
find: ".shouldCloseDefaultModals", find: ".shouldCloseDefaultModals",
replacement: { replacement: {
match: /onClick:(\i)(?=,.{0,30}className:"channelMention")/, match: /onClick:(\i)(?=,.{0,30}className:"channelMention".+?(\i)\.inContent)/,
replace: "onClick:(_vcEv)=>(_vcEv.detail>=2||_vcEv.target.className.includes('MentionText'))&&($1)()", replace: (_, onClick, props) => ""
+ `onClick:(vcDoubleClickEvt)=>$self.shouldRunOnClick(vcDoubleClickEvt,${props})&&${onClick}()`,
} }
} }
], ],
shouldRunOnClick(e: MouseEvent, { channelId }) {
const channel = ChannelStore.getChannel(channelId);
if (!channel || ![2, 13].includes(channel.type)) return true;
return e.detail >= 2;
},
schedule(cb: () => void, e: any) { schedule(cb: () => void, e: any) {
const id = e.props.channel.id as string; const id = e.props.channel.id as string;
if (SelectedChannelStore.getVoiceChannelId() === id) { if (SelectedChannelStore.getVoiceChannelId() === id) {