]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
macOS: Show 'quitting with active tunnel' only when appropriate
authorRoopesh Chander <roop@roopc.net>
Thu, 21 Feb 2019 14:11:01 +0000 (19:41 +0530)
committerRoopesh Chander <roop@roopc.net>
Fri, 22 Feb 2019 07:33:53 +0000 (13:03 +0530)
Not when logging off or when the machine's shutting down

Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/WireGuard/UI/macOS/AppDelegate.swift
WireGuard/WireGuard/UI/macOS/Application.swift
WireGuard/WireGuard/UI/macOS/StatusMenu.swift

index fde1a27622bfb62708ff321763508379eee9e1e1..cbe6153c68038bfe392538bffe93a3d8e71c516f 100644 (file)
@@ -12,7 +12,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
 
     var manageTunnelsRootVC: ManageTunnelsRootViewController?
     var manageTunnelsWindowObject: NSWindow?
-    var isTerminationAlertShown = false
 
     func applicationDidFinishLaunching(_ aNotification: Notification) {
         Logger.configureGlobal(withFilePath: FileManager.appLogFileURL?.path)
@@ -42,25 +41,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
         }
     }
 
-    func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
+    @objc func quit() {
         guard let currentTunnel = tunnelsTracker?.currentTunnel, currentTunnel.status == .active || currentTunnel.status == .activating else {
-            return .terminateNow
-        }
-        if isTerminationAlertShown {
-            return .terminateNow
+            NSApp.terminate(nil)
+            return
         }
         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
+            alert.beginSheetModal(for: window) { _ in
                 NSApp.terminate(nil)
             }
-            return .terminateCancel
         } else {
             alert.runModal()
-            return .terminateNow
+            NSApp.terminate(nil)
         }
     }
 }
index f1da81a0e6d9bf3a769dd820c7b62e317c2b8f99..6e33802fd3b4df0da37c6291e731fe070dd6d93a 100644 (file)
@@ -14,7 +14,7 @@ class Application: NSApplication {
         "Z": #selector(UndoActionRespondable.redo(_:)),
         "w": #selector(NSWindow.performClose(_:)),
         "m": #selector(NSWindow.performMiniaturize(_:)),
-        "q": #selector(NSApplication.terminate(_:))
+        "q": #selector(AppDelegate.quit)
     ]
 
     private var appDelegate: AppDelegate? //swiftlint:disable:this weak_delegate
index 70d536bfba0e0397aafd3c6b7ac090fe6d67f90a..ada33dc0587979d3c99b77d1a0c724f47b6668d3 100644 (file)
@@ -122,8 +122,8 @@ class StatusMenu: NSMenu {
         let aboutItem = NSMenuItem(title: tr("macMenuAbout"), action: #selector(aboutClicked), keyEquivalent: "")
         aboutItem.target = self
         addItem(aboutItem)
-        let quitItem = NSMenuItem(title: tr("macMenuQuit"), action: #selector(NSApplication.terminate), keyEquivalent: "")
-        quitItem.target = NSApp
+        let quitItem = NSMenuItem(title: tr("macMenuQuit"), action: #selector(AppDelegate.quit), keyEquivalent: "")
+        quitItem.target = NSApp.delegate
         addItem(quitItem)
     }