Compare commits
No commits in common. "c3f088295189cd8ad3141b489ed96e2c0b44261e" and "4c33323e9ef5025283265c53b264466e2f6715f9" have entirely different histories.
c3f0882951
...
4c33323e9e
@ -1,15 +0,0 @@
|
||||
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 };
|
@ -2,10 +2,7 @@ const DiscordRPC = require("discord-auto-rpc");
|
||||
const { appName, appVersion } = require("./appInfo.js");
|
||||
|
||||
const clientId = "1032772293220384808";
|
||||
|
||||
/** @type {DiscordRPC.AutoClient} */
|
||||
let richPresence;
|
||||
|
||||
let intervalId;
|
||||
|
||||
let currentStatus = {
|
||||
@ -35,7 +32,6 @@ module.exports = {
|
||||
richPresence = new DiscordRPC.AutoClient({ transport: "ipc" });
|
||||
richPresence.endlessLogin({ clientId });
|
||||
richPresence.once("ready", () => {
|
||||
console.log("connected presence with user " + richPresence.user.username);
|
||||
richPresence.setActivity(currentStatus);
|
||||
intervalId = setInterval(() => {
|
||||
richPresence.setActivity(currentStatus);
|
||||
@ -51,17 +47,16 @@ module.exports = {
|
||||
richPresence = null;
|
||||
}
|
||||
},
|
||||
updateStatus: ({ state, details, largeImageKey }) => {
|
||||
updateStatus: ({ state, details }) => {
|
||||
currentStatus.state = state ?? " ";
|
||||
currentStatus.details = details ?? " ";
|
||||
currentStatus.largeImageKey = largeImageKey ?? "ezppfarm";
|
||||
},
|
||||
updateUser: ({ username, id }) => {
|
||||
currentStatus.smallImageKey = id ? `https://a.ez-pp.farm/${id}` : " ";
|
||||
currentStatus.smallImageText = username ?? " ";
|
||||
updateVersion: (osuVersion) => {
|
||||
currentStatus.smallImageKey = osuVersion ? "osu" : " ";
|
||||
currentStatus.smallImageText = osuVersion ? `osu! ${osuVersion}` : " ";
|
||||
},
|
||||
update: () => {
|
||||
if (richPresence && richPresence.user) {
|
||||
if (richPresence) {
|
||||
richPresence.setActivity(currentStatus);
|
||||
}
|
||||
},
|
||||
|
66
main.js
66
main.js
@ -46,7 +46,6 @@ 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.
|
||||
@ -73,25 +72,6 @@ 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(
|
||||
@ -116,32 +96,15 @@ 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;
|
||||
if (setId) {
|
||||
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:
|
||||
details = "AFK...";
|
||||
infoText = " ";
|
||||
largeImageKey = "ezppfarm";
|
||||
break;
|
||||
case 2:
|
||||
details = "Playing...";
|
||||
@ -155,7 +118,6 @@ function startOsuStatus() {
|
||||
case 5:
|
||||
details = "Multiplayer: Selecting a Beatmap...";
|
||||
infoText = " ";
|
||||
largeImageKey = "ezppfarm";
|
||||
break;
|
||||
case 6:
|
||||
details = "Watching...";
|
||||
@ -165,12 +127,10 @@ function startOsuStatus() {
|
||||
break;
|
||||
case 9:
|
||||
details = "Submitting...";
|
||||
largeImageKey = "ezppfarm";
|
||||
break;
|
||||
case 11:
|
||||
details = "Multiplayer: Idle...";
|
||||
infoText = " ";
|
||||
largeImageKey = "ezppfarm";
|
||||
break;
|
||||
case 12:
|
||||
details = "Multiplayer: Playing...";
|
||||
@ -178,14 +138,12 @@ function startOsuStatus() {
|
||||
case 13:
|
||||
details = "Browsing osu!direct...";
|
||||
infoText = " ";
|
||||
largeImageKey = "ezppfarm";
|
||||
break;
|
||||
}
|
||||
|
||||
richPresence.updateStatus({
|
||||
details,
|
||||
state: infoText,
|
||||
largeImageKey,
|
||||
});
|
||||
|
||||
richPresence.update();
|
||||
@ -428,8 +386,9 @@ 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)
|
||||
})...`,
|
||||
});
|
||||
});
|
||||
await uiDownloader.startDownload();
|
||||
@ -458,8 +417,9 @@ 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)
|
||||
})...`,
|
||||
});
|
||||
});
|
||||
await updateDownloader.startDownload();
|
||||
@ -504,8 +464,9 @@ 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)
|
||||
})...`,
|
||||
});
|
||||
});
|
||||
await patcherDownloader.startDownload();
|
||||
@ -577,9 +538,11 @@ function registerIPCPipes() {
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch { }
|
||||
} catch {}
|
||||
|
||||
const userConfig = getUserConfig(osuPath);
|
||||
richPresence.updateVersion(await userConfig.get("LastVersion"));
|
||||
richPresence.update();
|
||||
if (richPresence.hasPresence) {
|
||||
await userConfig.set("DiscordRichPresence", "0");
|
||||
}
|
||||
@ -600,10 +563,7 @@ function registerIPCPipes() {
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
stopOsuStatus();
|
||||
richPresence.updateUser({
|
||||
username: " ",
|
||||
id: undefined
|
||||
});
|
||||
richPresence.updateVersion();
|
||||
richPresence.updateStatus({
|
||||
state: "Idle in Launcher...",
|
||||
details: undefined,
|
||||
|
Loading…
x
Reference in New Issue
Block a user