From 7a580e8941b95eff80dfe9d2f1deb05b3c2cab85 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Thu, 21 Feb 2019 19:41:01 +0530 Subject: macOS: Show 'quitting with active tunnel' only when appropriate Not when logging off or when the machine's shutting down Signed-off-by: Roopesh Chander --- WireGuard/WireGuard/UI/macOS/AppDelegate.swift | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'WireGuard/WireGuard/UI/macOS/AppDelegate.swift') diff --git a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift index fde1a27..cbe6153 100644 --- a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift +++ b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift @@ -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) } } } -- cgit v1.2.3-59-g8ed1b