extend timeout to 10 seconds, fix undefined values

This commit is contained in:
HorizonCode 2024-07-17 10:19:28 +02:00
parent cd8f42327c
commit 6d42b4fe89

30
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,7 +532,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)
})...`, })...`,
}); });
}); });
@ -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,7 +590,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) status: `Downloading ${data.fileName}(${
formatBytes(data.loaded)
}/${formatBytes(data.total)})...`, }/${formatBytes(data.total)})...`,
}); });
}); });
@ -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);