feat: add macOS app bundle paths and support case-insensitive process termination for Antigravity executables#146
feat: add macOS app bundle paths and support case-insensitive process termination for Antigravity executables#146Frazix12 wants to merge 2 commits intoDraculabo:mainfrom
Conversation
…ccidental termination of manager processes
… termination for Antigravity executables
| const processList: { pid: number; name: string; cmd: string }[] = []; | ||
|
|
||
| if (platform === 'win32') { | ||
| // Parse CSV Output | ||
| // Parse CSV output: first line is headers, data starts at index 1 | ||
| const lines = output.trim().split(/\r?\n/); | ||
| // First line is headers "ProcessId","Name","CommandLine" | ||
| // We start from index 1 | ||
| for (let i = 1; i < lines.length; i++) { | ||
| const line = lines[i]; | ||
| if (!line) { | ||
| continue; | ||
| } | ||
|
|
||
| // Regex to match CSV fields: "val1","val2","val3" | ||
| // Match CSV fields: "val1","val2","val3" | ||
| const match = line.match(/^"(\d+)","(.*?)","(.*?)"$/); | ||
|
|
||
| if (match) { | ||
| const pid = parseInt(match[1]); | ||
| const name = match[2]; | ||
| const cmdLine = match[3]; | ||
|
|
||
| processList.push({ pid, name, cmd: cmdLine || name }); | ||
| } | ||
| } | ||
| } else { | ||
| const lines = output.split('\n'); | ||
| for (const line of lines) { | ||
| const parts = line.trim().split(/\s+/); | ||
| if (parts.length < 2) continue; | ||
| if (parts.length < 2) { | ||
| continue; | ||
| } | ||
|
|
||
| const pid = parseInt(parts[0]); | ||
| if (isNaN(pid)) continue; | ||
| const rest = parts.slice(1).join(' '); | ||
| if (rest.includes('Antigravity') || rest.includes('antigravity')) { | ||
| processList.push({ pid, name: parts[1], cmd: rest }); | ||
| if (isNaN(pid)) { | ||
| continue; | ||
| } | ||
|
|
||
| const cmd = parts.slice(1).join(' '); | ||
|
|
||
| // Only include processes running from a known Antigravity install | ||
| // path. Because we use `pid,args` (no comm column), parts[1] is | ||
| // the real executable path, so startsWith is reliable here. | ||
| const isFromInstallPath = ANTIGRAVITY_INSTALL_PATH_PREFIXES.some((prefix) => | ||
| cmd.startsWith(prefix), | ||
| ); | ||
| if (isFromInstallPath) { | ||
| processList.push({ pid, name: parts[1] ?? '', cmd }); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
The parsing logic for the Unix process list assumes that the output of ps -A -o pid,args is always well-formed and that parts[1] is the executable path. If the output format changes, or if a line is malformed (e.g., missing fields), this could result in missed processes or incorrect filtering. Consider adding more robust validation and error handling for unexpected or malformed lines to ensure that all relevant processes are correctly identified.
Recommended solution:
- Add explicit checks for the expected number of fields and handle cases where the line does not match the expected format.
- Log or skip malformed lines to avoid silent failures.
| if (p.pid === currentPid) { | ||
| return false; | ||
| } | ||
| // Exclude this electron app (if named Antigravity Manager or antigravity-manager) | ||
| if (p.cmd.includes('Antigravity Manager') || p.cmd.includes('antigravity-manager')) { | ||
| // Exclude the manager app under all naming variants (defensive) | ||
| if ( | ||
| p.cmd.includes('AntigravityManager') || | ||
| p.cmd.includes('Antigravity Manager') || | ||
| p.cmd.includes('antigravity-manager') | ||
| ) { | ||
| return false; | ||
| } | ||
| // Match Antigravity (but not manager) | ||
| // Windows: match by executable name | ||
| if (platform === 'win32') { | ||
| return ( | ||
| p.cmd.includes('Antigravity.exe') || | ||
| (p.cmd.includes('antigravity') && !p.cmd.includes('manager')) | ||
| ); | ||
| } else { | ||
| // Explicit !manager check for Linux/macOS to be defensive | ||
| return ( | ||
| (p.cmd.includes('Antigravity') || p.cmd.includes('antigravity')) && | ||
| !p.cmd.includes('manager') | ||
| ); | ||
| } | ||
| // Linux/macOS: already filtered to install-path processes above | ||
| return true; | ||
| }); | ||
|
|
||
| if (targetProcessList.length === 0) { |
There was a problem hiding this comment.
The filtering logic for manager processes and executable names is case-sensitive (e.g., p.cmd.includes('AntigravityManager')). On case-insensitive filesystems (such as Windows), this could result in false negatives, allowing manager processes to be incorrectly included in the target process list. This could lead to unintended termination of the manager process.
Recommended solution:
- Normalize both the command and the filter strings to lowercase before performing inclusion checks, e.g.,
p.cmd.toLowerCase().includes('antigravitymanager').
| // while Linux installs use 'antigravity' (lowercase). | ||
| // Errors are swallowed intentionally — process may already be gone or | ||
| // the variant may not exist on this platform. | ||
| try { |
There was a problem hiding this comment.
Could you clarify why we need to call this twice?
No description provided.