diff options
-rw-r--r-- | src/plugins/arRPC.tsx | 22 |
1 files changed, 19 insertions, 3 deletions
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 }); }; |