feat: improve NodeCG runtime installation and relaunch behavior

This commit is contained in:
2026-05-16 22:22:30 +02:00
parent 41e4e91c4b
commit 955a1f7116
10 changed files with 104 additions and 37 deletions
+11 -1
View File
@@ -80,7 +80,8 @@ export function createNodecgProcessManager({
},
stdio: ["ignore", "pipe", "pipe"],
detached: resolvedDeps.platform !== "win32",
shell: resolvedDeps.platform === "win32",
shell: false,
windowsHide: true,
});
child.stdout?.on("data", (chunk) => {
@@ -163,7 +164,15 @@ export function createNodecgProcessManager({
killNodecgProcessTree(pid, "SIGTERM", log, resolvedDeps);
stopNodecgPromise = new Promise((resolve) => {
let completed = false;
const complete = () => {
if (completed) {
return;
}
completed = true;
if (nodecgProcess === processToStop) {
nodecgProcess = null;
}
@@ -181,6 +190,7 @@ export function createNodecgProcessManager({
if (processToStop.exitCode === null && processToStop.signalCode === null) {
log(`NodeCG did not exit after SIGTERM, forcing SIGKILL pid=${pid}`);
killNodecgProcessTree(pid, "SIGKILL", log, resolvedDeps);
complete();
}
},
Math.max(0, appConfig.nodecgKillTimeoutMs),
+14 -4
View File
@@ -28,6 +28,11 @@ type RuntimeProvisionerDeps = {
writeFileSync: (filePath: string, content: string) => unknown;
};
export type PreparedNodecgRuntime = {
runtimePath: string;
installed: boolean;
};
type RuntimeManifest = {
appVersion?: unknown;
bundleName?: unknown;
@@ -47,14 +52,16 @@ export function prepareUserNodecgRuntime({
bundleName,
log,
deps,
}: RuntimeProvisionerConfig): string {
}: RuntimeProvisionerConfig): PreparedNodecgRuntime {
const resolvedDeps = resolveDeps(deps);
const targetRuntimePath = path.join(userDataPath, "nodecg");
validateSourceRuntime(sourceRuntimePath, bundleName, resolvedDeps.existsSync);
resolvedDeps.mkdirSync(targetRuntimePath, { recursive: true });
if (shouldInstallRuntime(sourceRuntimePath, targetRuntimePath, appVersion, bundleName, resolvedDeps)) {
const installed = shouldInstallRuntime(sourceRuntimePath, targetRuntimePath, appVersion, bundleName, resolvedDeps);
if (installed) {
log(`Installing managed NodeCG runtime into ${targetRuntimePath}`);
installManagedRuntime(sourceRuntimePath, targetRuntimePath, appVersion, bundleName, resolvedDeps);
}
@@ -63,7 +70,7 @@ export function prepareUserNodecgRuntime({
resolvedDeps.mkdirSync(path.join(targetRuntimePath, writableDir), { recursive: true });
}
return targetRuntimePath;
return { runtimePath: targetRuntimePath, installed };
}
function resolveDeps(deps?: Partial<RuntimeProvisionerDeps>): RuntimeProvisionerDeps {
@@ -166,7 +173,10 @@ function installManagedRuntime(
);
}
function readJson(filePath: string, deps: Pick<RuntimeProvisionerDeps, "existsSync" | "readFileSync">): RuntimeManifest | null {
function readJson(
filePath: string,
deps: Pick<RuntimeProvisionerDeps, "existsSync" | "readFileSync">,
): RuntimeManifest | null {
if (!deps.existsSync(filePath)) {
return null;
}