15 Commits
2.1.0 ... 2.1.2

Author SHA1 Message Date
c3f0882951 Merge pull request 'add dynamic beatmap images to presence' (#12) from dev into master
Reviewed-on: #12
2024-03-11 17:55:54 +00:00
c17cbc48d8 fix user reset 2024-03-11 18:46:04 +01:00
513692c2d5 reset user on exit 2024-03-11 18:37:33 +01:00
90717ed960 display user as small image, fix dynamic beatmap images 2024-03-11 18:06:24 +01:00
6bcce04b72 Merge branch 'dev' of https://git.ez-pp.farm/EZPPFarm/EZPPLauncher into dev 2024-03-11 17:34:38 +01:00
8d2024aa0a check if rpc is connected 2024-03-11 17:34:36 +01:00
22815e74b6 check if beatmap is not null 2024-03-11 15:46:07 +01:00
c4d9862860 assign the cover url to a const 2024-03-11 15:42:08 +01:00
d56d4875e0 add dynamic beatmap image to presence 2024-03-11 15:38:20 +01:00
4c33323e9e Merge pull request 'oops' (#10) from dev into master
Reviewed-on: #10
2024-01-30 08:52:43 +00:00
da8e237679 oops 2024-01-30 09:51:23 +01:00
eb166c0165 Merge pull request 'bump patch version' (#9) from dev into master
Reviewed-on: #9
2024-01-29 07:58:55 +00:00
c4cd8fed12 bump patch version 2024-01-29 08:58:42 +01:00
6bca0b32a9 Merge pull request 'disable unhandled error logging for now' (#8) from dev into master
Reviewed-on: #8
2024-01-29 07:57:48 +00:00
72d466b1ec disable unhandled error logging for now 2024-01-29 08:57:28 +01:00
5 changed files with 82 additions and 22 deletions

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

@@ -2,7 +2,10 @@ const DiscordRPC = require("discord-auto-rpc");
const { appName, appVersion } = require("./appInfo.js");
const clientId = "1032772293220384808";
/** @type {DiscordRPC.AutoClient} */
let richPresence;
let intervalId;
let currentStatus = {
@@ -32,6 +35,7 @@ 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);
@@ -47,16 +51,17 @@ 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" : " ";
currentStatus.smallImageText = osuVersion ? `osu! ${osuVersion}` : " ";
updateUser: ({ username, id }) => {
currentStatus.smallImageKey = id ? `https://a.ez-pp.farm/${id}` : " ";
currentStatus.smallImageText = username ?? " ";
},
update: () => {
if (richPresence) {
if (richPresence && richPresence.user) {
richPresence.setActivity(currentStatus);
}
},

62
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.
@@ -72,6 +73,25 @@ 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(
@@ -96,15 +116,32 @@ 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...";
@@ -118,6 +155,7 @@ function startOsuStatus() {
case 5:
details = "Multiplayer: Selecting a Beatmap...";
infoText = " ";
largeImageKey = "ezppfarm";
break;
case 6:
details = "Watching...";
@@ -127,10 +165,12 @@ function startOsuStatus() {
break;
case 9:
details = "Submitting...";
largeImageKey = "ezppfarm";
break;
case 11:
details = "Multiplayer: Idle...";
infoText = " ";
largeImageKey = "ezppfarm";
break;
case 12:
details = "Multiplayer: Playing...";
@@ -138,12 +178,14 @@ function startOsuStatus() {
case 13:
details = "Browsing osu!direct...";
infoText = " ";
largeImageKey = "ezppfarm";
break;
}
richPresence.updateStatus({
details,
state: infoText,
largeImageKey,
});
richPresence.update();
@@ -386,8 +428,7 @@ 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)
})...`,
});
});
@@ -417,8 +458,7 @@ 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)
})...`,
});
});
@@ -464,8 +504,7 @@ 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)
})...`,
});
});
@@ -541,8 +580,6 @@ function registerIPCPipes() {
} catch { }
const userConfig = getUserConfig(osuPath);
richPresence.updateVersion(await userConfig.get("LastVersion"));
richPresence.update();
if (richPresence.hasPresence) {
await userConfig.set("DiscordRichPresence", "0");
}
@@ -563,7 +600,10 @@ function registerIPCPipes() {
mainWindow.show();
mainWindow.focus();
stopOsuStatus();
richPresence.updateVersion();
richPresence.updateUser({
username: " ",
id: undefined
});
richPresence.updateStatus({
state: "Idle in Launcher...",
details: undefined,

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",