Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 24 additions & 15 deletions packages/main/src/modules/GameClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -347,20 +347,29 @@ export class GameClient implements AppModule {
cwd: string
): Promise<void> {
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"));
}
});
});
}

Expand Down
Loading