From e0c821cad9f887abf8307f86e8f0ed81ea6a6990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=AFs=20Betts?= Date: Wed, 20 Nov 2024 15:54:13 +0100 Subject: [PATCH] Special-case this fix to Electron apps --- src/client/stdio.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/client/stdio.ts b/src/client/stdio.ts index af9841fd..4c78b356 100644 --- a/src/client/stdio.ts +++ b/src/client/stdio.ts @@ -112,9 +112,18 @@ export class StdioClientTransport implements Transport { env: this._serverParams.env ?? getDefaultEnvironment(), stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"], shell: false, - detached: process.platform === "win32", signal: this._abortController.signal, - }, + + // NB: The behavior of detached varies based on platform, and also + // is different based on whether the process is a Win32 Subsystem + // process or a Console Subsystem process. Strangely, the behavior + // of detached is almost 1:1 the opposite in Electron+Windows vs + // what is documented on the node.js website, and also is different + // based on whether you launch Electron in a development environment + // (i.e. via `electron-forge start`) vs a production environment + // (i.e. YourApp.exe). + detached: process.platform === "win32" && isElectron(), + } ); this._process.on("error", (error) => { @@ -188,3 +197,7 @@ export class StdioClientTransport implements Transport { }); } } + +function isElectron() { + return "type" in process; +}