display user as small image, fix dynamic beatmap images

This commit is contained in:
HorizonCode 2024-03-11 18:06:24 +01:00
parent 6bcce04b72
commit 90717ed960
2 changed files with 42 additions and 21 deletions

View File

@ -56,9 +56,9 @@ module.exports = {
currentStatus.details = details ?? " "; currentStatus.details = details ?? " ";
currentStatus.largeImageKey = largeImageKey ?? "ezppfarm"; currentStatus.largeImageKey = largeImageKey ?? "ezppfarm";
}, },
updateVersion: (osuVersion) => { updateUser: ({ username, id }) => {
currentStatus.smallImageKey = osuVersion ? "osu" : " "; currentStatus.smallImageKey = id ? `https://a.ez-pp.farm/${id}` : " ";
currentStatus.smallImageText = osuVersion ? `osu! ${osuVersion}` : " "; currentStatus.smallImageText = username ? username : " ";
}, },
update: () => { update: () => {
if (richPresence && richPresence.user) { if (richPresence && richPresence.user) {

57
main.js
View File

@ -73,6 +73,25 @@ function startOsuStatus() {
if (firstInstance) { if (firstInstance) {
if (!osuLoaded) { if (!osuLoaded) {
osuLoaded = true; 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(() => { setTimeout(() => {
if (patch) { if (patch) {
const patcherExecuteable = path.join( const patcherExecuteable = path.join(
@ -107,12 +126,14 @@ function startOsuStatus() {
currentStatus.player_status.status.beatmap !== null currentStatus.player_status.status.beatmap !== null
) { ) {
const setId = currentStatus.player_status.status.beatmap.set_id; const setId = currentStatus.player_status.status.beatmap.set_id;
const coverImage = if (setId) {
`https://assets.ppy.sh/beatmaps/${setId}/covers/list@2x.jpg`; const coverImage =
if ( `https://assets.ppy.sh/beatmaps/${setId}/covers/list@2x.jpg`;
checkImageExists(coverImage) if (
) { checkImageExists(coverImage)
largeImageKey = coverImage; ) {
largeImageKey = coverImage;
}
} }
} }
@ -120,6 +141,7 @@ function startOsuStatus() {
case 1: case 1:
details = "AFK..."; details = "AFK...";
infoText = " "; infoText = " ";
largeImageKey = "ezppfarm";
break; break;
case 2: case 2:
details = "Playing..."; details = "Playing...";
@ -133,6 +155,7 @@ function startOsuStatus() {
case 5: case 5:
details = "Multiplayer: Selecting a Beatmap..."; details = "Multiplayer: Selecting a Beatmap...";
infoText = " "; infoText = " ";
largeImageKey = "ezppfarm";
break; break;
case 6: case 6:
details = "Watching..."; details = "Watching...";
@ -142,10 +165,12 @@ function startOsuStatus() {
break; break;
case 9: case 9:
details = "Submitting..."; details = "Submitting...";
largeImageKey = "ezppfarm";
break; break;
case 11: case 11:
details = "Multiplayer: Idle..."; details = "Multiplayer: Idle...";
infoText = " "; infoText = " ";
largeImageKey = "ezppfarm";
break; break;
case 12: case 12:
details = "Multiplayer: Playing..."; details = "Multiplayer: Playing...";
@ -153,6 +178,7 @@ function startOsuStatus() {
case 13: case 13:
details = "Browsing osu!direct..."; details = "Browsing osu!direct...";
infoText = " "; infoText = " ";
largeImageKey = "ezppfarm";
break; break;
} }
@ -402,9 +428,8 @@ function registerIPCPipes() {
progress: Math.ceil(data.progress), progress: Math.ceil(data.progress),
}); });
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${ status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
formatBytes(data.total) })...`,
})...`,
}); });
}); });
await uiDownloader.startDownload(); await uiDownloader.startDownload();
@ -433,9 +458,8 @@ function registerIPCPipes() {
progress: Math.ceil(data.progress), progress: Math.ceil(data.progress),
}); });
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${ status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
formatBytes(data.total) })...`,
})...`,
}); });
}); });
await updateDownloader.startDownload(); await updateDownloader.startDownload();
@ -480,9 +504,8 @@ function registerIPCPipes() {
progress: Math.ceil(data.progress), progress: Math.ceil(data.progress),
}); });
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${ status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
formatBytes(data.total) })...`,
})...`,
}); });
}); });
await patcherDownloader.startDownload(); await patcherDownloader.startDownload();
@ -554,11 +577,9 @@ function registerIPCPipes() {
}); });
} }
} }
} catch {} } catch { }
const userConfig = getUserConfig(osuPath); const userConfig = getUserConfig(osuPath);
richPresence.updateVersion(await userConfig.get("LastVersion"));
richPresence.update();
if (richPresence.hasPresence) { if (richPresence.hasPresence) {
await userConfig.set("DiscordRichPresence", "0"); await userConfig.set("DiscordRichPresence", "0");
} }