Discord RPC Fix

This commit is contained in:
MasterAcnolo
2025-11-12 14:59:11 +01:00
parent 783871d131
commit 627c56cd25

View File

@@ -2,14 +2,12 @@ const config = require('../config');
const RPC = require("discord-rpc"); const RPC = require("discord-rpc");
const clientId = `${config.DiscordRPCID}`; const clientId = `${config.DiscordRPCID}`;
const rpc = new RPC.Client({ transport: "ipc" }); const rpc = new RPC.Client({ transport: "ipc" });
let intervalId; let intervalId;
function startRPC() { function startRPC() {
rpc.on("ready", () => { rpc.on("ready", () => {
const presence = { const presence = {
largeImageKey: "icon", largeImageKey: "icon",
smallImageKey: "acnolo_pfp", smallImageKey: "acnolo_pfp",
@@ -26,19 +24,26 @@ function startRPC() {
}, 15000); }, 15000);
}); });
const cleanExit = () => { async function cleanExit() {
if (intervalId) clearInterval(intervalId); try {
rpc.destroy(); // déconnecte proprement if (intervalId) clearInterval(intervalId);
};
if (rpc && rpc.transport) {
await rpc.destroy();
}
} catch (err) {
console.warn("Erreur lors de la fermeture du RPC :", err);
} finally {
process.exit();
}
}
process.on("exit", cleanExit); process.on("exit", cleanExit);
process.on("SIGINT", () => { process.on("SIGINT", cleanExit);
cleanExit(); process.on("SIGTERM", cleanExit);
process.exit();
}); rpc.login({ clientId }).catch(err => {
process.on("SIGTERM", () => { console.warn("Impossible de connecter le RPC :", err);
cleanExit();
process.exit();
}); });
} }