mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: move active state to delegate
This commit is contained in:
@ -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,7 +107,6 @@ class AppDelegate: NSObject,
|
|||||||
// Initial config loading
|
// Initial config loading
|
||||||
configDidReload(ghostty)
|
configDidReload(ghostty)
|
||||||
|
|
||||||
|
|
||||||
// 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()
|
||||||
@ -127,14 +129,15 @@ class AppDelegate: NSObject,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func applicationDidBecomeActive(_ notification: Notification) {
|
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
|
// 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 possible to have other windows in a few scenarios:
|
||||||
// is called before this.
|
// - if we're opening a URL since `application(_:openFile:)` is called before this.
|
||||||
if (ghostty.firstLaunch) {
|
// - if we're restoring from persisted state
|
||||||
if terminalManager.windows.count == 0 {
|
if terminalManager.windows.count == 0 {
|
||||||
terminalManager.newWindow()
|
terminalManager.newWindow()
|
||||||
}
|
|
||||||
ghostty.firstLaunch = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,6 @@ 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).
|
||||||
|
Reference in New Issue
Block a user