2025-02-02 03:17:37 +01:00
|
|
|
/*
|
|
|
|
|
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
|
2025-02-07 04:16:15 +01:00
|
|
|
* Copyright (c) 2025 Vendicated and Vencord contributors
|
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2025-02-02 03:17:37 +01:00
|
|
|
*/
|
|
|
|
|
|
2025-12-12 20:58:16 +01:00
|
|
|
import type arRpcPlugin from "@vencord/types/plugins/arRPC.web";
|
2025-02-06 04:00:14 +01:00
|
|
|
import { Logger } from "@vencord/types/utils";
|
2025-02-05 14:12:38 -05:00
|
|
|
import { findLazy, findStoreLazy, onceReady } from "@vencord/types/webpack";
|
2025-02-02 03:17:37 +01:00
|
|
|
import { FluxDispatcher, InviteActions } from "@vencord/types/webpack/common";
|
|
|
|
|
import { IpcCommands } from "shared/IpcEvents";
|
|
|
|
|
|
|
|
|
|
import { onIpcCommand } from "./ipcCommands";
|
|
|
|
|
import { Settings } from "./settings";
|
|
|
|
|
|
2025-02-06 04:00:14 +01:00
|
|
|
const logger = new Logger("VesktopRPC", "#5865f2");
|
2025-02-05 14:12:38 -05:00
|
|
|
const StreamerModeStore = findStoreLazy("StreamerModeStore");
|
|
|
|
|
|
2025-12-12 20:58:16 +01:00
|
|
|
const arRPC = Vencord.Plugins.plugins["WebRichPresence (arRPC)"] as typeof arRpcPlugin;
|
2025-02-02 03:17:37 +01:00
|
|
|
|
2025-02-05 14:12:38 -05:00
|
|
|
onIpcCommand(IpcCommands.RPC_ACTIVITY, async jsonData => {
|
2025-02-02 03:17:37 +01:00
|
|
|
if (!Settings.store.arRPC) return;
|
|
|
|
|
|
|
|
|
|
await onceReady;
|
|
|
|
|
|
2025-02-05 14:12:38 -05:00
|
|
|
const data = JSON.parse(jsonData);
|
|
|
|
|
|
|
|
|
|
if (data.socketId === "STREAMERMODE" && StreamerModeStore.autoToggle) {
|
|
|
|
|
FluxDispatcher.dispatch({
|
|
|
|
|
type: "STREAMER_MODE_UPDATE",
|
|
|
|
|
key: "enabled",
|
|
|
|
|
value: data.activity?.application_id === "STREAMERMODE"
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
arRPC.handleEvent(new MessageEvent("message", { data: jsonData }));
|
2025-02-02 03:17:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
onIpcCommand(IpcCommands.RPC_INVITE, async code => {
|
|
|
|
|
const { invite } = await InviteActions.resolveInvite(code, "Desktop Modal");
|
|
|
|
|
if (!invite) return false;
|
|
|
|
|
|
|
|
|
|
VesktopNative.win.focus();
|
|
|
|
|
|
|
|
|
|
FluxDispatcher.dispatch({
|
|
|
|
|
type: "INVITE_MODAL_OPEN",
|
|
|
|
|
invite,
|
|
|
|
|
code,
|
|
|
|
|
context: "APP"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
});
|
2025-02-05 14:00:40 -05:00
|
|
|
|
|
|
|
|
const { DEEP_LINK } = findLazy(m => m.DEEP_LINK?.handler);
|
|
|
|
|
|
|
|
|
|
onIpcCommand(IpcCommands.RPC_DEEP_LINK, async data => {
|
2025-02-06 04:00:14 +01:00
|
|
|
logger.debug("Opening deep link:", data);
|
2025-02-05 14:00:40 -05:00
|
|
|
try {
|
|
|
|
|
DEEP_LINK.handler({ args: data });
|
|
|
|
|
return true;
|
|
|
|
|
} catch (err) {
|
2025-02-06 04:00:14 +01:00
|
|
|
logger.error("Failed to open deep link:", err);
|
2025-02-05 14:00:40 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|