fix arRPC bridge (#528)

* fix aRPC bridge

* fix formatting
This commit is contained in:
Angelos Bouklis 2023-12-02 21:02:55 +02:00 committed by GitHub
parent c8107ef588
commit b5a6a2b579
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,87 +1,97 @@
window.addEventListener( window.addEventListener("load", async () => {
"load", let Dispatcher = undefined,
(() => { lookupAsset = undefined,
let Dispatcher, lookupApp = undefined;
lookupAsset,
lookupApp,
apps = {};
ArmCordRPC.listen(async (data) => { let apps = {};
msg = data; //already parsed const chunkName = 'webpackChunkdiscord_app';
//console.log(msg);
if (!Dispatcher) { const wpRequire = window[chunkName].push(
const wpRequire = window.webpackChunkdiscord_app.push([[Symbol()], {}, (x) => x]); [ [Symbol()], {}, (x) => x ]
const cache = wpRequire.c; );
window.webpackChunkdiscord_app.pop();
for (const id in cache) { const cache = wpRequire.c;
let mod = cache[id].exports; window[chunkName].pop();
for (const prop in mod) {
const candidate = mod[prop];
if (candidate && candidate.register && candidate.wait) {
Dispatcher = candidate;
break;
}
}
if (Dispatcher) break; // make sure to exit outer loop as well
}
const factories = wpRequire.m; for (const id in cache) {
for (const id in factories) { let mod = cache[id].exports;
if (factories[id].toString().includes("getAssetImage: size must === [number, number] for Twitch")) { if (typeof mod !== "object") continue;
const mod = wpRequire(id);
// fetchAssetIds let candidates;
const _lookupAsset = Object.values(mod).find( try {
(e) => typeof e === "function" && e.toString().includes("APPLICATION_ASSETS_FETCH_SUCCESS") candidates = Object.values(mod);
); } catch {
if (_lookupAsset) continue;
lookupAsset = async (appId, name) => (await _lookupAsset(appId, [name, undefined]))[0]; }
}
if (lookupAsset) break;
}
for (const id in factories) { for (const candidate of candidates) {
if (factories[id].toString().includes("APPLICATION_RPC")) { if (candidate && candidate.register && candidate.wait) {
const mod = wpRequire(id); Dispatcher = candidate;
break;
}
}
}
// fetchApplicationsRPC const factories = wpRequire.m;
const _lookupApp = Object.values(mod).find( for (const id in factories) {
(e) => typeof e === "function" && e.toString().includes(",coverImage:") if (
); factories[id]
if (_lookupApp) .toString()
lookupApp = async (appId) => { .includes("getAssetImage: size must === [number, number] for Twitch")
let socket = {}; ) {
await _lookupApp(socket, appId); const mod = wpRequire(id);
return socket.application;
};
}
if (lookupApp) break;
}
}
if (msg.activity?.assets?.large_image) // fetchAssetIds
msg.activity.assets.large_image = await lookupAsset( const _lookupAsset = Object.values(mod).find(
msg.activity.application_id, (e) =>
msg.activity.assets.large_image typeof e === "function" &&
); e.toString().includes("APPLICATION_ASSETS_FETCH_SUCCESS"),
if (msg.activity?.assets?.small_image) );
msg.activity.assets.small_image = await lookupAsset( if (_lookupAsset)
msg.activity.application_id, lookupAsset = async (appId, name) =>
msg.activity.assets.small_image (await _lookupAsset(appId, [name, undefined]))[0];
); }
if (lookupAsset) break;
}
// prevent errors when activity is null and let activity stop for (const id in factories) {
if (msg.activity) { if (factories[id].toString().includes("APPLICATION_RPC")) {
const appId = msg.activity.application_id; const mod = wpRequire(id);
if (!apps[appId]) apps[appId] = await lookupApp(appId);
const app = apps[appId]; // fetchApplicationsRPC
if (!msg.activity.name) msg.activity.name = app.name; const _lookupApp = Object.values(mod).find(
} (e) => typeof e === "function" && e.toString().includes(",coverImage:"),
);
if (_lookupApp)
lookupApp = async (appId) => {
let socket = {};
await _lookupApp(socket, appId);
return socket.application;
};
}
if (lookupApp) break;
}
Dispatcher.dispatch({type: "LOCAL_ACTIVITY_UPDATE", ...msg}); // set RPC status ArmCordRPC.listen(async (msg) => {
}); if (msg.activity) {
})() if (msg.activity?.assets?.large_image && lookupAsset)
); msg.activity.assets.large_image = await lookupAsset(
msg.activity.application_id,
msg.activity.assets.large_image,
);
if (msg.activity?.assets?.small_image && lookupAsset)
msg.activity.assets.small_image = await lookupAsset(
msg.activity.application_id,
msg.activity.assets.small_image,
);
const appId = msg.activity.application_id;
if (!apps[appId] && lookupApp) apps[appId] = await lookupApp(appId);
const app = apps[appId];
if (!msg.activity.name) msg.activity.name = app.name;
}
Dispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", ...msg }); // set RPC status
});
});