From: Roopesh Chander Date: Wed, 23 Jan 2019 11:01:26 +0000 (+0530) Subject: macOS: Deactivate any active tunnel when app exits X-Git-Tag: 0.0.20190207-1~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5a76be6fdf0d1365d6cb8d3f3df517d615d4b3a;p=thirdparty%2Fwireguard-apple.git macOS: Deactivate any active tunnel when app exits Signed-off-by: Roopesh Chander --- diff --git a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift index 76ac000..5546eef 100644 --- a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift +++ b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift @@ -40,6 +40,12 @@ class AppDelegate: NSObject, NSApplicationDelegate { self.statusItemController = statusItemController } } + + func applicationWillTerminate(_ notification: Notification) { + if let currentTunnel = tunnelsTracker?.currentTunnel { + tunnelsManager?.startDeactivation(of: currentTunnel) + } + } } extension AppDelegate: StatusMenuWindowDelegate { diff --git a/WireGuard/WireGuard/UI/macOS/TunnelsTracker.swift b/WireGuard/WireGuard/UI/macOS/TunnelsTracker.swift index 3d29b02..9c93186 100644 --- a/WireGuard/WireGuard/UI/macOS/TunnelsTracker.swift +++ b/WireGuard/WireGuard/UI/macOS/TunnelsTracker.swift @@ -16,7 +16,7 @@ class TunnelsTracker { private var tunnelsManager: TunnelsManager private var tunnelStatusObservers = [AnyObject]() - private var currentTunnel: TunnelContainer? { + private(set) var currentTunnel: TunnelContainer? { didSet { statusMenu?.currentTunnel = currentTunnel statusItemController?.currentTunnel = currentTunnel