fix arRPC

This commit is contained in:
smartfrigde 2023-11-05 18:39:46 +01:00
parent 4cb480cf93
commit 0dfb518082
3 changed files with 83 additions and 71 deletions

View file

@ -1,4 +1,6 @@
(() => {
window.addEventListener(
"load",
(() => {
let Dispatcher,
lookupAsset,
lookupApp,
@ -15,43 +17,47 @@
for (const id in cache) {
let mod = cache[id].exports;
mod = mod && (mod.Z ?? mod.ZP);
if (mod && mod.register && mod.wait) {
Dispatcher = mod;
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 factories) {
if (factories[id].toString().includes("getAssetImage: size must === [number, number] for Twitch")) {
const mod = wpRequire(id);
// fetchAssetIds
const _lookupAsset = Object.values(mod).find(
(e) => typeof e === "function" && e.toString().includes("apply(")
(e) => typeof e === "function" && e.toString().includes("APPLICATION_ASSETS_FETCH_SUCCESS")
);
if (_lookupAsset)
lookupAsset = async (appId, name) => (await _lookupAsset(appId, [name, undefined]))[0];
break;
}
if (lookupAsset) break;
}
for (const id in factories) {
if (factories[id].toString().includes(`e.application={`)) {
if (factories[id].toString().includes("APPLICATION_RPC")) {
const mod = wpRequire(id);
// fetchApplicationsRPC
const _lookupApp = Object.values(mod).find(
(e) => typeof e === "function" && e.toString().includes(`e.application={`)
(e) => typeof e === "function" && e.toString().includes(",coverImage:")
);
if (_lookupApp)
lookupApp = async (appId) => {
let socket = {};
await _lookupApp(socket, appId);
return socket.application;
};
break;
}
if (lookupApp) break;
}
}
@ -66,6 +72,7 @@
msg.activity.assets.small_image
);
// 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);
@ -76,4 +83,5 @@
Dispatcher.dispatch({type: "LOCAL_ACTIVITY_UPDATE", ...msg}); // set RPC status
});
})();
})()
);

View file

@ -67,5 +67,6 @@ contextBridge.exposeInMainWorld("ArmCordRPC", {
}
});
ipcRenderer.on("rpc", (_event, data: object) => {
console.log(data);
windowCallback(data);
});

View file

@ -73,7 +73,10 @@ sleep(5000).then(async () => {
// Settings info version injection
setInterval(() => {
const host = document.querySelector<HTMLDivElement>("nav > [class|=side] [class|=info]");
// @ts-expect-error
const host = [...document.querySelectorAll('[class*="sidebar"] [class*="info"] [class*="line"]')].find((x) =>
x.textContent.startsWith("Host ")
);
if (!host || host.querySelector("#ac-ver")) {
return;
}
@ -84,8 +87,8 @@ setInterval(() => {
el.onclick = () => ipcRenderer.send("openSettingsWindow");
host.append(el);
let advanced = document
.querySelector('[class*="socialLinks-"]')!
.parentElement!.querySelector(
.querySelector('[class*="socialLinks"]')
?.parentElement?.querySelector(
'[class*="header"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"]'
);
if (!advanced) return;