aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/macOS/AppDelegate.swift23
1 files changed, 20 insertions, 3 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
index 5546eef1..fde1a276 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
}
}
}