fix: force mac nordvpn disconnect teardown
This commit is contained in:
@@ -365,6 +365,12 @@ function cleanupMacWireguardState(paths = {}) {
|
||||
return { cleaned };
|
||||
}
|
||||
|
||||
function shouldAttemptMacWireguardDisconnect(wireguardState) {
|
||||
if (!wireguardState) return false;
|
||||
if (wireguardState.active) return true;
|
||||
return Boolean(wireguardState.configPath || wireguardState.endpoint || wireguardState.lastConnection);
|
||||
}
|
||||
|
||||
function fetchJson(url, headers = {}) {
|
||||
return new Promise((resolve) => {
|
||||
const targetUrl = new URL(url);
|
||||
@@ -1107,20 +1113,35 @@ async function disconnectNordvpn(installProbe) {
|
||||
}
|
||||
|
||||
if (installProbe.platform === "darwin" && installProbe.wireguard && installProbe.wireguard.dependenciesReady) {
|
||||
if (!installProbe.wireguard.active) {
|
||||
const cleaned = cleanupMacWireguardState();
|
||||
if (!shouldAttemptMacWireguardDisconnect(installProbe.wireguard)) {
|
||||
const tailscale = await resumeMacTailscaleIfNeeded();
|
||||
return {
|
||||
backend: "wireguard",
|
||||
changed: false,
|
||||
stateCleaned: cleaned.cleaned,
|
||||
tailscaleRestored: tailscale.restored,
|
||||
message: "No active macOS WireGuard NordVPN connection found.",
|
||||
};
|
||||
}
|
||||
const down = await runSudoWireguard(installProbe, "down");
|
||||
if (!down.ok) {
|
||||
throw new Error((down.stderr || down.stdout || down.error).trim() || "wg-quick down failed");
|
||||
const message = (down.stderr || down.stdout || down.error).trim();
|
||||
const normalized = message.toLowerCase();
|
||||
if (
|
||||
normalized.includes("is not a known interface") ||
|
||||
normalized.includes("unable to access interface") ||
|
||||
normalized.includes("not found")
|
||||
) {
|
||||
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.",
|
||||
};
|
||||
}
|
||||
throw new Error(message || "wg-quick down failed");
|
||||
}
|
||||
const cleaned = cleanupMacWireguardState();
|
||||
const tailscale = await resumeMacTailscaleIfNeeded();
|
||||
|
||||
Reference in New Issue
Block a user