macOS: App menu > Quit shall show a prompt to quit or close window
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
1dccd39818
commit
4d6692548c
|
@ -308,7 +308,6 @@
|
||||||
"macMenuHideApp" = "Hide WireGuard";
|
"macMenuHideApp" = "Hide WireGuard";
|
||||||
"macMenuHideOtherApps" = "Hide Others";
|
"macMenuHideOtherApps" = "Hide Others";
|
||||||
"macMenuShowAllApps" = "Show All";
|
"macMenuShowAllApps" = "Show All";
|
||||||
"macMenuQuitManagingTunnels" = "Quit Tunnel Manager";
|
|
||||||
|
|
||||||
"macMenuFile" = "File";
|
"macMenuFile" = "File";
|
||||||
"macMenuCloseWindow" = "Close Window";
|
"macMenuCloseWindow" = "Close Window";
|
||||||
|
@ -406,6 +405,12 @@
|
||||||
|
|
||||||
// Mac alert
|
// 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";
|
"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.";
|
"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";
|
"macPrivacyNoticeMessage" = "Privacy notice: be sure you trust this configuration file";
|
||||||
|
|
|
@ -78,6 +78,33 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
return false
|
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() {
|
@objc func quit() {
|
||||||
if let manageWindow = manageTunnelsWindowObject, manageWindow.attachedSheet != nil {
|
if let manageWindow = manageTunnelsWindowObject, manageWindow.attachedSheet != nil {
|
||||||
NSApp.activate(ignoringOtherApps: true)
|
NSApp.activate(ignoringOtherApps: true)
|
||||||
|
|
|
@ -51,8 +51,8 @@ class MainMenu: NSMenu {
|
||||||
|
|
||||||
menu.addItem(NSMenuItem.separator())
|
menu.addItem(NSMenuItem.separator())
|
||||||
|
|
||||||
menu.addItem(withTitle: tr("macMenuQuitManagingTunnels"),
|
menu.addItem(withTitle: tr("macMenuQuit"),
|
||||||
action: #selector(NSWindow.performClose(_:)), keyEquivalent: "q")
|
action: #selector(AppDelegate.confirmAndQuit), keyEquivalent: "q")
|
||||||
|
|
||||||
return menu
|
return menu
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue