fix: clear stale nordvpn disconnect state

This commit is contained in:
Stefano Fiorini
2026-03-12 02:08:34 -05:00
parent 09b1c1e37a
commit b4c8d3fdb8
2 changed files with 42 additions and 0 deletions

View File

@@ -349,6 +349,22 @@ function buildLookupResult(address, options = {}) {
return [address, 4];
}
function cleanupMacWireguardState(paths = {}) {
const targets = [paths.configPath || WG_CONFIG_PATH, paths.lastConnectionPath || LAST_CONNECTION_PATH];
let cleaned = false;
for (const target of targets) {
try {
if (target && fs.existsSync(target)) {
fs.unlinkSync(target);
cleaned = true;
}
} catch {
// Ignore cleanup errors; caller will rely on current runtime state.
}
}
return { cleaned };
}
function fetchJson(url, headers = {}) {
return new Promise((resolve) => {
const targetUrl = new URL(url);
@@ -1092,10 +1108,12 @@ async function disconnectNordvpn(installProbe) {
if (installProbe.platform === "darwin" && installProbe.wireguard && installProbe.wireguard.dependenciesReady) {
if (!installProbe.wireguard.active) {
const cleaned = cleanupMacWireguardState();
const tailscale = await resumeMacTailscaleIfNeeded();
return {
backend: "wireguard",
changed: false,
stateCleaned: cleaned.cleaned,
tailscaleRestored: tailscale.restored,
message: "No active macOS WireGuard NordVPN connection found.",
};
@@ -1104,10 +1122,12 @@ async function disconnectNordvpn(installProbe) {
if (!down.ok) {
throw new Error((down.stderr || down.stdout || down.error).trim() || "wg-quick down failed");
}
const cleaned = cleanupMacWireguardState();
const tailscale = await resumeMacTailscaleIfNeeded();
return {
backend: "wireguard",
changed: true,
stateCleaned: cleaned.cleaned,
tailscaleRestored: tailscale.restored,
message: "Disconnected the macOS NordLynx/WireGuard session.",
};