EZPPLauncher/electron/richPresence.js

65 lines
1.7 KiB
JavaScript
Raw Normal View History

const DiscordRPC = require("discord-auto-rpc");
const { appName, appVersion } = require("./appInfo.js");
const clientId = "1032772293220384808";
let richPresence;
2024-01-20 00:27:22 +00:00
let intervalId
2024-01-19 14:04:58 +00:00
let currentStatus = {
details: " ",
state: "Idle in Launcher...",
startTimestamp: new Date(),
largeImageKey: "ezppfarm",
largeImageText: `${appName} ${appVersion}`,
smallImageKey: " ",
smallImageText: " ",
buttons: [
{
label: "Download the Launcher",
url: "https://git.ez-pp.farm/EZPPFarm/EZPPLauncher/releases/latest",
},
{
label: "Join EZPPFarm",
url: "https://ez-pp.farm/discord",
},
],
instance: false,
};
module.exports = {
connect: () => {
2024-01-20 00:27:22 +00:00
console.log("Connecting to Discord...");
if (!richPresence) {
richPresence = new DiscordRPC.AutoClient({ transport: "ipc" });
richPresence.endlessLogin({ clientId });
richPresence.once("ready", () => {
2024-01-20 00:27:22 +00:00
richPresence.setActivity(currentStatus);
intervalId = setInterval(() => {
richPresence.setActivity(currentStatus);
}, 2500);
});
}
},
disconnect: async () => {
if (richPresence) {
2024-01-20 00:27:22 +00:00
clearInterval(intervalId);
await richPresence.clearActivity();
await richPresence.destroy();
richPresence = null;
}
},
updateStatus: ({ state, details }) => {
currentStatus.state = state ?? " ";
currentStatus.details = details ?? " ";
},
updateVersion: (osuVersion) => {
currentStatus.smallImageKey = osuVersion ? "osu" : " ";
currentStatus.smallImageText = osuVersion ? `osu! ${osuVersion}` : " ";
},
2024-01-18 18:47:56 +00:00
update: () => {
2024-01-20 00:27:22 +00:00
if (richPresence) {
2024-01-19 14:04:58 +00:00
richPresence.setActivity(currentStatus);
}
},
};