diff --git a/app.js b/app.js index 4956cf6..5569b99 100644 --- a/app.js +++ b/app.js @@ -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); }) diff --git a/executeUtil.js b/executeUtil.js new file mode 100644 index 0000000..cb5d5ae --- /dev/null +++ b/executeUtil.js @@ -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() + } +} \ No newline at end of file diff --git a/osuUtil.js b/osuUtil.js index a7c909f..be13ea3 100644 --- a/osuUtil.js +++ b/osuUtil.js @@ -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 } \ No newline at end of file +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 } \ No newline at end of file diff --git a/preload/preload.js b/preload/preload.js index 303b99e..d2a9c49 100644 --- a/preload/preload.js +++ b/preload/preload.js @@ -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);