Refactor cloudflared process management to improve port-specific termination and enhance tunnel management. Update Antigravity cloaking comments for clarity.

This commit is contained in:
decolua
2026-04-28 10:20:31 +07:00
parent a3032f7a3e
commit 111e78940a
3 changed files with 30 additions and 16 deletions
+16 -5
View File
@@ -360,7 +360,21 @@ export async function spawnQuickTunnel(localPort, onUrlUpdate) {
});
}
export function killCloudflared() {
// Kill cloudflared processes whose command line targets the given port (any host).
// Boundary check ensures :20128 doesn't match :201280 or :202128.
function killCloudflaredByPort(port) {
if (!port) return;
try {
if (IS_WINDOWS) {
const psCmd = `Get-CimInstance Win32_Process -Filter \\"Name='cloudflared.exe'\\" | Where-Object { $_.CommandLine -match ':${port}(\\D|$)' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force }`;
execSync(`powershell -NoProfile -Command "${psCmd}"`, { stdio: "ignore", windowsHide: true });
} else {
execSync(`pkill -f "cloudflared.*:${port}([^0-9]|$)" 2>/dev/null || true`, { stdio: "ignore", windowsHide: true });
}
} catch (e) { /* ignore */ }
}
export function killCloudflared(localPort) {
if (cloudflaredProcess) {
try {
cloudflaredProcess.kill();
@@ -376,10 +390,7 @@ export function killCloudflared() {
clearPid();
}
// Kill any remaining cloudflared processes
try {
execSync("pkill -f cloudflared 2>/dev/null || true", { stdio: "ignore", windowsHide: true });
} catch (e) { /* ignore */ }
killCloudflaredByPort(localPort);
}
export function isCloudflaredRunning() {