fix updating task

This commit is contained in:
HorizonCode 2024-01-25 08:54:02 +01:00
parent 4348c36fa0
commit 2329122ef0

50
main.js
View File

@ -45,39 +45,12 @@ let userOsuPath;
let osuLoaded = false; let osuLoaded = false;
let patch = false; let patch = false;
let terminate = false;
let finishedUpdating = false;
let currentUser = undefined; let currentUser = undefined;
function isDev() { function isDev() {
return !app.isPackaged; 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() { function startOsuStatus() {
osuCheckInterval = setInterval(async () => { osuCheckInterval = setInterval(async () => {
const osuWindowTitle = windowName.getWindowText("osu!.exe"); const osuWindowTitle = windowName.getWindowText("osu!.exe");
@ -87,7 +60,6 @@ function startOsuStatus() {
const firstInstance = osuWindowTitle[0]; const firstInstance = osuWindowTitle[0];
if (firstInstance) { if (firstInstance) {
console.log(osuWindowTitle);
if (!osuLoaded) { if (!osuLoaded) {
osuLoaded = true; osuLoaded = true;
setTimeout(() => { setTimeout(() => {
@ -507,14 +479,28 @@ function registerIPCPipes() {
} }
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Launching osu updater to verify...", status: "Launching osu! updater to verify...",
}); });
await new Promise((res) => setTimeout(res, 1000)); await new Promise((res) => setTimeout(res, 1000));
runOsuUpdater(osuPath, () => { await new Promise((res) => {
finishedUpdating = true; 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)); await new Promise((res) => setTimeout(res, 1000));