mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
Shutdown tunnel on quit in macos (#2710)
Fixes #2565 With this PR, the 'Quit' menu item (in the macOS status item menu) disconnects the tunnel (if tunnel is active) before quitting. While the tunnel is connected, the menu item's title is changed to 'Disconnect and Quit'. Depends on #2687 (and this PR currently includes those commits), so opened as draft. **Edit:** Now made ready for review.
This commit is contained in:
@@ -154,9 +154,9 @@
|
||||
let menuItem = createMenuItem(
|
||||
menu,
|
||||
title: "Quit",
|
||||
action: #selector(NSApplication.terminate(_:)),
|
||||
action: #selector(quitButtonTapped),
|
||||
key: "q",
|
||||
target: nil
|
||||
target: self
|
||||
)
|
||||
if let appName = Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String {
|
||||
menuItem.title = "Quit \(appName)"
|
||||
@@ -237,6 +237,17 @@
|
||||
NSApp.orderFrontStandardAboutPanel(self)
|
||||
}
|
||||
|
||||
@objc private func quitButtonTapped() {
|
||||
Task {
|
||||
do {
|
||||
try await appStore?.tunnel.stop()
|
||||
} catch {
|
||||
logger.error("\(#function): Error stopping tunnel: \(error)")
|
||||
}
|
||||
NSApp.terminate(self)
|
||||
}
|
||||
}
|
||||
|
||||
private func openSettingsWindow() {
|
||||
if let settingsWindow = NSApp.windows.first(where: {
|
||||
$0.identifier?.rawValue.hasPrefix("firezone-settings") ?? false
|
||||
@@ -365,6 +376,14 @@
|
||||
resourcesUnavailableReasonMenuItem.title = "Disconnected"
|
||||
resourcesSeparatorMenuItem.isHidden = false
|
||||
}
|
||||
quitMenuItem.title = {
|
||||
switch self.tunnelStatus {
|
||||
case .connected, .connecting:
|
||||
return "Disconnect and Quit"
|
||||
default:
|
||||
return "Quit"
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
private func handleMenuVisibilityOrStatusChanged() {
|
||||
|
||||
Reference in New Issue
Block a user