macos: handle reopen event and open a window if none are visible

Fixes #410
This commit is contained in:
Mitchell Hashimoto
2023-09-07 14:47:50 -07:00
parent 2c7d4321cd
commit 1d8ee005c6

View File

@ -47,6 +47,8 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyApp
windowManager = PrimaryWindowManager(ghostty: self.ghostty)
}
//MARK: - NSApplicationDelegate
func applicationDidFinishLaunching(_ notification: Notification) {
// System settings overrides
UserDefaults.standard.register(defaults: [
@ -100,6 +102,18 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyApp
return .terminateLater
}
/// This is called when the application is already open and someone double-clicks the icon
/// or clicks the dock icon.
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
// If we have visible windows then we allow macOS to do its default behavior
// of focusing one of them.
guard !flag else { return true }
// No visible windows, open a new one.
windowManager.newWindow()
return false
}
/// Sync all of our menu item keyboard shortcuts with the Ghostty configuration.
private func syncMenuShortcuts() {
guard ghostty.config != nil else { return }