diff options
author | Roopesh Chander <roop@roopc.net> | 2019-02-21 19:41:01 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2019-02-22 13:03:53 +0530 |
commit | 7a580e8941b95eff80dfe9d2f1deb05b3c2cab85 (patch) | |
tree | 88b7f5a62be3b07af622f7d0e4fe51e2300eaf75 | |
parent | macOS: Fix removal of DNSes from AllowedIPs when DNS has changed (diff) | |
download | wireguard-apple-7a580e8941b95eff80dfe9d2f1deb05b3c2cab85.tar.xz wireguard-apple-7a580e8941b95eff80dfe9d2f1deb05b3c2cab85.zip |
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 <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r-- | WireGuard/WireGuard/UI/macOS/AppDelegate.swift | 15 | ||||
-rw-r--r-- | WireGuard/WireGuard/UI/macOS/Application.swift | 2 | ||||
-rw-r--r-- | WireGuard/WireGuard/UI/macOS/StatusMenu.swift | 4 |
3 files changed, 8 insertions, 13 deletions
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) } } } diff --git a/WireGuard/WireGuard/UI/macOS/Application.swift b/WireGuard/WireGuard/UI/macOS/Application.swift index f1da81a..6e33802 100644 --- a/WireGuard/WireGuard/UI/macOS/Application.swift +++ b/WireGuard/WireGuard/UI/macOS/Application.swift @@ -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 diff --git a/WireGuard/WireGuard/UI/macOS/StatusMenu.swift b/WireGuard/WireGuard/UI/macOS/StatusMenu.swift index 70d536b..ada33dc 100644 --- a/WireGuard/WireGuard/UI/macOS/StatusMenu.swift +++ b/WireGuard/WireGuard/UI/macOS/StatusMenu.swift @@ -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) } |