diff --git a/main.js b/main.js index 52fd20d..218c870 100644 --- a/main.js +++ b/main.js @@ -45,39 +45,12 @@ let userOsuPath; let osuLoaded = false; let patch = false; -let terminate = false; -let finishedUpdating = false; - let currentUser = undefined; function isDev() { return !app.isPackaged; } -async function waitForTermination() { - terminate = true; - return new Promise((res) => { - const checkInterval = setInterval(async () => { - const osuWindowTitle = windowName.getWindowText("osu!.exe"); - if (osuWindowTitle.length < 0) { - return; - } - const firstInstance = osuWindowTitle[0]; - console.log({ terminate, firstInstance }); - if (terminate && finishedUpdating) { - console.log("terminating..."); - finishedUpdating = false; - terminate = false; - const processId = firstInstance.processId; - await fkill(processId, { force: true, silent: true }); - clearInterval(checkInterval); - res(); - console.log("terminated"); - } - }, 500); - }); -} - function startOsuStatus() { osuCheckInterval = setInterval(async () => { const osuWindowTitle = windowName.getWindowText("osu!.exe"); @@ -87,7 +60,6 @@ function startOsuStatus() { const firstInstance = osuWindowTitle[0]; if (firstInstance) { - console.log(osuWindowTitle); if (!osuLoaded) { osuLoaded = true; setTimeout(() => { @@ -507,14 +479,28 @@ function registerIPCPipes() { } mainWindow.webContents.send("ezpplauncher:launchstatus", { - status: "Launching osu updater to verify...", + status: "Launching osu! updater to verify...", }); await new Promise((res) => setTimeout(res, 1000)); - runOsuUpdater(osuPath, () => { - finishedUpdating = true; + await new Promise((res) => { + runOsuUpdater(osuPath, async () => { + await new Promise((res) => setTimeout(res, 500)); + const terminationThread = setInterval(async () => { + const osuWindowTitle = windowName.getWindowText("osu!.exe"); + if (osuWindowTitle.length < 0) { + return; + } + const firstInstance = osuWindowTitle[0]; + if (firstInstance) { + const processId = firstInstance.processId; + await fkill(processId, { force: true, silent: true }); + clearInterval(terminationThread); + res(); + } + }, 500); + }); }); - await waitForTermination(); await new Promise((res) => setTimeout(res, 1000));