Net core: turning capture on restarts the core cleanly; remember TUN state
After the AmneziaVPN app held the routes, the running core kept Amnezia's utun as its way out; its own TUN reused the same utun name and sent everything into itself (no routes, no DNS). "tun on" now refuses while AmneziaVPN is open and restarts the core; the on/off choice is saved (tun.json) and used on the next start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -313,15 +313,21 @@ final class NetCore: ObservableObject {
|
||||
NSWorkspace.shared.runningApplications.contains { $0.localizedName == "AmneziaVPN" }
|
||||
}
|
||||
|
||||
/// Turns traffic capture on/off without a password (the core keeps running).
|
||||
/// Turns traffic capture on/off without a password. On restarts the core cleanly
|
||||
/// (a few seconds): after AmneziaVPN it would otherwise keep using Amnezia's tunnel.
|
||||
func setTun(_ on: Bool) async {
|
||||
if on && Self.amneziaRunning {
|
||||
lastError = "Сначала выключи AmneziaVPN — иначе она и ядро подерутся за маршрут."
|
||||
lastError = "Сначала закрой AmneziaVPN (⌘Q) — иначе она и ядро подерутся за маршрут."
|
||||
return
|
||||
}
|
||||
lastError = nil
|
||||
tunOn = on
|
||||
_ = await call(["cmd": "tun", "on": on])
|
||||
busy = true
|
||||
let r = await call(["cmd": "tun", "on": on], timeout: 30)
|
||||
busy = false
|
||||
if r?["ok"] as? Bool != true {
|
||||
lastError = "Не включилось: \(r?["error"] as? String ?? "помощник не ответил")."
|
||||
}
|
||||
SoundEngine.shared.play(on ? "pop" : "close")
|
||||
try? await Task.sleep(for: .seconds(1))
|
||||
await refresh()
|
||||
@@ -426,7 +432,7 @@ struct NetPanel: View {
|
||||
.frame(width: 444, alignment: .leading)
|
||||
} else {
|
||||
NetRow(title: "Ядро перехватывает трафик",
|
||||
subtitle: net.tunOn ? "весь трафик Мака идёт через BroV" : "выключено — Мак ходит сам (можно включить AmneziaVPN)",
|
||||
subtitle: net.tunOn ? "весь трафик Мака идёт через BroV" : (net.busy ? "перезапускаю ядро…" : "выключено — Мак ходит сам (можно включить AmneziaVPN)"),
|
||||
delay: nil, isOn: net.tunOn, accent: "#A78BFA") {
|
||||
Task { await net.setTun(!net.tunOn) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user