fix: update rich presence methods to use async/await for improved reliability

This commit is contained in:
HorizonCode 2025-05-14 11:15:01 +02:00
parent 1739618278
commit 084409a955
2 changed files with 13 additions and 14 deletions

View File

@ -34,23 +34,22 @@ module.exports = {
if (!richPresence) {
richPresence = new DiscordRPC.AutoClient({ transport: "ipc" });
richPresence.endlessLogin({ clientId });
richPresence.once("ready", () => {
richPresence.once("ready", async () => {
console.log(
"connected presence with user " + richPresence.user.username,
);
richPresence.setActivity(currentStatus);
intervalId = setInterval(() => {
richPresence.setActivity(currentStatus);
}, 2500);
await richPresence.setActivity(currentStatus);
intervalId = setInterval(() => richPresence.setActivity(currentStatus), 2500);
});
}
},
disconnect: async () => {
if (richPresence) {
clearInterval(intervalId);
await richPresence.clearActivity();
await richPresence.destroy();
const presence = richPresence;
richPresence = null;
clearInterval(intervalId);
await presence.clearActivity();
await presence.destroy();
}
},
updateStatus: ({ state, details, largeImageKey }) => {
@ -62,9 +61,9 @@ module.exports = {
currentStatus.smallImageKey = id ? `https://a.ez-pp.farm/${id}` : " ";
currentStatus.smallImageText = username ?? " ";
},
update: () => {
update: async () => {
if (richPresence && richPresence.user) {
richPresence.setActivity(currentStatus);
await richPresence.setActivity(currentStatus);
}
},
hasPresence: () => richPresence != undefined,

View File

@ -98,7 +98,7 @@ function startOsuStatus() {
id,
username,
});
richPresence.update();
await richPresence.update();
}
}
} catch {
@ -235,7 +235,7 @@ function startOsuStatus() {
largeImageKey,
});
richPresence.update();
await richPresence.update();
}
}, 2500);
}
@ -732,7 +732,7 @@ function registerIPCPipes() {
logger.log("Launching osu!...");
const onExitHook = () => {
const onExitHook = async () => {
logger.log("osu! has exited.");
mainWindow.show();
mainWindow.focus();
@ -745,7 +745,7 @@ function registerIPCPipes() {
state: "Idle in Launcher...",
details: undefined,
});
richPresence.update();
await richPresence.update();
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Waiting for cleanup...",
});