mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
fix arRPC
This commit is contained in:
parent
4cb480cf93
commit
0dfb518082
3 changed files with 83 additions and 71 deletions
|
@ -1,79 +1,87 @@
|
||||||
(() => {
|
window.addEventListener(
|
||||||
let Dispatcher,
|
"load",
|
||||||
lookupAsset,
|
(() => {
|
||||||
lookupApp,
|
let Dispatcher,
|
||||||
apps = {};
|
lookupAsset,
|
||||||
|
lookupApp,
|
||||||
|
apps = {};
|
||||||
|
|
||||||
ArmCordRPC.listen(async (data) => {
|
ArmCordRPC.listen(async (data) => {
|
||||||
msg = data; //already parsed
|
msg = data; //already parsed
|
||||||
//console.log(msg);
|
//console.log(msg);
|
||||||
|
|
||||||
if (!Dispatcher) {
|
if (!Dispatcher) {
|
||||||
const wpRequire = window.webpackChunkdiscord_app.push([[Symbol()], {}, (x) => x]);
|
const wpRequire = window.webpackChunkdiscord_app.push([[Symbol()], {}, (x) => x]);
|
||||||
const cache = wpRequire.c;
|
const cache = wpRequire.c;
|
||||||
window.webpackChunkdiscord_app.pop();
|
window.webpackChunkdiscord_app.pop();
|
||||||
|
|
||||||
for (const id in cache) {
|
for (const id in cache) {
|
||||||
let mod = cache[id].exports;
|
let mod = cache[id].exports;
|
||||||
mod = mod && (mod.Z ?? mod.ZP);
|
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
|
||||||
|
}
|
||||||
|
|
||||||
if (mod && mod.register && mod.wait) {
|
const factories = wpRequire.m;
|
||||||
Dispatcher = mod;
|
for (const id in factories) {
|
||||||
break;
|
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("APPLICATION_ASSETS_FETCH_SUCCESS")
|
||||||
|
);
|
||||||
|
if (_lookupAsset)
|
||||||
|
lookupAsset = async (appId, name) => (await _lookupAsset(appId, [name, undefined]))[0];
|
||||||
|
}
|
||||||
|
if (lookupAsset) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const id in factories) {
|
||||||
|
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(",coverImage:")
|
||||||
|
);
|
||||||
|
if (_lookupApp)
|
||||||
|
lookupApp = async (appId) => {
|
||||||
|
let socket = {};
|
||||||
|
await _lookupApp(socket, appId);
|
||||||
|
return socket.application;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (lookupApp) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const factories = wpRequire.m;
|
if (msg.activity?.assets?.large_image)
|
||||||
for (const id in factories) {
|
msg.activity.assets.large_image = await lookupAsset(
|
||||||
if (factories[id].toString().includes("getAssetImage: size must === [number, number] for Twitch")) {
|
msg.activity.application_id,
|
||||||
const mod = wpRequire(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
|
||||||
|
);
|
||||||
|
|
||||||
const _lookupAsset = Object.values(mod).find(
|
// prevent errors when activity is null and let activity stop
|
||||||
(e) => typeof e === "function" && e.toString().includes("apply(")
|
if (msg.activity) {
|
||||||
);
|
const appId = msg.activity.application_id;
|
||||||
lookupAsset = async (appId, name) => (await _lookupAsset(appId, [name, undefined]))[0];
|
if (!apps[appId]) apps[appId] = await lookupApp(appId);
|
||||||
|
|
||||||
break;
|
const app = apps[appId];
|
||||||
}
|
if (!msg.activity.name) msg.activity.name = app.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const id in factories) {
|
Dispatcher.dispatch({type: "LOCAL_ACTIVITY_UPDATE", ...msg}); // set RPC status
|
||||||
if (factories[id].toString().includes(`e.application={`)) {
|
});
|
||||||
const mod = wpRequire(id);
|
})()
|
||||||
|
);
|
||||||
const _lookupApp = Object.values(mod).find(
|
|
||||||
(e) => typeof e === "function" && e.toString().includes(`e.application={`)
|
|
||||||
);
|
|
||||||
lookupApp = async (appId) => {
|
|
||||||
let socket = {};
|
|
||||||
await _lookupApp(socket, appId);
|
|
||||||
return socket.application;
|
|
||||||
};
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
if (msg.activity) {
|
|
||||||
const appId = msg.activity.application_id;
|
|
||||||
if (!apps[appId]) 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
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
|
|
|
@ -67,5 +67,6 @@ contextBridge.exposeInMainWorld("ArmCordRPC", {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ipcRenderer.on("rpc", (_event, data: object) => {
|
ipcRenderer.on("rpc", (_event, data: object) => {
|
||||||
|
console.log(data);
|
||||||
windowCallback(data);
|
windowCallback(data);
|
||||||
});
|
});
|
||||||
|
|
|
@ -73,7 +73,10 @@ sleep(5000).then(async () => {
|
||||||
|
|
||||||
// Settings info version injection
|
// Settings info version injection
|
||||||
setInterval(() => {
|
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")) {
|
if (!host || host.querySelector("#ac-ver")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -84,8 +87,8 @@ setInterval(() => {
|
||||||
el.onclick = () => ipcRenderer.send("openSettingsWindow");
|
el.onclick = () => ipcRenderer.send("openSettingsWindow");
|
||||||
host.append(el);
|
host.append(el);
|
||||||
let advanced = document
|
let advanced = document
|
||||||
.querySelector('[class*="socialLinks-"]')!
|
.querySelector('[class*="socialLinks"]')
|
||||||
.parentElement!.querySelector(
|
?.parentElement?.querySelector(
|
||||||
'[class*="header"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"]'
|
'[class*="header"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"] + [class*="item"]'
|
||||||
);
|
);
|
||||||
if (!advanced) return;
|
if (!advanced) return;
|
||||||
|
|
Loading…
Reference in a new issue