]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
macOS: App menu > Quit shall show a prompt to quit or close window
authorRoopesh Chander <roop@roopc.net>
Tue, 4 Jun 2019 20:47:49 +0000 (02:17 +0530)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 6 Jun 2019 08:27:11 +0000 (10:27 +0200)
Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/WireGuard/Base.lproj/Localizable.strings
WireGuard/WireGuard/UI/macOS/AppDelegate.swift
WireGuard/WireGuard/UI/macOS/MainMenu.swift

index fead21078b02dbf520921b06a904292fd48d673e..5d918bcdb2ca3e1a8a4bf8006017604515b3f8d9 100644 (file)
 "macMenuHideApp" = "Hide WireGuard";
 "macMenuHideOtherApps" = "Hide Others";
 "macMenuShowAllApps" = "Show All";
-"macMenuQuitManagingTunnels" = "Quit Tunnel Manager";
 
 "macMenuFile" = "File";
 "macMenuCloseWindow" = "Close Window";
 
 // Mac alert
 
+"macConfirmAndQuitAlertMessage" = "Do you want to close the tunnels manager or quit WireGuard entirely?";
+"macConfirmAndQuitAlertInfo" = "If you close the tunnels manager, WireGuard will continue to be available from the menu bar icon.";
+"macConfirmAndQuitInfoWithActiveTunnel (%@)" = "If you close the tunnels manager, WireGuard will continue to be available from the menu bar icon.\n\nNote that if you quit WireGuard entirely the currently active tunnel ('%@') will still remain active until you deactivate it from this application or through the Network panel in System Preferences.";
+"macConfirmAndQuitAlertQuitWireGuard" = "Quit WireGuard";
+"macConfirmAndQuitAlertCloseWindow" = "Close Tunnels Manager";
+
 "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.";
 "macPrivacyNoticeMessage" = "Privacy notice: be sure you trust this configuration file";
index ba2b0bdfbac7f3cf52d207fe62eee22eb3033473..da0c77cea1ddc1eb2d2d8949a4bf5991f687e13c 100644 (file)
@@ -78,6 +78,33 @@ class AppDelegate: NSObject, NSApplicationDelegate {
         return false
     }
 
+    @objc func confirmAndQuit() {
+        let alert = NSAlert()
+        alert.messageText = tr("macConfirmAndQuitAlertMessage")
+        if let currentTunnel = tunnelsTracker?.currentTunnel, currentTunnel.status == .active || currentTunnel.status == .activating {
+            alert.informativeText = tr(format: "macConfirmAndQuitInfoWithActiveTunnel (%@)", currentTunnel.name)
+        } else {
+            alert.informativeText = tr("macConfirmAndQuitAlertInfo")
+        }
+        alert.addButton(withTitle: tr("macConfirmAndQuitAlertCloseWindow"))
+        alert.addButton(withTitle: tr("macConfirmAndQuitAlertQuitWireGuard"))
+
+        NSApp.activate(ignoringOtherApps: true)
+        if let manageWindow = manageTunnelsWindowObject {
+            manageWindow.orderFront(self)
+            alert.beginSheetModal(for: manageWindow) { response in
+                switch response {
+                case .alertFirstButtonReturn:
+                    manageWindow.close()
+                case .alertSecondButtonReturn:
+                    NSApp.terminate(nil)
+                default:
+                    break
+                }
+            }
+        }
+    }
+
     @objc func quit() {
         if let manageWindow = manageTunnelsWindowObject, manageWindow.attachedSheet != nil {
             NSApp.activate(ignoringOtherApps: true)
index 27b674d16dccfe9400dfe478dfb7492a0e60a577..92fca4b32a6c3192322463db8f60a95a87b586ac 100644 (file)
@@ -51,8 +51,8 @@ class MainMenu: NSMenu {
 
         menu.addItem(NSMenuItem.separator())
 
-        menu.addItem(withTitle: tr("macMenuQuitManagingTunnels"),
-            action: #selector(NSWindow.performClose(_:)), keyEquivalent: "q")
+        menu.addItem(withTitle: tr("macMenuQuit"),
+            action: #selector(AppDelegate.confirmAndQuit), keyEquivalent: "q")
 
         return menu
     }