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 { appName, appVersion } = require("./appInfo.js");
|
||||||
|
|
||||||
const clientId = "1032772293220384808";
|
const clientId = "1032772293220384808";
|
||||||
|
|
||||||
/** @type {DiscordRPC.AutoClient} */
|
|
||||||
let richPresence;
|
let richPresence;
|
||||||
|
|
||||||
let intervalId;
|
let intervalId;
|
||||||
|
|
||||||
let currentStatus = {
|
let currentStatus = {
|
||||||
@ -35,7 +32,6 @@ module.exports = {
|
|||||||
richPresence = new DiscordRPC.AutoClient({ transport: "ipc" });
|
richPresence = new DiscordRPC.AutoClient({ transport: "ipc" });
|
||||||
richPresence.endlessLogin({ clientId });
|
richPresence.endlessLogin({ clientId });
|
||||||
richPresence.once("ready", () => {
|
richPresence.once("ready", () => {
|
||||||
console.log("connected presence with user " + richPresence.user.username);
|
|
||||||
richPresence.setActivity(currentStatus);
|
richPresence.setActivity(currentStatus);
|
||||||
intervalId = setInterval(() => {
|
intervalId = setInterval(() => {
|
||||||
richPresence.setActivity(currentStatus);
|
richPresence.setActivity(currentStatus);
|
||||||
@ -51,17 +47,16 @@ module.exports = {
|
|||||||
richPresence = null;
|
richPresence = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateStatus: ({ state, details, largeImageKey }) => {
|
updateStatus: ({ state, details }) => {
|
||||||
currentStatus.state = state ?? " ";
|
currentStatus.state = state ?? " ";
|
||||||
currentStatus.details = details ?? " ";
|
currentStatus.details = details ?? " ";
|
||||||
currentStatus.largeImageKey = largeImageKey ?? "ezppfarm";
|
|
||||||
},
|
},
|
||||||
updateUser: ({ username, id }) => {
|
updateVersion: (osuVersion) => {
|
||||||
currentStatus.smallImageKey = id ? `https://a.ez-pp.farm/${id}` : " ";
|
currentStatus.smallImageKey = osuVersion ? "osu" : " ";
|
||||||
currentStatus.smallImageText = username ?? " ";
|
currentStatus.smallImageText = osuVersion ? `osu! ${osuVersion}` : " ";
|
||||||
},
|
},
|
||||||
update: () => {
|
update: () => {
|
||||||
if (richPresence && richPresence.user) {
|
if (richPresence) {
|
||||||
richPresence.setActivity(currentStatus);
|
richPresence.setActivity(currentStatus);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
60
main.js
60
main.js
@ -46,7 +46,6 @@ const { getHwId } = require("./electron/hwidUtil");
|
|||||||
const { appName, appVersion } = require("./electron/appInfo");
|
const { appName, appVersion } = require("./electron/appInfo");
|
||||||
const { updateAvailable, releasesUrl } = require("./electron/updateCheck");
|
const { updateAvailable, releasesUrl } = require("./electron/updateCheck");
|
||||||
const fkill = require("fkill");
|
const fkill = require("fkill");
|
||||||
const { checkImageExists } = require("./electron/imageUtil");
|
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// 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.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
@ -73,25 +72,6 @@ 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(
|
||||||
@ -116,32 +96,15 @@ function startOsuStatus() {
|
|||||||
if (!("player_status" in currentStatus)) return;
|
if (!("player_status" in currentStatus)) return;
|
||||||
if (!("status" in currentStatus.player_status)) return;
|
if (!("status" in currentStatus.player_status)) return;
|
||||||
|
|
||||||
let largeImageKey = "ezppfarm";
|
|
||||||
let details = "Idle...";
|
let details = "Idle...";
|
||||||
let infoText = currentStatus.player_status.status.info_text.length > 0
|
let infoText = currentStatus.player_status.status.info_text.length > 0
|
||||||
? currentStatus.player_status.status.info_text
|
? 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) {
|
switch (currentStatus.player_status.status.action) {
|
||||||
case 1:
|
case 1:
|
||||||
details = "AFK...";
|
details = "AFK...";
|
||||||
infoText = " ";
|
infoText = " ";
|
||||||
largeImageKey = "ezppfarm";
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
details = "Playing...";
|
details = "Playing...";
|
||||||
@ -155,7 +118,6 @@ 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...";
|
||||||
@ -165,12 +127,10 @@ 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...";
|
||||||
@ -178,14 +138,12 @@ function startOsuStatus() {
|
|||||||
case 13:
|
case 13:
|
||||||
details = "Browsing osu!direct...";
|
details = "Browsing osu!direct...";
|
||||||
infoText = " ";
|
infoText = " ";
|
||||||
largeImageKey = "ezppfarm";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
richPresence.updateStatus({
|
richPresence.updateStatus({
|
||||||
details,
|
details,
|
||||||
state: infoText,
|
state: infoText,
|
||||||
largeImageKey,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
richPresence.update();
|
richPresence.update();
|
||||||
@ -428,7 +386,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)}/${formatBytes(data.total)
|
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${
|
||||||
|
formatBytes(data.total)
|
||||||
})...`,
|
})...`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -458,7 +417,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)}/${formatBytes(data.total)
|
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${
|
||||||
|
formatBytes(data.total)
|
||||||
})...`,
|
})...`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -504,7 +464,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)}/${formatBytes(data.total)
|
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${
|
||||||
|
formatBytes(data.total)
|
||||||
})...`,
|
})...`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -577,9 +538,11 @@ 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");
|
||||||
}
|
}
|
||||||
@ -600,10 +563,7 @@ function registerIPCPipes() {
|
|||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
mainWindow.focus();
|
mainWindow.focus();
|
||||||
stopOsuStatus();
|
stopOsuStatus();
|
||||||
richPresence.updateUser({
|
richPresence.updateVersion();
|
||||||
username: " ",
|
|
||||||
id: undefined
|
|
||||||
});
|
|
||||||
richPresence.updateStatus({
|
richPresence.updateStatus({
|
||||||
state: "Idle in Launcher...",
|
state: "Idle in Launcher...",
|
||||||
details: undefined,
|
details: undefined,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user