diff --git a/package-lock.json b/package-lock.json index e0cc8d0..1565856 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "arena-returns-launcher", - "version": "3.4.2", + "version": "3.5.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "arena-returns-launcher", - "version": "3.4.2", + "version": "3.5.1", "workspaces": [ "packages/*" ], diff --git a/packages/main/src/modules/GameClient.ts b/packages/main/src/modules/GameClient.ts index 35a86fe..aae595d 100644 --- a/packages/main/src/modules/GameClient.ts +++ b/packages/main/src/modules/GameClient.ts @@ -3,7 +3,7 @@ import { join } from "path"; import { existsSync, mkdirSync } from "fs"; import { chmodSync } from "fs"; import { stat, chmod, readdir, readFile, appendFile } from "fs/promises"; -import { exec } from "child_process"; +import { exec, spawn } from "child_process"; import log from "electron-log"; import { GameUpdater, GameSettings, ReplayFile } from "./GameUpdater.js"; import type { AppModule } from "../AppModule.js"; @@ -240,7 +240,7 @@ export class GameClient implements AppModule { let javaExecutable: string; switch (process.platform) { case "win32": - javaExecutable = join(jreDir, "bin", "java.exe"); + javaExecutable = join(jreDir, "bin", "javaw.exe"); break; case "darwin": javaExecutable = join(jreDir, "bin", "java.exe"); @@ -347,20 +347,29 @@ export class GameClient implements AppModule { cwd: string ): Promise { return new Promise((resolve, reject) => { - const child = exec( - `"${javaExecutable}" ${args.join(" ")}`, - { cwd }, - (error) => { - if (error && !error.killed) { - log.error("Java process error:", error); - } - } - ); - if (child.pid) { + log.info("Launching Java process with executable:", javaExecutable); + log.info("Java arguments:", args); + log.info("Working directory:", cwd); + + const child = spawn(javaExecutable, args, { + cwd, + detached: true, + stdio: "ignore", + windowsHide: true, // Hide the console window on Windows + shell: true, // Enable shell parsing for proper quote handling + }); + + child.on("error", (error) => { + log.error("Failed to start Java process:", error); + reject(new Error(`Failed to start Java process: ${error.message}`)); + }); + + child.on("spawn", () => { + log.info("Java process started successfully with PID:", child.pid); + // Unref the child process so the parent can exit without waiting + child.unref(); resolve(); - } else { - reject(new Error("Failed to start Java process")); - } + }); }); }