mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 07:46:12 +03:00
Merge pull request #1232 from mitchellh/service_window
macos: Address window spawning and ordering issues from service.
This commit is contained in:
@ -57,6 +57,9 @@ class AppDelegate: NSObject,
|
||||
/// The dock menu
|
||||
private var dockMenu: NSMenu = NSMenu()
|
||||
|
||||
/// This is only true before application has become active.
|
||||
private var applicationHasBecomeActive: Bool = false
|
||||
|
||||
/// The ghostty global state. Only one per process.
|
||||
let ghostty: Ghostty.AppState = Ghostty.AppState()
|
||||
|
||||
@ -104,13 +107,6 @@ class AppDelegate: NSObject,
|
||||
// Initial config loading
|
||||
configDidReload(ghostty)
|
||||
|
||||
// Let's launch our first window. We only do this if we have no other windows. It
|
||||
// is possible to have other windows if we're opening a URL since `application(_:openFile:)`
|
||||
// is called before this.
|
||||
if (terminalManager.windows.count == 0) {
|
||||
terminalManager.newWindow()
|
||||
}
|
||||
|
||||
// Register our service provider. This must happen after everything
|
||||
// else is initialized.
|
||||
NSApp.servicesProvider = ServiceProvider()
|
||||
@ -132,6 +128,19 @@ class AppDelegate: NSObject,
|
||||
center.delegate = self
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(_ notification: Notification) {
|
||||
guard !applicationHasBecomeActive else { return }
|
||||
applicationHasBecomeActive = true
|
||||
|
||||
// Let's launch our first window. We only do this if we have no other windows. It
|
||||
// is possible to have other windows in a few scenarios:
|
||||
// - if we're opening a URL since `application(_:openFile:)` is called before this.
|
||||
// - if we're restoring from persisted state
|
||||
if terminalManager.windows.count == 0 {
|
||||
terminalManager.newWindow()
|
||||
}
|
||||
}
|
||||
|
||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||
return ghostty.shouldQuitAfterLastWindowClosed
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ class TerminalManager {
|
||||
}
|
||||
}
|
||||
|
||||
// If we have no main window, just use the first window.
|
||||
return windows.first
|
||||
// If we have no main window, just use the last window.
|
||||
return windows.last
|
||||
}
|
||||
|
||||
init(_ ghostty: Ghostty.AppState) {
|
||||
|
Reference in New Issue
Block a user