feat(arRPC): update for server 2.2 (#230)
This commit is contained in:
parent
46b14cb2e0
commit
9bcdc8451f
@ -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 });
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user