macOS: Show 'quitting with active tunnel' only when appropriate
Not when logging off or when the machine's shutting down Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
39fb52a2e3
commit
7a580e8941
|
@ -12,7 +12,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
|
|
||||||
var manageTunnelsRootVC: ManageTunnelsRootViewController?
|
var manageTunnelsRootVC: ManageTunnelsRootViewController?
|
||||||
var manageTunnelsWindowObject: NSWindow?
|
var manageTunnelsWindowObject: NSWindow?
|
||||||
var isTerminationAlertShown = false
|
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||||
Logger.configureGlobal(withFilePath: FileManager.appLogFileURL?.path)
|
Logger.configureGlobal(withFilePath: FileManager.appLogFileURL?.path)
|
||||||
|
@ -42,25 +41,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
|
@objc func quit() {
|
||||||
guard let currentTunnel = tunnelsTracker?.currentTunnel, currentTunnel.status == .active || currentTunnel.status == .activating else {
|
guard let currentTunnel = tunnelsTracker?.currentTunnel, currentTunnel.status == .active || currentTunnel.status == .activating else {
|
||||||
return .terminateNow
|
NSApp.terminate(nil)
|
||||||
}
|
return
|
||||||
if isTerminationAlertShown {
|
|
||||||
return .terminateNow
|
|
||||||
}
|
}
|
||||||
let alert = NSAlert()
|
let alert = NSAlert()
|
||||||
alert.messageText = tr("macAppExitingWithActiveTunnelMessage")
|
alert.messageText = tr("macAppExitingWithActiveTunnelMessage")
|
||||||
alert.informativeText = tr("macAppExitingWithActiveTunnelInfo")
|
alert.informativeText = tr("macAppExitingWithActiveTunnelInfo")
|
||||||
if let window = manageTunnelsWindowObject {
|
if let window = manageTunnelsWindowObject {
|
||||||
alert.beginSheetModal(for: window) { [weak self] _ in
|
alert.beginSheetModal(for: window) { _ in
|
||||||
self?.isTerminationAlertShown = true
|
|
||||||
NSApp.terminate(nil)
|
NSApp.terminate(nil)
|
||||||
}
|
}
|
||||||
return .terminateCancel
|
|
||||||
} else {
|
} else {
|
||||||
alert.runModal()
|
alert.runModal()
|
||||||
return .terminateNow
|
NSApp.terminate(nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Application: NSApplication {
|
||||||
"Z": #selector(UndoActionRespondable.redo(_:)),
|
"Z": #selector(UndoActionRespondable.redo(_:)),
|
||||||
"w": #selector(NSWindow.performClose(_:)),
|
"w": #selector(NSWindow.performClose(_:)),
|
||||||
"m": #selector(NSWindow.performMiniaturize(_:)),
|
"m": #selector(NSWindow.performMiniaturize(_:)),
|
||||||
"q": #selector(NSApplication.terminate(_:))
|
"q": #selector(AppDelegate.quit)
|
||||||
]
|
]
|
||||||
|
|
||||||
private var appDelegate: AppDelegate? //swiftlint:disable:this weak_delegate
|
private var appDelegate: AppDelegate? //swiftlint:disable:this weak_delegate
|
||||||
|
|
|
@ -122,8 +122,8 @@ class StatusMenu: NSMenu {
|
||||||
let aboutItem = NSMenuItem(title: tr("macMenuAbout"), action: #selector(aboutClicked), keyEquivalent: "")
|
let aboutItem = NSMenuItem(title: tr("macMenuAbout"), action: #selector(aboutClicked), keyEquivalent: "")
|
||||||
aboutItem.target = self
|
aboutItem.target = self
|
||||||
addItem(aboutItem)
|
addItem(aboutItem)
|
||||||
let quitItem = NSMenuItem(title: tr("macMenuQuit"), action: #selector(NSApplication.terminate), keyEquivalent: "")
|
let quitItem = NSMenuItem(title: tr("macMenuQuit"), action: #selector(AppDelegate.quit), keyEquivalent: "")
|
||||||
quitItem.target = NSApp
|
quitItem.target = NSApp.delegate
|
||||||
addItem(quitItem)
|
addItem(quitItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue