diff options
author | Roopesh Chander <roop@roopc.net> | 2019-02-08 03:01:17 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2019-02-08 04:40:11 +0530 |
commit | a99a755c340bb24e1d48a60fcfc74148a57f0586 (patch) | |
tree | bf283649159846f606a931570ff6978ea06b1bec /WireGuard/WireGuard | |
parent | TunnelsManager: Don't lose .restarting state (diff) | |
download | wireguard-apple-a99a755c340bb24e1d48a60fcfc74148a57f0586.tar.xz wireguard-apple-a99a755c340bb24e1d48a60fcfc74148a57f0586.zip |
macOS: Show alert if exiting with an active tunnel
Instead of deactivating the tunnel.
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard')
-rw-r--r-- | WireGuard/WireGuard/Base.lproj/Localizable.strings | 5 | ||||
-rw-r--r-- | WireGuard/WireGuard/UI/macOS/AppDelegate.swift | 23 |
2 files changed, 25 insertions, 3 deletions
diff --git a/WireGuard/WireGuard/Base.lproj/Localizable.strings b/WireGuard/WireGuard/Base.lproj/Localizable.strings index 25d7739..b923360 100644 --- a/WireGuard/WireGuard/Base.lproj/Localizable.strings +++ b/WireGuard/WireGuard/Base.lproj/Localizable.strings @@ -323,3 +323,8 @@ "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."; diff --git a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift index 5546eef..fde1a27 100644 --- a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift +++ b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift @@ -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 } } } |