aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-06-05 02:17:49 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2019-06-06 10:27:11 +0200
commit481cffa4ba8fe7bd15810a76bfeeabedffa8c531 (patch)
tree594c4d24fddec8822635acb1579d70eabc498f5f
parentmacOS: Save/restore the log window's size (diff)
downloadwireguard-apple-481cffa4ba8fe7bd15810a76bfeeabedffa8c531.tar.xz
wireguard-apple-481cffa4ba8fe7bd15810a76bfeeabedffa8c531.zip
macOS: App menu > Quit shall show a prompt to quit or close window
-rw-r--r--WireGuard/WireGuard/Base.lproj/Localizable.strings7
-rw-r--r--WireGuard/WireGuard/UI/macOS/AppDelegate.swift27
-rw-r--r--WireGuard/WireGuard/UI/macOS/MainMenu.swift4
3 files changed, 35 insertions, 3 deletions
diff --git a/WireGuard/WireGuard/Base.lproj/Localizable.strings b/WireGuard/WireGuard/Base.lproj/Localizable.strings
index fead2107..5d918bcd 100644
--- a/WireGuard/WireGuard/Base.lproj/Localizable.strings
+++ b/WireGuard/WireGuard/Base.lproj/Localizable.strings
@@ -308,7 +308,6 @@
"macMenuHideApp" = "Hide WireGuard";
"macMenuHideOtherApps" = "Hide Others";
"macMenuShowAllApps" = "Show All";
-"macMenuQuitManagingTunnels" = "Quit Tunnel Manager";
"macMenuFile" = "File";
"macMenuCloseWindow" = "Close Window";
@@ -406,6 +405,12 @@
// 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";
diff --git a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
index ba2b0bdf..da0c77ce 100644
--- a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
+++ b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
@@ -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)
diff --git a/WireGuard/WireGuard/UI/macOS/MainMenu.swift b/WireGuard/WireGuard/UI/macOS/MainMenu.swift
index 27b674d1..92fca4b3 100644
--- a/WireGuard/WireGuard/UI/macOS/MainMenu.swift
+++ b/WireGuard/WireGuard/UI/macOS/MainMenu.swift
@@ -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
}