diff options
author | CanadaHonk <19228318+CanadaHonk@users.noreply.github.com> | 2022-11-20 15:21:42 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-20 16:21:42 +0100 |
commit | 9240865f65112f9fee5187e9f5fcdd5ed2758285 (patch) | |
tree | f54e01b9186ce0d340a886c455675b15ddea3c85 /src/plugins/arRPC.tsx | |
parent | e85d763f2273dd95e9fdf3112896e28bd4a39feb (diff) | |
download | Vencord-9240865f65112f9fee5187e9f5fcdd5ed2758285.tar.gz Vencord-9240865f65112f9fee5187e9f5fcdd5ed2758285.tar.bz2 Vencord-9240865f65112f9fee5187e9f5fcdd5ed2758285.zip |
feat(arRPC): update for server 2.0 (#224)
Diffstat (limited to 'src/plugins/arRPC.tsx')
-rw-r--r-- | src/plugins/arRPC.tsx | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/plugins/arRPC.tsx b/src/plugins/arRPC.tsx index bfacb6f..54a7473 100644 --- a/src/plugins/arRPC.tsx +++ b/src/plugins/arRPC.tsx @@ -16,12 +16,24 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { popNotice,showNotice } from "../api/Notices"; +import { popNotice, showNotice } from "../api/Notices"; import { Link } from "../components/Link"; import { Devs } from "../utils/constants"; import definePlugin from "../utils/types"; +import { Webpack } from "../Vencord"; import { FluxDispatcher, Forms, Toasts } from "../webpack/common"; +const assetManager = Webpack.mapMangledModuleLazy( + "getAssetImage: size must === [number, number] for Twitch", + { + getAsset: Webpack.filters.byCode("apply("), + } +); + +async function lookupAsset(applicationId: string, key: string): Promise<string> { + return (await assetManager.getAsset(applicationId, [key, undefined]))[0]; +} + let ws: WebSocket; export default definePlugin({ name: "WebRichPresence (arRPC)", @@ -42,8 +54,12 @@ export default definePlugin({ if (ws) ws.close(); ws = new WebSocket("ws://127.0.0.1:1337"); // try to open WebSocket - ws.onmessage = e => { // on message, set status to data + ws.onmessage = async e => { // on message, set status to data const data = JSON.parse(e.data); + + 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); + FluxDispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", ...data }); }; |