Merge pull request #411 from mitchellh/macos-dock-click

macos: handle reopen event and open a window if none are visible
This commit is contained in:
Mitchell Hashimoto
2023-09-07 14:51:21 -07:00
committed by GitHub

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 }