macos: Address window spawning and ordering issues from service.

This commit is contained in:
Vivek Roy
2024-01-06 00:35:24 +05:30
parent 5a56b6ccad
commit 3aad646be2
3 changed files with 17 additions and 8 deletions

View File

@ -104,12 +104,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.
@ -132,6 +126,18 @@ class AppDelegate: NSObject,
center.delegate = self center.delegate = self
} }
func applicationDidBecomeActive(_ notification: Notification) {
// 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 (ghostty.firstLaunch) {
if terminalManager.windows.count == 0 {
terminalManager.newWindow()
}
ghostty.firstLaunch = false
}
}
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) {

View File

@ -36,6 +36,9 @@ extension Ghostty {
/// Optional delegate /// Optional delegate
weak var delegate: GhosttyAppStateDelegate? weak var delegate: GhosttyAppStateDelegate?
/// True when application is first launched. Immidiately set to false after first window is shown.
var firstLaunch: Bool = true
/// The ghostty global configuration. This should only be changed when it is definitely /// The ghostty global configuration. This should only be changed when it is definitely
/// safe to change. It is definite safe to change only when the embedded app runtime /// safe to change. It is definite safe to change only when the embedded app runtime
/// in Ghostty says so (usually, only in a reload configuration callback). /// in Ghostty says so (usually, only in a reload configuration callback).