add dynamic beatmap images to presence #12

Merged
HorizonCode merged 8 commits from dev into master 2024-03-11 17:55:54 +00:00
5 changed files with 37 additions and 5 deletions
Showing only changes of commit 6bcce04b72 - Show all commits

View File

@ -1,4 +1,4 @@
const appName = "EZPPLauncher";
const appVersion = "2.1.0";
const appVersion = "2.1.1";
module.exports = { appName, appVersion };

15
electron/imageUtil.js Normal file
View File

@ -0,0 +1,15 @@
async function checkImageExists(url) {
try {
const response = await fetch(url, { method: "HEAD" });
if (!response.ok) {
return false;
}
const contentType = response.headers.get("content-type");
if (!contentType) return false;
return contentType.startsWith("image/");
} catch (error) {
return false;
}
}
module.exports = { checkImageExists };

View File

@ -51,9 +51,10 @@ module.exports = {
richPresence = null;
}
},
updateStatus: ({ state, details }) => {
updateStatus: ({ state, details, largeImageKey }) => {
currentStatus.state = state ?? " ";
currentStatus.details = details ?? " ";
currentStatus.largeImageKey = largeImageKey ?? "ezppfarm";
},
updateVersion: (osuVersion) => {
currentStatus.smallImageKey = osuVersion ? "osu" : " ";

20
main.js
View File

@ -3,14 +3,14 @@ const { app, BrowserWindow, Menu, ipcMain, dialog, shell } = require(
"electron",
);
const unhandled = require("electron-unhandled");
/* const unhandled = require("electron-unhandled");
unhandled({
logger: console.error,
showDialog: true,
reportButton: () => {
shell.openExternal("https://ez-pp.farm/discord");
},
});
}); */
const path = require("path");
const serve = require("electron-serve");
@ -46,6 +46,7 @@ const { getHwId } = require("./electron/hwidUtil");
const { appName, appVersion } = require("./electron/appInfo");
const { updateAvailable, releasesUrl } = require("./electron/updateCheck");
const fkill = require("fkill");
const { checkImageExists } = require("./electron/imageUtil");
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
@ -96,10 +97,24 @@ function startOsuStatus() {
if (!("player_status" in currentStatus)) return;
if (!("status" in currentStatus.player_status)) return;
let largeImageKey = "ezppfarm";
let details = "Idle...";
let infoText = currentStatus.player_status.status.info_text.length > 0
? currentStatus.player_status.status.info_text
: " ";
if (
"beatmap" in currentStatus.player_status.status &&
currentStatus.player_status.status.beatmap !== null
) {
const setId = currentStatus.player_status.status.beatmap.set_id;
const coverImage =
`https://assets.ppy.sh/beatmaps/${setId}/covers/list@2x.jpg`;
if (
checkImageExists(coverImage)
) {
largeImageKey = coverImage;
}
}
switch (currentStatus.player_status.status.action) {
case 1:
@ -144,6 +159,7 @@ function startOsuStatus() {
richPresence.updateStatus({
details,
state: infoText,
largeImageKey,
});
richPresence.update();

View File

@ -1,6 +1,6 @@
{
"name": "ezpplauncher-next",
"version": "2.1.0",
"version": "2.1.1",
"description": "EZPPLauncher rewritten with Svelte.",
"private": false,
"license": "MIT",