Merge pull request #1232 from mitchellh/service_window

macos: Address window spawning and ordering issues from service.
This commit is contained in:
Mitchell Hashimoto
2024-01-05 12:33:17 -08:00
committed by GitHub
2 changed files with 18 additions and 9 deletions

View File

@ -57,6 +57,9 @@ class AppDelegate: NSObject,
/// The dock menu /// The dock menu
private var dockMenu: NSMenu = NSMenu() 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. /// The ghostty global state. Only one per process.
let ghostty: Ghostty.AppState = Ghostty.AppState() let ghostty: Ghostty.AppState = Ghostty.AppState()
@ -104,13 +107,6 @@ class AppDelegate: NSObject,
// Initial config loading // Initial config loading
configDidReload(ghostty) 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 // Register our service provider. This must happen after everything
// else is initialized. // else is initialized.
NSApp.servicesProvider = ServiceProvider() NSApp.servicesProvider = ServiceProvider()
@ -132,6 +128,19 @@ class AppDelegate: NSObject,
center.delegate = self 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 { func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return ghostty.shouldQuitAfterLastWindowClosed return ghostty.shouldQuitAfterLastWindowClosed
} }

View File

@ -33,8 +33,8 @@ class TerminalManager {
} }
} }
// If we have no main window, just use the first window. // If we have no main window, just use the last window.
return windows.first return windows.last
} }
init(_ ghostty: Ghostty.AppState) { init(_ ghostty: Ghostty.AppState) {