Refactor to hide only BaseTerminalController windows

This also slightly changes the code, as the duplication of the for loop
was making it harder to read now. I think technically slightly less
efficient, but this is hardly a hot code path, so should be fine imo.
This commit is contained in:
Roland Peelen
2024-10-01 09:52:14 +02:00
committed by Mitchell Hashimoto
parent 2dbd46096f
commit af48c1af0c

View File

@ -570,26 +570,20 @@ class AppDelegate: NSObject,
self.menuQuickTerminal?.state = if (quickController.visible) { .on } else { .off } self.menuQuickTerminal?.state = if (quickController.visible) { .on } else { .off }
} }
/// Toggles the visibility of all Ghostty windows /// Toggles visibility of all Ghosty Terminal windows. When hidden, activates Ghostty as the frontmost application
@IBAction func toggleVisibility(_ sender: Any) { @IBAction func toggleVisibility(_ sender: Any) {
let configurationErrorsWindow = ConfigurationErrorsController.sharedInstance.window for controller in NSApp.windows.compactMap({ $0.windowController as? BaseTerminalController }) {
if isVisible {
controller.window?.orderOut(nil)
} else {
controller.window?.makeKeyAndOrderFront(nil)
}
}
if isVisible { if !isVisible {
// Hide all windows
for window in NSApp.windows {
if window !== configurationErrorsWindow {
window.orderOut(nil)
}
}
} else {
// Show all windows
for window in NSApp.windows {
if window !== configurationErrorsWindow {
window.makeKeyAndOrderFront(nil)
}
}
NSApp.activate(ignoringOtherApps: true) NSApp.activate(ignoringOtherApps: true)
} }
isVisible.toggle() isVisible.toggle()
} }
} }