Merge remote-tracking branch 'upstream/dev' into dev

This commit is contained in:
thororen1234 2024-08-03 00:24:55 -04:00
commit 68050022f3
6 changed files with 38 additions and 11 deletions

View file

@ -18,14 +18,14 @@
import { Logger } from "@utils/Logger"; import { Logger } from "@utils/Logger";
import { Channel, Message } from "discord-types/general"; import { Channel, Message } from "discord-types/general";
import type { MouseEventHandler } from "react"; import type { ComponentType, MouseEventHandler, ReactElement } from "react";
const logger = new Logger("MessagePopover"); const logger = new Logger("MessagePopover");
export interface ButtonItem { export interface ButtonItem {
key?: string, key?: string,
label: string, label: string,
icon: React.ComponentType<any>, icon: ComponentType<any>,
message: Message, message: Message,
channel: Channel, channel: Channel,
onClick?: MouseEventHandler<HTMLButtonElement>, onClick?: MouseEventHandler<HTMLButtonElement>,
@ -49,16 +49,16 @@ export function removeButton(identifier: string) {
export function _buildPopoverElements( export function _buildPopoverElements(
msg: Message, msg: Message,
makeButton: (item: ButtonItem) => React.ComponentType PopoverButton: ComponentType<ButtonItem>,
) { ) {
const items = [] as React.ComponentType[]; const items = [] as ReactElement[];
for (const [identifier, getItem] of buttons.entries()) { for (const [identifier, getItem] of buttons.entries()) {
try { try {
const item = getItem(msg); const item = getItem(msg);
if (item) { if (item) {
item.key ??= identifier; item.key ??= identifier;
items.push(makeButton(item)); items.push(<PopoverButton {...item} />);
} }
} catch (err) { } catch (err) {
logger.error(`[${identifier}]`, err); logger.error(`[${identifier}]`, err);

View file

@ -26,9 +26,8 @@ export default definePlugin({
patches: [{ patches: [{
find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL", find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL",
replacement: { replacement: {
// foo && !bar ? createElement(reactionStuffs)... createElement(blah,...makeElement(reply-other)) match: /"reply-self".+?Fragment,{children:\[(?=.+?\((\i\.\i),{label:)(?<=message:(\i).+?)/,
match: /\i&&!\i\?\(0,\i\.jsxs?\)\(.{0,200}renderEmojiPicker:.{0,500}\?(\i)\(\{key:"reply-other"(?<=message:(\i).+?)/, replace: (m, PopoverButton, msg) => `${m}...Vencord.Api.MessagePopover._buildPopoverElements(${msg},${PopoverButton}),`
replace: (m, makeElement, msg) => `...Vencord.Api.MessagePopover._buildPopoverElements(${msg},${makeElement}),${m}`
} }
}], }],
}); });

View file

@ -27,7 +27,7 @@ export default definePlugin({
authors: [Devs.D3SOX, Devs.Nickyux], authors: [Devs.D3SOX, Devs.Nickyux],
patches: [ patches: [
{ {
find: ".PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP", find: ".Messages.GUILD_OWNER,",
replacement: { replacement: {
match: /,isOwner:(\i),/, match: /,isOwner:(\i),/,
replace: ",_isOwner:$1=$self.isGuildOwner(e)," replace: ",_isOwner:$1=$self.isGuildOwner(e),"

View file

@ -311,7 +311,7 @@ export default definePlugin({
replacement: [ replacement: [
{ {
// Create a variable for the channel prop // Create a variable for the channel prop
match: /maxUsers:\i,users:\i.+?}=(\i).*?;/, match: /users:\i,maxUsers:\i.+?}=(\i).*?;/,
replace: (m, props) => `${m}let{shcChannel}=${props};` replace: (m, props) => `${m}let{shcChannel}=${props};`
}, },
{ {

View file

@ -8,7 +8,7 @@ import { definePluginSettings } from "@api/Settings";
import { makeRange } from "@components/PluginSettings/components"; import { makeRange } from "@components/PluginSettings/components";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { Logger } from "@utils/Logger"; import { Logger } from "@utils/Logger";
import definePlugin, { OptionType, ReporterTestable } from "@utils/types"; import definePlugin, { OptionType, PluginNative, ReporterTestable } from "@utils/types";
import { findByCodeLazy, findLazy } from "@webpack"; import { findByCodeLazy, findLazy } from "@webpack";
import { Button, ChannelStore, GuildStore, UserStore } from "@webpack/common"; import { Button, ChannelStore, GuildStore, UserStore } from "@webpack/common";
import type { Channel, Embed, GuildMember, MessageAttachment, User } from "discord-types/general"; import type { Channel, Embed, GuildMember, MessageAttachment, User } from "discord-types/general";
@ -102,6 +102,12 @@ const settings = definePluginSettings({
await start(); await start();
} }
}, },
preferUDP: {
type: OptionType.BOOLEAN,
description: "Enable if you use an older build of XSOverlay unable to connect through websockets. This setting is ignored on web.",
default: false,
disabled: () => IS_WEB
},
botNotifications: { botNotifications: {
type: OptionType.BOOLEAN, type: OptionType.BOOLEAN,
description: "Allow bot notifications", description: "Allow bot notifications",
@ -178,6 +184,8 @@ async function start() {
}); });
} }
const Native = VencordNative.pluginHelpers.XSOverlay as PluginNative<typeof import("./native")>;
export default definePlugin({ export default definePlugin({
name: "XSOverlay", name: "XSOverlay",
description: "Forwards discord notifications to XSOverlay, for easy viewing in VR", description: "Forwards discord notifications to XSOverlay, for easy viewing in VR",
@ -349,6 +357,10 @@ function sendOtherNotif(content: string, titleString: string) {
} }
async function sendToOverlay(notif: NotificationObject) { async function sendToOverlay(notif: NotificationObject) {
if (!IS_WEB && settings.store.preferUDP) {
Native.sendToOverlay(notif);
return;
}
const apiObject: ApiObject = { const apiObject: ApiObject = {
sender: "Vencord", sender: "Vencord",
target: "xsoverlay", target: "xsoverlay",

View file

@ -0,0 +1,16 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2023 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { createSocket, Socket } from "dgram";
let xsoSocket: Socket;
export function sendToOverlay(_, data: any) {
data.messageType = data.type;
const json = JSON.stringify(data);
xsoSocket ??= createSocket("udp4");
xsoSocket.send(json, 42069, "127.0.0.1");
}