From 56442ae1e92a8ed010377d5762bbd80ca3de0c3a Mon Sep 17 00:00:00 2001 From: Cookie <52550063+Covkie@users.noreply.github.com> Date: Wed, 5 Feb 2025 14:00:40 -0500 Subject: [PATCH] feat(rpc): implement arrpc's `link` event (#1016) Co-authored-by: Vendicated --- src/main/arrpc.ts | 3 +++ src/renderer/arrpc.ts | 14 +++++++++++++- src/renderer/index.ts | 10 ++++------ src/renderer/patches/index.ts | 1 + src/renderer/patches/nativeFocus.tsx | 23 +++++++++++++++++++++++ src/shared/IpcEvents.ts | 1 + 6 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 src/renderer/patches/nativeFocus.tsx diff --git a/src/main/arrpc.ts b/src/main/arrpc.ts index b3b5c95..da29a77 100644 --- a/src/main/arrpc.ts +++ b/src/main/arrpc.ts @@ -26,6 +26,9 @@ export async function initArRPC() { await sendRendererCommand(IpcCommands.RPC_INVITE, invite).then(callback); }); + server.on("link", async (data: any, deepCallback: (valid: boolean) => void) => { + await sendRendererCommand(IpcCommands.RPC_DEEP_LINK, data).then(deepCallback); + }); } catch (e) { console.error("Failed to start arRPC server", e); } diff --git a/src/renderer/arrpc.ts b/src/renderer/arrpc.ts index ecf5319..e78e7a9 100644 --- a/src/renderer/arrpc.ts +++ b/src/renderer/arrpc.ts @@ -4,7 +4,7 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ -import { onceReady } from "@vencord/types/webpack"; +import { findLazy, onceReady } from "@vencord/types/webpack"; import { FluxDispatcher, InviteActions } from "@vencord/types/webpack/common"; import { IpcCommands } from "shared/IpcEvents"; @@ -38,3 +38,15 @@ onIpcCommand(IpcCommands.RPC_INVITE, async code => { return true; }); + +const { DEEP_LINK } = findLazy(m => m.DEEP_LINK?.handler); + +onIpcCommand(IpcCommands.RPC_DEEP_LINK, async data => { + try { + DEEP_LINK.handler({ args: data }); + return true; + } catch (err) { + console.error("[RPC]", "Failed to open deep link:", err, data); + return false; + } +}); diff --git a/src/renderer/index.ts b/src/renderer/index.ts index 656acd2..6e0459d 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -4,25 +4,23 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ -import "./fixes"; -import "./appBadge"; -import "./patches"; import "./themedSplash"; import "./ipcCommands"; +import "./appBadge"; +import "./patches"; +import "./fixes"; import "./arrpc"; console.log("read if cute :3"); export * as Components from "./components"; -import { findByPropsLazy, onceReady } from "@vencord/types/webpack"; +import { onceReady } from "@vencord/types/webpack"; import { Alerts } from "@vencord/types/webpack/common"; import SettingsUi from "./components/settings/Settings"; import { Settings } from "./settings"; export { Settings }; -const InviteActions = findByPropsLazy("resolveInvite"); - const customSettingsSections = ( Vencord.Plugins.plugins.Settings as any as { customSections: ((ID: Record) => any)[] } ).customSections; diff --git a/src/renderer/patches/index.ts b/src/renderer/patches/index.ts index aabff3e..1bcf9df 100644 --- a/src/renderer/patches/index.ts +++ b/src/renderer/patches/index.ts @@ -12,3 +12,4 @@ import "./hideVenmicInput"; import "./screenShareFixes"; import "./spellCheck"; import "./windowsTitleBar"; +import "./nativeFocus"; diff --git a/src/renderer/patches/nativeFocus.tsx b/src/renderer/patches/nativeFocus.tsx new file mode 100644 index 0000000..475577d --- /dev/null +++ b/src/renderer/patches/nativeFocus.tsx @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Vesktop, a desktop app aiming to give you a snappier Discord Experience + * Copyright (c) 2023 Vendicated and Vencord contributors + */ + +import { addPatch } from "./shared"; + +addPatch({ + patches: [ + { + find: ".DEEP_LINK]:{", + replacement: [ + { + // TODO: Fix eslint rule + // eslint-disable-next-line no-useless-escape + match: /(?<=\.DEEP_LINK.{0,200}?)\i\.\i\.focus\(\)/, + replace: "VesktopNative.win.focus()" + } + ] + } + ] +}); diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index 2de1c34..4fdd736 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -61,6 +61,7 @@ export const enum IpcEvents { export const enum IpcCommands { RPC_ACTIVITY = "rpc:activity", RPC_INVITE = "rpc:invite", + RPC_DEEP_LINK = "rpc:link", NAVIGATE_SETTINGS = "navigate:settings", GET_LANGUAGES = "navigator.languages" }