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 committed 2026-04-28 10:20:31 +07:00
1 parent a3032f7a3e
commit 111e78940a
3 files changed
+30 -16

No files matched your search

+6 -5
View File
@@ -1,7 +1,7 @@
import crypto from "crypto";
import { loadState, saveState, generateShortId } from "./state.js";
import { spawnQuickTunnel, killCloudflared, isCloudflaredRunning, setUnexpectedExitHandler } from "./cloudflared.js";
import { startFunnel, stopFunnel, stopDaemon, isTailscaleRunning, isTailscaleLoggedIn, startLogin, startDaemonWithPassword } from "./tailscale.js";
import { startFunnel, stopFunnel, isTailscaleRunning, isTailscaleLoggedIn, startLogin, startDaemonWithPassword } from "./tailscale.js";
import { getSettings, updateSettings } from "@/lib/localDb";
import { getCachedPassword, loadEncryptedPassword, initDbHooks } from "@/mitm/manager";
@@ -16,6 +16,7 @@ let isReconnecting = false;
let exitHandlerRegistered = false;
let reconnectTimeoutId = null;
let manualDisabled = false;
let activeLocalPort = null;
export function isTunnelManuallyDisabled() {
return manualDisabled;
@@ -47,6 +48,7 @@ async function registerTunnelUrl(shortId, tunnelUrl) {
export async function enableTunnel(localPort = 20128) {
manualDisabled = false;
activeLocalPort = localPort;
if (isCloudflaredRunning()) {
const existing = loadState();
@@ -56,7 +58,7 @@ export async function enableTunnel(localPort = 20128) {
}
}
killCloudflared();
killCloudflared(localPort);
const machineId = getMachineId();
const existing = loadState();
@@ -125,7 +127,7 @@ export async function disableTunnel() {
setUnexpectedExitHandler(null);
exitHandlerRegistered = false;
killCloudflared();
killCloudflared(activeLocalPort);
const state = loadState();
if (state) {
@@ -192,9 +194,8 @@ export async function enableTailscale(localPort = 20128) {
}
export async function disableTailscale() {
// Only reset funnel — keep tailscaled daemon running to avoid breaking other apps using Tailscale
stopFunnel();
const sudoPass = getCachedPassword() || await loadEncryptedPassword() || "";
await stopDaemon(sudoPass);
await updateSettings({ tailscaleEnabled: false, tailscaleUrl: "" });
return { success: true };
}