]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
macOS: Show alert if exiting with an active tunnel
authorRoopesh Chander <roop@roopc.net>
Thu, 7 Feb 2019 21:31:17 +0000 (03:01 +0530)
committerRoopesh Chander <roop@roopc.net>
Thu, 7 Feb 2019 23:10:11 +0000 (04:40 +0530)
Instead of deactivating the tunnel.

Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/WireGuard/Base.lproj/Localizable.strings
WireGuard/WireGuard/UI/macOS/AppDelegate.swift

index 25d773936a5ee95b073dc9b2f40fde7ed5e535b9..b92336095f313dff6882d9f75f3749aaf3050f4d 100644 (file)
 "macViewPrivateData" = "view tunnel private keys";
 "iosExportPrivateData" = "Authenticate to export tunnel private keys.";
 "iosViewPrivateData" = "Authenticate to view tunnel private keys.";
+
+// Mac alert
+
+"macAppExitingWithActiveTunnelMessage" = "WireGuard is exiting with an active tunnel";
+"macAppExitingWithActiveTunnelInfo" = "The tunnel will remain active after exiting. You may disable it by reopening this application or through the Network panel in System Preferences.";
index 5546eef193f07597b5a37bf3522cf969081fe190..fde1a27622bfb62708ff321763508379eee9e1e1 100644 (file)
@@ -12,6 +12,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
 
     var manageTunnelsRootVC: ManageTunnelsRootViewController?
     var manageTunnelsWindowObject: NSWindow?
+    var isTerminationAlertShown = false
 
     func applicationDidFinishLaunching(_ aNotification: Notification) {
         Logger.configureGlobal(withFilePath: FileManager.appLogFileURL?.path)
@@ -41,9 +42,25 @@ class AppDelegate: NSObject, NSApplicationDelegate {
         }
     }
 
-    func applicationWillTerminate(_ notification: Notification) {
-        if let currentTunnel = tunnelsTracker?.currentTunnel {
-            tunnelsManager?.startDeactivation(of: currentTunnel)
+    func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
+        guard let currentTunnel = tunnelsTracker?.currentTunnel, currentTunnel.status == .active || currentTunnel.status == .activating else {
+            return .terminateNow
+        }
+        if isTerminationAlertShown {
+            return .terminateNow
+        }
+        let alert = NSAlert()
+        alert.messageText = tr("macAppExitingWithActiveTunnelMessage")
+        alert.informativeText = tr("macAppExitingWithActiveTunnelInfo")
+        if let window = manageTunnelsWindowObject {
+            alert.beginSheetModal(for: window) { [weak self] _ in
+                self?.isTerminationAlertShown = true
+                NSApp.terminate(nil)
+            }
+            return .terminateCancel
+        } else {
+            alert.runModal()
+            return .terminateNow
         }
     }
 }