fix(hooks): prevent console window flash on Windows (#167)
On Windows, the detached spawn option creates a visible console window. Combined with npm (which is a .cmd batch file), this causes a brief window flash that steals focus from the user's terminal. - Remove detached: true (not needed, child.unref() handles non-blocking) - Add windowsHide: true to both spawn() and inner execSync()
This commit is contained in:
@@ -17,7 +17,7 @@ if (!fs.existsSync(cacheDir)) {
|
|||||||
fs.mkdirSync(cacheDir, { recursive: true });
|
fs.mkdirSync(cacheDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run check in background (spawn detached process)
|
// Run check in background (spawn background process, windowsHide prevents console flash)
|
||||||
const child = spawn(process.execPath, ['-e', `
|
const child = spawn(process.execPath, ['-e', `
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
@@ -32,7 +32,7 @@ const child = spawn(process.execPath, ['-e', `
|
|||||||
|
|
||||||
let latest = null;
|
let latest = null;
|
||||||
try {
|
try {
|
||||||
latest = execSync('npm view get-shit-done-cc version', { encoding: 'utf8', timeout: 10000 }).trim();
|
latest = execSync('npm view get-shit-done-cc version', { encoding: 'utf8', timeout: 10000, windowsHide: true }).trim();
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
@@ -44,8 +44,8 @@ const child = spawn(process.execPath, ['-e', `
|
|||||||
|
|
||||||
fs.writeFileSync(cacheFile, JSON.stringify(result));
|
fs.writeFileSync(cacheFile, JSON.stringify(result));
|
||||||
`], {
|
`], {
|
||||||
detached: true,
|
stdio: 'ignore',
|
||||||
stdio: 'ignore'
|
windowsHide: true
|
||||||
});
|
});
|
||||||
|
|
||||||
child.unref();
|
child.unref();
|
||||||
|
|||||||
Reference in New Issue
Block a user