fix updating task

This commit is contained in:
HorizonCode 2024-01-25 08:54:02 +01:00
parent 4348c36fa0
commit 2329122ef0
1 changed files with 18 additions and 32 deletions

50
main.js
View File

@ -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));