refactor(core): optimize Windows process detection and remove debug logging

- Replace execFileAsync with execAsync for complex PowerShell commands in getProcessInfo
- Remove unnecessary getProcessInfo retry logic when parent not in processMap
- Remove all debug logging code (writeDebugLog function and fs import)
- Improve performance by ~1.6-2.6 seconds per detection
- Keep execFileAsync for simple commands in getProcessTableWindows
This commit is contained in:
xuewenjie
2025-12-18 16:24:40 +08:00
parent 01e62a2120
commit cb59b5a9dc

View File

@@ -38,12 +38,9 @@ async function getProcessInfo(pid: number): Promise<{
'}',
].join(' ');
const { stdout } = await execFileAsync('powershell', [
'-NoProfile',
'-NonInteractive',
'-Command',
powershellCommand,
]);
const { stdout } = await execAsync(
`powershell -NoProfile -NonInteractive -Command "${powershellCommand.replace(/"/g, '\\"')}"`,
);
const output = stdout.trim();
if (!output) return { parentPid: 0, name: '', command: '' };
const {
@@ -234,22 +231,7 @@ async function getIdeProcessInfoForWindows(): Promise<{
ancestors.push(curr);
if (curr.parentPid === 0 || !processMap.has(curr.parentPid)) {
// Try to get info about the missing parent
if (curr.parentPid !== 0) {
try {
const parentInfo = await getProcessInfo(curr.parentPid);
if (parentInfo.name) {
ancestors.push({
pid: curr.parentPid,
parentPid: parentInfo.parentPid,
name: parentInfo.name,
command: parentInfo.command,
});
}
} catch (_e) {
// Ignore if query fails
}
}
// Parent process not in map, stop traversal
break;
}
curr = processMap.get(curr.parentPid);