Skip to content

Commit 720043a

Browse files
dorlugasigalCopilot
andcommitted
fix(windows): add windowsHide to all child_process calls
Extend windowsHide: true to git, shell detection, agent detection, version check, and update executor modules. The initial fix only covered tunnel and service modules but git commands (polled by the frontend) were the main source of flashing console windows. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 406096a commit 720043a

6 files changed

Lines changed: 46 additions & 30 deletions

File tree

src/cli/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function getWindowsAncestors(startPid, maxDepth = 4) {
7979
const result = execFileSync(
8080
'wmic',
8181
['process', 'get', 'Name,ParentProcessId,ProcessId', '/format:csv'],
82-
{ stdio: ['pipe', 'pipe', 'ignore'], encoding: 'utf8', timeout: 5000 },
82+
{ stdio: ['pipe', 'pipe', 'ignore'], encoding: 'utf8', timeout: 5000, windowsHide: true },
8383
);
8484

8585
// Parse CSV output — first non-empty line is the header

src/utils/agents.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,29 @@ function tryDetectAgent(agent) {
6262
let remaining = candidates.length;
6363

6464
for (const bin of candidates) {
65-
child_process.execFile(bin, args, { timeout: 5000, encoding: 'utf8' }, (err, stdout) => {
66-
remaining--;
67-
if (resolved) return;
68-
if (!err) {
69-
resolved = true;
70-
const version = (stdout || '').trim().split('\n')[0] || 'unknown';
71-
resolve({
72-
id: agent.id,
73-
name: agent.name,
74-
cmd: agent.cmd,
75-
args: agent.args || [],
76-
icon: agent.icon,
77-
version,
78-
});
79-
} else if (remaining === 0) {
80-
resolve(null);
81-
}
82-
});
65+
child_process.execFile(
66+
bin,
67+
args,
68+
{ timeout: 5000, encoding: 'utf8', windowsHide: true },
69+
(err, stdout) => {
70+
remaining--;
71+
if (resolved) return;
72+
if (!err) {
73+
resolved = true;
74+
const version = (stdout || '').trim().split('\n')[0] || 'unknown';
75+
resolve({
76+
id: agent.id,
77+
name: agent.name,
78+
cmd: agent.cmd,
79+
args: agent.args || [],
80+
icon: agent.icon,
81+
version,
82+
});
83+
} else if (remaining === 0) {
84+
resolve(null);
85+
}
86+
},
87+
);
8388
}
8489
});
8590
}

src/utils/git.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ const path = require('path');
33
const log = require('./logger');
44

55
function git(cmd, cwd) {
6-
return execSync(`git ${cmd}`, { cwd, stdio: 'pipe', timeout: 3000 }).toString().trim();
6+
return execSync(`git ${cmd}`, { cwd, stdio: 'pipe', timeout: 3000, windowsHide: true })
7+
.toString()
8+
.trim();
79
}
810

911
function getGitInfo(cwd) {
@@ -144,7 +146,7 @@ async function getGitRoot(cwd) {
144146
require('child_process').execFile(
145147
'git',
146148
['rev-parse', '--show-toplevel'],
147-
{ cwd, timeout: GIT_TIMEOUT },
149+
{ cwd, timeout: GIT_TIMEOUT, windowsHide: true },
148150
(err, stdout) => {
149151
if (err) return reject(err);
150152
resolve(stdout.trim());
@@ -167,6 +169,7 @@ async function gitAsync(args, cwd, options = {}) {
167169
cwd,
168170
timeout: options.timeout || GIT_TIMEOUT,
169171
maxBuffer: options.maxBuffer || MAX_DIFF_BUFFER,
172+
windowsHide: true,
170173
},
171174
(err, stdout) => {
172175
if (err) return reject(err);
@@ -343,6 +346,7 @@ async function getFileDiff(cwd, filePath, options = {}) {
343346
cwd: root,
344347
timeout: GIT_TIMEOUT,
345348
maxBuffer: MAX_DIFF_BUFFER,
349+
windowsHide: true,
346350
},
347351
(err, stdout) => {
348352
// git diff --no-index exits with 1 when files differ — that's expected

src/utils/shells.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function detectWindowsShells() {
2525
stdio: ['pipe', 'pipe', 'ignore'],
2626
encoding: 'utf8',
2727
timeout: 3000,
28+
windowsHide: true,
2829
});
2930
const fullPath = result.trim().split('\n')[0].trim();
3031
if (fullPath) {

src/utils/update-executor.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,20 @@ function clearUpdateResult() {
339339

340340
function execFilePromise(cmd, args, options = {}) {
341341
return new Promise((resolve, reject) => {
342-
execFile(cmd, args, { encoding: 'utf8', ...options }, (err, stdout, stderr) => {
343-
if (err) {
344-
err.stdout = stdout;
345-
err.stderr = stderr;
346-
reject(err);
347-
} else {
348-
resolve({ stdout, stderr });
349-
}
350-
});
342+
execFile(
343+
cmd,
344+
args,
345+
{ encoding: 'utf8', windowsHide: true, ...options },
346+
(err, stdout, stderr) => {
347+
if (err) {
348+
err.stdout = stdout;
349+
err.stderr = stderr;
350+
reject(err);
351+
} else {
352+
resolve({ stdout, stderr });
353+
}
354+
},
355+
);
351356
});
352357
}
353358

src/utils/version.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function getVersion() {
2323
cwd: path.join(__dirname, '..', '..'),
2424
encoding: 'utf-8',
2525
stdio: ['pipe', 'pipe', 'pipe'],
26+
windowsHide: true,
2627
}).trim();
2728

2829
const tagMatch = gitDesc.match(/^v(\d+\.\d+\.\d+)(?:-(\d+)-g([0-9a-f]+))?(-dirty)?$/);

0 commit comments

Comments
 (0)