AccountPanelServerProfile: fix right click menu (#3600)

Co-authored-by: Vendicated <vendicated@riseup.net>
This commit is contained in:
sadan4 2025-08-11 21:28:19 -04:00 committed by GitHub
parent 27b2e97e3f
commit 72329f901c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,7 +11,7 @@ import { getCurrentChannel } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types";
import { User } from "@vencord/discord-types";
import { findComponentByCodeLazy } from "@webpack";
import { ContextMenuApi, Menu, useEffect, useRef } from "@webpack/common";
import { ContextMenuApi, Menu } from "@webpack/common";
interface UserProfileProps {
popoutProps: Record<string, any>;
@ -22,7 +22,7 @@ interface UserProfileProps {
const UserProfile = findComponentByCodeLazy(".POPOUT,user");
let openAlternatePopout = false;
let accountPanelRef: React.RefObject<Record<PropertyKey, any> | null> = { current: null };
let accountPanelRef: React.RefObject<HTMLDivElement | null> = { current: null };
const AccountPanelContextMenu = ErrorBoundary.wrap(() => {
const { prioritizeServerProfile } = settings.use(["prioritizeServerProfile"]);
@ -38,8 +38,7 @@ const AccountPanelContextMenu = ErrorBoundary.wrap(() => {
disabled={getCurrentChannel()?.getGuildId() == null}
action={e => {
openAlternatePopout = true;
accountPanelRef.current?.props.onMouseDown();
accountPanelRef.current?.props.onClick(e);
accountPanelRef.current?.click();
}}
/>
<Menu.MenuCheckboxItem
@ -71,10 +70,6 @@ export default definePlugin({
find: "#{intl::ACCOUNT_SPEAKING_WHILE_MUTED}",
group: true,
replacement: [
{
match: /let{ref:\i,speaking:\i/,
replace: "$self.useAccountPanelRef();$&"
},
{
match: /(\.AVATAR,children:.+?renderPopout:\((\i),\i\)=>){(.+?)}(?=,position)(?<=currentUser:(\i).+?)/,
replace: (_, rest, popoutProps, originalPopout, currentUser) => `${rest}$self.UserProfile({popoutProps:${popoutProps},currentUser:${currentUser},originalRenderPopout:()=>{${originalPopout}}})`
@ -84,8 +79,8 @@ export default definePlugin({
replace: "$&$self.onPopoutClose();"
},
{
match: /(?<=#{intl::SET_STATUS}\),)/,
replace: "ref:$self.accountPanelRef,onContextMenu:$self.openAccountPanelContextMenu,"
match: /#{intl::SET_STATUS}\)(?<=innerRef:(\i),style:.+?)/,
replace: "$&,onContextMenu:($self.grabRef($1),$self.openAccountPanelContextMenu)"
}
]
}
@ -95,12 +90,9 @@ export default definePlugin({
return accountPanelRef;
},
useAccountPanelRef() {
useEffect(() => () => {
accountPanelRef.current = null;
}, []);
return (accountPanelRef = useRef(null));
grabRef(ref: React.RefObject<HTMLDivElement>) {
accountPanelRef = ref;
return ref;
},
openAccountPanelContextMenu(event: React.UIEvent) {