Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Fix the issue where the launch shortcut window never closes after launching BS #485

Merged
merged 1 commit into from
May 20, 2024
Merged
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
23 changes: 22 additions & 1 deletion src/main/services/bs-launcher/abstract-launcher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BSLocalVersionService } from "../bs-local-version.service";
import { ChildProcessWithoutNullStreams, SpawnOptionsWithoutStdio, spawn } from "child_process";
import path from "path";
import log from "electron-log";
import { sToMs } from "shared/helpers/time.helpers";

export abstract class AbstractLauncherService {

Expand Down Expand Up @@ -46,20 +47,40 @@ export abstract class AbstractLauncherService {

}

protected launchBs(bsExePath: string, args: string[], options?: SpawnOptionsWithoutStdio): {process: ChildProcessWithoutNullStreams, exit: Promise<number>} {
protected launchBs(bsExePath: string, args: string[], options?: SpawnBsProcessOptions): {process: ChildProcessWithoutNullStreams, exit: Promise<number>} {
const process = this.launchBSProcess(bsExePath, args, options);

let timoutId: NodeJS.Timeout;

const exit = new Promise<number>((resolve, reject) => {

process.on("error", (err) => {
log.error(`Error while launching BS`, err);
reject(err);
});

process.on("exit", (code) => {
log.info(`BS process exit with code ${code}`);
resolve(code);
});

const unrefAfter = options?.unrefAfter ?? sToMs(10);

timoutId = setTimeout(() => {
log.error("BS process unref after timeout", unrefAfter);
process.unref();
process.removeAllListeners();
resolve(-1);
}, unrefAfter);

}).finally(() => {
clearTimeout(timoutId);
});

return { process, exit };
}
}

export type SpawnBsProcessOptions = {
unrefAfter?: number;
} & SpawnOptionsWithoutStdio;
Loading