diff --git a/src/plugins/xsOverlay/index.tsx b/src/plugins/xsOverlay/index.tsx index ab76a0e79..12dbf6b61 100644 --- a/src/plugins/xsOverlay/index.tsx +++ b/src/plugins/xsOverlay/index.tsx @@ -8,7 +8,7 @@ import { definePluginSettings } from "@api/Settings"; import { makeRange } from "@components/PluginSettings/components"; import { Devs } from "@utils/constants"; 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 { Button, ChannelStore, GuildStore, UserStore } from "@webpack/common"; import type { Channel, Embed, GuildMember, MessageAttachment, User } from "discord-types/general"; @@ -102,6 +102,12 @@ const settings = definePluginSettings({ 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: { type: OptionType.BOOLEAN, description: "Allow bot notifications", @@ -178,6 +184,8 @@ async function start() { }); } +const Native = VencordNative.pluginHelpers.XSOverlay as PluginNative; + export default definePlugin({ name: "XSOverlay", 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) { + if (!IS_WEB && settings.store.preferUDP) { + Native.sendToOverlay(notif); + return; + } const apiObject: ApiObject = { sender: "Vencord", target: "xsoverlay", diff --git a/src/plugins/xsOverlay/native.ts b/src/plugins/xsOverlay/native.ts new file mode 100644 index 000000000..75ddfeea5 --- /dev/null +++ b/src/plugins/xsOverlay/native.ts @@ -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"); +}