mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
parent
c8107ef588
commit
b5a6a2b579
1 changed files with 86 additions and 76 deletions
|
@ -1,87 +1,97 @@
|
|||
window.addEventListener(
|
||||
"load",
|
||||
(() => {
|
||||
let Dispatcher,
|
||||
lookupAsset,
|
||||
lookupApp,
|
||||
apps = {};
|
||||
window.addEventListener("load", async () => {
|
||||
let Dispatcher = undefined,
|
||||
lookupAsset = undefined,
|
||||
lookupApp = undefined;
|
||||
|
||||
ArmCordRPC.listen(async (data) => {
|
||||
msg = data; //already parsed
|
||||
//console.log(msg);
|
||||
let apps = {};
|
||||
const chunkName = 'webpackChunkdiscord_app';
|
||||
|
||||
if (!Dispatcher) {
|
||||
const wpRequire = window.webpackChunkdiscord_app.push([[Symbol()], {}, (x) => x]);
|
||||
const cache = wpRequire.c;
|
||||
window.webpackChunkdiscord_app.pop();
|
||||
const wpRequire = window[chunkName].push(
|
||||
[ [Symbol()], {}, (x) => x ]
|
||||
);
|
||||
|
||||
for (const id in cache) {
|
||||
let mod = cache[id].exports;
|
||||
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 cache = wpRequire.c;
|
||||
window[chunkName].pop();
|
||||
|
||||
const factories = wpRequire.m;
|
||||
for (const id in factories) {
|
||||
if (factories[id].toString().includes("getAssetImage: size must === [number, number] for Twitch")) {
|
||||
const mod = wpRequire(id);
|
||||
for (const id in cache) {
|
||||
let mod = cache[id].exports;
|
||||
if (typeof mod !== "object") continue;
|
||||
|
||||
// fetchAssetIds
|
||||
const _lookupAsset = Object.values(mod).find(
|
||||
(e) => typeof e === "function" && e.toString().includes("APPLICATION_ASSETS_FETCH_SUCCESS")
|
||||
);
|
||||
if (_lookupAsset)
|
||||
lookupAsset = async (appId, name) => (await _lookupAsset(appId, [name, undefined]))[0];
|
||||
}
|
||||
if (lookupAsset) break;
|
||||
}
|
||||
let candidates;
|
||||
try {
|
||||
candidates = Object.values(mod);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const id in factories) {
|
||||
if (factories[id].toString().includes("APPLICATION_RPC")) {
|
||||
const mod = wpRequire(id);
|
||||
for (const candidate of candidates) {
|
||||
if (candidate && candidate.register && candidate.wait) {
|
||||
Dispatcher = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fetchApplicationsRPC
|
||||
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;
|
||||
}
|
||||
}
|
||||
const factories = wpRequire.m;
|
||||
for (const id in factories) {
|
||||
if (
|
||||
factories[id]
|
||||
.toString()
|
||||
.includes("getAssetImage: size must === [number, number] for Twitch")
|
||||
) {
|
||||
const mod = wpRequire(id);
|
||||
|
||||
if (msg.activity?.assets?.large_image)
|
||||
msg.activity.assets.large_image = await lookupAsset(
|
||||
msg.activity.application_id,
|
||||
msg.activity.assets.large_image
|
||||
);
|
||||
if (msg.activity?.assets?.small_image)
|
||||
msg.activity.assets.small_image = await lookupAsset(
|
||||
msg.activity.application_id,
|
||||
msg.activity.assets.small_image
|
||||
);
|
||||
// fetchAssetIds
|
||||
const _lookupAsset = Object.values(mod).find(
|
||||
(e) =>
|
||||
typeof e === "function" &&
|
||||
e.toString().includes("APPLICATION_ASSETS_FETCH_SUCCESS"),
|
||||
);
|
||||
if (_lookupAsset)
|
||||
lookupAsset = async (appId, name) =>
|
||||
(await _lookupAsset(appId, [name, undefined]))[0];
|
||||
}
|
||||
if (lookupAsset) break;
|
||||
}
|
||||
|
||||
// prevent errors when activity is null and let activity stop
|
||||
if (msg.activity) {
|
||||
const appId = msg.activity.application_id;
|
||||
if (!apps[appId]) apps[appId] = await lookupApp(appId);
|
||||
for (const id in factories) {
|
||||
if (factories[id].toString().includes("APPLICATION_RPC")) {
|
||||
const mod = wpRequire(id);
|
||||
|
||||
const app = apps[appId];
|
||||
if (!msg.activity.name) msg.activity.name = app.name;
|
||||
}
|
||||
// fetchApplicationsRPC
|
||||
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
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue