diff options
author | CanadaHonk <19228318+CanadaHonk@users.noreply.github.com> | 2022-11-20 23:57:30 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-21 00:57:30 +0100 |
commit | 9bcdc8451f2d1e9904303a61eab70c58aebb4dad (patch) | |
tree | e3baa5492e82eba08ab6d366188c43043d8cc4b2 /src/plugins/arRPC.tsx | |
parent | 46b14cb2e087ba251da5b73d04b0dc6a4d22d40f (diff) | |
download | Vencord-9bcdc8451f2d1e9904303a61eab70c58aebb4dad.tar.gz Vencord-9bcdc8451f2d1e9904303a61eab70c58aebb4dad.tar.bz2 Vencord-9bcdc8451f2d1e9904303a61eab70c58aebb4dad.zip |
feat(arRPC): update for server 2.2 (#230)
Diffstat (limited to 'src/plugins/arRPC.tsx')
-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 }); }; |