fix: update rich presence methods to use async/await for improved reliability
This commit is contained in:
parent
1739618278
commit
084409a955
@ -34,23 +34,22 @@ module.exports = {
|
|||||||
if (!richPresence) {
|
if (!richPresence) {
|
||||||
richPresence = new DiscordRPC.AutoClient({ transport: "ipc" });
|
richPresence = new DiscordRPC.AutoClient({ transport: "ipc" });
|
||||||
richPresence.endlessLogin({ clientId });
|
richPresence.endlessLogin({ clientId });
|
||||||
richPresence.once("ready", () => {
|
richPresence.once("ready", async () => {
|
||||||
console.log(
|
console.log(
|
||||||
"connected presence with user " + richPresence.user.username,
|
"connected presence with user " + richPresence.user.username,
|
||||||
);
|
);
|
||||||
richPresence.setActivity(currentStatus);
|
await richPresence.setActivity(currentStatus);
|
||||||
intervalId = setInterval(() => {
|
intervalId = setInterval(() => richPresence.setActivity(currentStatus), 2500);
|
||||||
richPresence.setActivity(currentStatus);
|
|
||||||
}, 2500);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
disconnect: async () => {
|
disconnect: async () => {
|
||||||
if (richPresence) {
|
if (richPresence) {
|
||||||
clearInterval(intervalId);
|
const presence = richPresence;
|
||||||
await richPresence.clearActivity();
|
|
||||||
await richPresence.destroy();
|
|
||||||
richPresence = null;
|
richPresence = null;
|
||||||
|
clearInterval(intervalId);
|
||||||
|
await presence.clearActivity();
|
||||||
|
await presence.destroy();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateStatus: ({ state, details, largeImageKey }) => {
|
updateStatus: ({ state, details, largeImageKey }) => {
|
||||||
@ -62,9 +61,9 @@ module.exports = {
|
|||||||
currentStatus.smallImageKey = id ? `https://a.ez-pp.farm/${id}` : " ";
|
currentStatus.smallImageKey = id ? `https://a.ez-pp.farm/${id}` : " ";
|
||||||
currentStatus.smallImageText = username ?? " ";
|
currentStatus.smallImageText = username ?? " ";
|
||||||
},
|
},
|
||||||
update: () => {
|
update: async () => {
|
||||||
if (richPresence && richPresence.user) {
|
if (richPresence && richPresence.user) {
|
||||||
richPresence.setActivity(currentStatus);
|
await richPresence.setActivity(currentStatus);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
hasPresence: () => richPresence != undefined,
|
hasPresence: () => richPresence != undefined,
|
||||||
|
8
main.js
8
main.js
@ -98,7 +98,7 @@ function startOsuStatus() {
|
|||||||
id,
|
id,
|
||||||
username,
|
username,
|
||||||
});
|
});
|
||||||
richPresence.update();
|
await richPresence.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@ -235,7 +235,7 @@ function startOsuStatus() {
|
|||||||
largeImageKey,
|
largeImageKey,
|
||||||
});
|
});
|
||||||
|
|
||||||
richPresence.update();
|
await richPresence.update();
|
||||||
}
|
}
|
||||||
}, 2500);
|
}, 2500);
|
||||||
}
|
}
|
||||||
@ -732,7 +732,7 @@ function registerIPCPipes() {
|
|||||||
|
|
||||||
logger.log("Launching osu!...");
|
logger.log("Launching osu!...");
|
||||||
|
|
||||||
const onExitHook = () => {
|
const onExitHook = async () => {
|
||||||
logger.log("osu! has exited.");
|
logger.log("osu! has exited.");
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
mainWindow.focus();
|
mainWindow.focus();
|
||||||
@ -745,7 +745,7 @@ function registerIPCPipes() {
|
|||||||
state: "Idle in Launcher...",
|
state: "Idle in Launcher...",
|
||||||
details: undefined,
|
details: undefined,
|
||||||
});
|
});
|
||||||
richPresence.update();
|
await richPresence.update();
|
||||||
mainWindow.webContents.send("ezpplauncher:launchstatus", {
|
mainWindow.webContents.send("ezpplauncher:launchstatus", {
|
||||||
status: "Waiting for cleanup...",
|
status: "Waiting for cleanup...",
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user