launch mechanics working

This commit is contained in:
HorizonCode 2022-10-16 23:10:07 +02:00
parent 72958950b7
commit 5c87704b10
4 changed files with 52 additions and 3 deletions

7
app.js
View File

@ -29,6 +29,13 @@ const run = () => {
app.on('window-all-closed', () => {
app.quit()
})
ipcMain.handle('launch', async () => {
const result = await osuUtil.startOsuWithDevServer(tempOsuPath, "ez-pp.farm", async () => {
await doUpdateCheck(mainWindow);
});
console.log(result);
return result;
})
ipcMain.on('do-update-check', async () => {
await doUpdateCheck(mainWindow);
})

18
executeUtil.js Normal file
View File

@ -0,0 +1,18 @@
const childProcess = require('child_process');
module.exports = {
runFile: (folder, file, args, onExit) => {
childProcess.execFile(file, args, {
cwd: folder
}, (_err, _stdout, _stderr) => {
onExit();
});
},
runFileDetached: (folder, file, args) => {
const subprocess = childProcess.spawn(file + " " + args, {
cwd: folder,
detached: true,
stdio: 'ignore'
})
subprocess.unref()
}
}

View File

@ -3,6 +3,7 @@ const fu = require('./fileUtil');
const path = require('path');
const crypto = require('crypto');
const axios = require('axios').default;
const executeUtil = require('./executeUtil');
const { EventEmitter } = require('events');
const { DownloaderHelper } = require('node-downloader-helper');
@ -122,7 +123,7 @@ async function downloadUpdateFiles(osuPath, filesToUpdate) {
const filePath = path.join(osuPath, fileToUpdate.fileName);
if (await fu.existsAsync(filePath))
await fs.promises.rm(filePath);
const fileDownload = new DownloaderHelper(fileToUpdate.fileURL, osuPath, {
fileName: fileToUpdate.fileName,
override: true,
@ -139,4 +140,12 @@ async function downloadUpdateFiles(osuPath, filesToUpdate) {
return eventEmitter;
}
module.exports = { isValidOsuFolder, getLatestConfig, getUpdateFiles, filesThatNeedUpdate, downloadUpdateFiles }
async function startWithDevServer(osuPath, serverDomain, onExit) {
const osuExe = path.join(osuPath, "osu!.exe");
console.log(osuExe);
if (!await fu.existsAsync(osuExe)) return false;
executeUtil.runFile(osuPath, osuExe, ["-devserver", serverDomain], onExit);
return true;
}
module.exports = { isValidOsuFolder, getLatestConfig, getUpdateFiles, filesThatNeedUpdate, downloadUpdateFiles, startOsuWithDevServer: startWithDevServer }

View File

@ -20,7 +20,22 @@ window.addEventListener('DOMContentLoaded', () => {
$("#launch-btn").on('click', async () => {
switch (currentState) {
case "up-to-date":
//TODO: launch client
$("#launch-btn").attr('disabled', true);
$('#launch-btn').html('Launching...');
const result = await ipcRenderer.invoke("launch");
if (!result) {
Swal.fire({
title: 'Uh oh!',
text: "Something went wrong while launching!",
icon: 'error',
confirmButtonText: 'Okay'
});
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Launch');
} else {
$("#launch-btn").attr('disabled', true);
$('#launch-btn').html('Running...');
}
break;
case "update-available":
$("#launch-btn").attr('disabled', true);