add dynamic beatmap images to presence #12
|
@ -56,9 +56,9 @@ module.exports = {
|
|||
currentStatus.details = details ?? " ";
|
||||
currentStatus.largeImageKey = largeImageKey ?? "ezppfarm";
|
||||
},
|
||||
updateVersion: (osuVersion) => {
|
||||
currentStatus.smallImageKey = osuVersion ? "osu" : " ";
|
||||
currentStatus.smallImageText = osuVersion ? `osu! ${osuVersion}` : " ";
|
||||
updateUser: ({ username, id }) => {
|
||||
currentStatus.smallImageKey = id ? `https://a.ez-pp.farm/${id}` : " ";
|
||||
currentStatus.smallImageText = username ? username : " ";
|
||||
},
|
||||
update: () => {
|
||||
if (richPresence && richPresence.user) {
|
||||
|
|
37
main.js
37
main.js
|
@ -73,6 +73,25 @@ function startOsuStatus() {
|
|||
if (firstInstance) {
|
||||
if (!osuLoaded) {
|
||||
osuLoaded = true;
|
||||
|
||||
try {
|
||||
const currentUserInfo = await fetch(`https://api.ez-pp.farm/get_player_info?name=${currentUser.username}&scope=info`);
|
||||
const currentUserInfoJson = await currentUserInfo.json();
|
||||
if ("player" in currentUserInfoJson && currentUserInfoJson.player != null) {
|
||||
if ("info" in currentUserInfoJson.player && currentUserInfoJson.player.info != null) {
|
||||
const id = currentUserInfoJson.player.info.id;
|
||||
const username = currentUserInfoJson.player.info.name;
|
||||
richPresence.updateUser({
|
||||
id,
|
||||
username,
|
||||
});
|
||||
richPresence.update();
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
if (patch) {
|
||||
const patcherExecuteable = path.join(
|
||||
|
@ -107,6 +126,7 @@ function startOsuStatus() {
|
|||
currentStatus.player_status.status.beatmap !== null
|
||||
) {
|
||||
const setId = currentStatus.player_status.status.beatmap.set_id;
|
||||
if (setId) {
|
||||
const coverImage =
|
||||
`https://assets.ppy.sh/beatmaps/${setId}/covers/list@2x.jpg`;
|
||||
if (
|
||||
|
@ -115,11 +135,13 @@ function startOsuStatus() {
|
|||
largeImageKey = coverImage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (currentStatus.player_status.status.action) {
|
||||
case 1:
|
||||
details = "AFK...";
|
||||
infoText = " ";
|
||||
largeImageKey = "ezppfarm";
|
||||
break;
|
||||
case 2:
|
||||
details = "Playing...";
|
||||
|
@ -133,6 +155,7 @@ function startOsuStatus() {
|
|||
case 5:
|
||||
details = "Multiplayer: Selecting a Beatmap...";
|
||||
infoText = " ";
|
||||
largeImageKey = "ezppfarm";
|
||||
break;
|
||||
case 6:
|
||||
details = "Watching...";
|
||||
|
@ -142,10 +165,12 @@ function startOsuStatus() {
|
|||
break;
|
||||
case 9:
|
||||
details = "Submitting...";
|
||||
largeImageKey = "ezppfarm";
|
||||
break;
|
||||
case 11:
|
||||
details = "Multiplayer: Idle...";
|
||||
infoText = " ";
|
||||
largeImageKey = "ezppfarm";
|
||||
break;
|
||||
case 12:
|
||||
details = "Multiplayer: Playing...";
|
||||
|
@ -153,6 +178,7 @@ function startOsuStatus() {
|
|||
case 13:
|
||||
details = "Browsing osu!direct...";
|
||||
infoText = " ";
|
||||
largeImageKey = "ezppfarm";
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -402,8 +428,7 @@ function registerIPCPipes() {
|
|||
progress: Math.ceil(data.progress),
|
||||
});
|
||||
mainWindow.webContents.send("ezpplauncher:launchstatus", {
|
||||
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${
|
||||
formatBytes(data.total)
|
||||
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
|
||||
})...`,
|
||||
});
|
||||
});
|
||||
|
@ -433,8 +458,7 @@ function registerIPCPipes() {
|
|||
progress: Math.ceil(data.progress),
|
||||
});
|
||||
mainWindow.webContents.send("ezpplauncher:launchstatus", {
|
||||
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${
|
||||
formatBytes(data.total)
|
||||
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
|
||||
})...`,
|
||||
});
|
||||
});
|
||||
|
@ -480,8 +504,7 @@ function registerIPCPipes() {
|
|||
progress: Math.ceil(data.progress),
|
||||
});
|
||||
mainWindow.webContents.send("ezpplauncher:launchstatus", {
|
||||
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${
|
||||
formatBytes(data.total)
|
||||
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
|
||||
})...`,
|
||||
});
|
||||
});
|
||||
|
@ -557,8 +580,6 @@ function registerIPCPipes() {
|
|||
} catch { }
|
||||
|
||||
const userConfig = getUserConfig(osuPath);
|
||||
richPresence.updateVersion(await userConfig.get("LastVersion"));
|
||||
richPresence.update();
|
||||
if (richPresence.hasPresence) {
|
||||
await userConfig.set("DiscordRichPresence", "0");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user