Skip to content

Commit 4e891d9

Browse files
committed
Clean up stale tunnel on app launch and quit
Kill any leftover tunnel helper from a previous session on startup, preventing stale utun interfaces and routes from hijacking traffic. Also tear down tunnel on app quit via willTerminateNotification.
1 parent afcfbf3 commit 4e891d9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

apps/LemonadeNexusMac/Sources/LemonadeNexusMac/LemonadeNexusApp.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ struct LemonadeNexusApp: App {
1212
.frame(minWidth: 900, minHeight: 600)
1313
.onAppear {
1414
configureAppearance()
15+
// Clean up tunnel on app quit
16+
NotificationCenter.default.addObserver(
17+
forName: NSApplication.willTerminateNotification,
18+
object: nil, queue: .main) { _ in
19+
TunnelManager.shared.cleanupStaleHelper()
20+
}
1521
if appState.autoDiscoveryEnabled {
1622
Task {
1723
await appState.discoverNearestServer()
@@ -87,6 +93,9 @@ struct LemonadeNexusApp: App {
8793
}
8894

8995
private func configureAppearance() {
96+
// Kill any stale tunnel helper from a previous session
97+
TunnelManager.shared.cleanupStaleHelper()
98+
9099
// Set the accent color globally
91100
NSApplication.shared.appearance = NSAppearance(named: .aqua)
92101

apps/LemonadeNexusMac/Sources/LemonadeNexusMac/Services/TunnelManager.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ final class TunnelManager: ObservableObject {
1515
private let configPath = "/tmp/lnsdk_wg0.json"
1616
private let pidPath = "/tmp/lnsdk_tunnel.pid"
1717

18+
/// Clean up any stale tunnel from a previous app session.
19+
/// Called once on app launch before any tunnel operations.
20+
func cleanupStaleHelper() {
21+
killExistingHelper()
22+
}
23+
1824
/// Path to the tunnel helper binary (built alongside the main app).
1925
private var helperPath: String {
2026
// The helper binary is in the same directory as the main app binary

0 commit comments

Comments
 (0)