From 9bcdc8451f2d1e9904303a61eab70c58aebb4dad Mon Sep 17 00:00:00 2001
From: CanadaHonk <19228318+CanadaHonk@users.noreply.github.com>
Date: Sun, 20 Nov 2022 23:57:30 +0000
Subject: feat(arRPC): update for server 2.2 (#230)

---
 src/plugins/arRPC.tsx | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

(limited to 'src/plugins/arRPC.tsx')

diff --git a/src/plugins/arRPC.tsx b/src/plugins/arRPC.tsx
index 54a7473..a9b2f3c 100644
--- a/src/plugins/arRPC.tsx
+++ b/src/plugins/arRPC.tsx
@@ -19,21 +19,31 @@
 import { popNotice, showNotice } from "../api/Notices";
 import { Link } from "../components/Link";
 import { Devs } from "../utils/constants";
+import { lazyWebpack } from "../utils/misc";
 import definePlugin from "../utils/types";
-import { Webpack } from "../Vencord";
+import { filters, mapMangledModuleLazy } from "../webpack";
 import { FluxDispatcher, Forms, Toasts } from "../webpack/common";
 
-const assetManager = Webpack.mapMangledModuleLazy(
+const assetManager = mapMangledModuleLazy(
     "getAssetImage: size must === [number, number] for Twitch",
     {
-        getAsset: Webpack.filters.byCode("apply("),
+        getAsset: filters.byCode("apply("),
     }
 );
 
+const rpcManager = lazyWebpack(filters.byCode(".APPLICATION_RPC("));
+
 async function lookupAsset(applicationId: string, key: string): Promise<string> {
     return (await assetManager.getAsset(applicationId, [key, undefined]))[0];
 }
 
+const apps: any = {};
+async function lookupApp(applicationId: string): Promise<string> {
+    const socket: any = {};
+    await rpcManager.lookupApp(socket, applicationId);
+    return socket.application;
+}
+
 let ws: WebSocket;
 export default definePlugin({
     name: "WebRichPresence (arRPC)",
@@ -60,6 +70,12 @@ export default definePlugin({
             if (data.activity?.assets?.large_image) data.activity.assets.large_image = await lookupAsset(data.activity.application_id, data.activity.assets.large_image);
             if (data.activity?.assets?.small_image) data.activity.assets.small_image = await lookupAsset(data.activity.application_id, data.activity.assets.small_image);
 
+            const appId = data.activity.application_id;
+            if (!apps[appId]) apps[appId] = await lookupApp(appId);
+
+            const app = apps[appId];
+            if (!data.activity.name) data.activity.name = app.name;
+
             FluxDispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", ...data });
         };
 
-- 
cgit 

