add dynamic beatmap image to presence
This commit is contained in:
parent
da8e237679
commit
d56d4875e0
15
electron/imageUtil.js
Normal file
15
electron/imageUtil.js
Normal 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 };
|
|
@ -47,9 +47,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" : " ";
|
||||
|
|
14
main.js
14
main.js
|
@ -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,22 @@ 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) {
|
||||
const setId = currentStatus.player_status.status.beatmap.set_id;
|
||||
if (
|
||||
checkImageExists(
|
||||
`https://assets.ppy.sh/beatmaps/${setId}/covers/list@2x.jpg`,
|
||||
)
|
||||
) {
|
||||
largeImageKey =
|
||||
`https://assets.ppy.sh/beatmaps/${setId}/covers/list@2x.jpg`;
|
||||
}
|
||||
}
|
||||
|
||||
switch (currentStatus.player_status.status.action) {
|
||||
case 1:
|
||||
|
@ -144,6 +157,7 @@ function startOsuStatus() {
|
|||
richPresence.updateStatus({
|
||||
details,
|
||||
state: infoText,
|
||||
largeImageKey,
|
||||
});
|
||||
|
||||
richPresence.update();
|
||||
|
|
Loading…
Reference in New Issue
Block a user