Add Useragent Headers, better error message handling on login, fix logger toggle #19

Merged
HorizonCode merged 6 commits from dev into master 2024-07-17 08:37:42 +00:00
Showing only changes of commit 6d42b4fe89 - Show all commits

34
main.js
View File

@ -116,7 +116,8 @@ function startOsuStatus() {
const windowTitle = firstInstance.processTitle; const windowTitle = firstInstance.processTitle;
lastOsuStatus = windowTitle; lastOsuStatus = windowTitle;
const currentStatusRequest = await fetch( const currentStatusRequest = await fetch(
"https://api.ez-pp.farm/v1/get_player_status?name=" + currentUser.username, "https://api.ez-pp.farm/v1/get_player_status?name=" +
currentUser.username,
); );
const currentStatus = await currentStatusRequest.json(); const currentStatus = await currentStatusRequest.json();
@ -127,7 +128,8 @@ function startOsuStatus() {
const currentModeString = gamemodes[currentMode]; const currentModeString = gamemodes[currentMode];
const currentInfoRequest = await fetch( const currentInfoRequest = await fetch(
"https://api.ez-pp.farm/v1/get_player_info?name=" + currentUser.username + "&scope=all", "https://api.ez-pp.farm/v1/get_player_info?name=" +
currentUser.username + "&scope=all",
); );
const currentInfo = await currentInfoRequest.json(); const currentInfo = await currentInfoRequest.json();
let currentUsername = currentInfo.player.info.name; let currentUsername = currentInfo.player.info.name;
@ -237,7 +239,7 @@ function registerIPCPipes() {
}; };
} }
const timeout = new AbortController(); const timeout = new AbortController();
const timeoutId = setTimeout(() => timeout.abort(), 8000); const timeoutId = setTimeout(() => timeout.abort(), 1000 * 10);
logger.log(`Logging in with user ${args.username}...`); logger.log(`Logging in with user ${args.username}...`);
try { try {
const fetchResult = await fetch("https://ez-pp.farm/login/check", { const fetchResult = await fetch("https://ez-pp.farm/login/check", {
@ -268,7 +270,7 @@ function registerIPCPipes() {
return result; return result;
} }
logger.log( logger.log(
`Login failed for user ${username}.\nResponse:\n${await fetchResult `Login failed for user ${args.username}.\nResponse:\n${await fetchResult
.text()}`, .text()}`,
); );
return { return {
@ -384,7 +386,7 @@ function registerIPCPipes() {
} }
if (key == "logging") { if (key == "logging") {
logger.enabled = logging; logger.enabled = value;
} }
if (typeof value == "boolean") { if (typeof value == "boolean") {
@ -432,8 +434,9 @@ function registerIPCPipes() {
ipcMain.handle("ezpplauncher:checkUpdate", async (e) => { ipcMain.handle("ezpplauncher:checkUpdate", async (e) => {
const updateInfo = await updateAvailable(); const updateInfo = await updateAvailable();
if (updateInfo.update) if (updateInfo.update) {
mainWindow.webContents.send("ezpplauncher:update", updateInfo.release); mainWindow.webContents.send("ezpplauncher:update", updateInfo.release);
}
}); });
ipcMain.handle("ezpplauncher:exitAndUpdate", async (e) => { ipcMain.handle("ezpplauncher:exitAndUpdate", async (e) => {
@ -529,8 +532,9 @@ 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)
})...`,
}); });
}); });
await updateDownloader.startDownload(); await updateDownloader.startDownload();
@ -557,13 +561,15 @@ function registerIPCPipes() {
status: "Looking for patcher updates...", status: "Looking for patcher updates...",
}); });
await new Promise((res) => setTimeout(res, 1000)); await new Promise((res) => setTimeout(res, 1000));
const [patchFiles, allUpdateFiles] = await getEZPPLauncherUpdateFiles(osuPath); const [patchFiles, allUpdateFiles] = await getEZPPLauncherUpdateFiles(
osuPath,
);
if (patchFiles.length > 0) { if (patchFiles.length > 0) {
logger.log("EZPPLauncher updates found."); logger.log("EZPPLauncher updates found.");
const patcherDownloader = await downloadEZPPLauncherUpdateFiles( const patcherDownloader = await downloadEZPPLauncherUpdateFiles(
osuPath, osuPath,
patchFiles, patchFiles,
allUpdateFiles allUpdateFiles,
); );
let errored = false; let errored = false;
patcherDownloader.eventEmitter.on("error", (data) => { patcherDownloader.eventEmitter.on("error", (data) => {
@ -584,8 +590,9 @@ 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) status: `Downloading ${data.fileName}(${
}/${formatBytes(data.total)})...`, formatBytes(data.loaded)
}/${formatBytes(data.total)})...`,
}); });
}); });
patcherDownloader.eventEmitter.on("delete", (data) => { patcherDownloader.eventEmitter.on("delete", (data) => {
@ -728,7 +735,8 @@ function registerIPCPipes() {
const osuGameplayFile = path.join(osuPath, "osu!gameplay.dll"); const osuGameplayFile = path.join(osuPath, "osu!gameplay.dll");
if (isWritable(osuUIFile) && isWritable(osuGameplayFile)) { if (isWritable(osuUIFile) && isWritable(osuGameplayFile)) {
logger.log( logger.log(
`Cleanup complete, took ${((performance.now() - timeStart) / 1000).toFixed(3) `Cleanup complete, took ${
((performance.now() - timeStart) / 1000).toFixed(3)
} seconds.`, } seconds.`,
); );
clearInterval(cleanup); clearInterval(cleanup);