mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: setup delegate for app state, config reload callback
This commit is contained in:
@ -3,7 +3,7 @@ import OSLog
|
||||
import GhosttyKit
|
||||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
|
||||
class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyAppStateDelegate {
|
||||
// The application logger. We should probably move this at some point to a dedicated
|
||||
// class/struct but for now it lives here! 🤷♂️
|
||||
static let logger = Logger(
|
||||
@ -43,6 +43,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
ghostty.delegate = self
|
||||
windowManager = PrimaryWindowManager(ghostty: self.ghostty)
|
||||
}
|
||||
|
||||
@ -149,6 +150,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
|
||||
ghostty.splitMoveFocus(surface: surface, direction: direction)
|
||||
}
|
||||
|
||||
//MARK: - GhosttyAppStateDelegate
|
||||
|
||||
func configDidReload(_ state: Ghostty.AppState) {
|
||||
syncMenuShortcuts()
|
||||
}
|
||||
|
||||
//MARK: - IB Actions
|
||||
|
||||
@IBAction func newWindow(_ sender: Any?) {
|
||||
windowManager.newWindow()
|
||||
}
|
||||
|
@ -1,6 +1,11 @@
|
||||
import SwiftUI
|
||||
import GhosttyKit
|
||||
|
||||
protocol GhosttyAppStateDelegate: AnyObject {
|
||||
/// Called when the configuration did finish reloading.
|
||||
func configDidReload(_ state: Ghostty.AppState)
|
||||
}
|
||||
|
||||
extension Ghostty {
|
||||
enum AppReadiness {
|
||||
case loading, error, ready
|
||||
@ -12,6 +17,9 @@ extension Ghostty {
|
||||
/// The readiness value of the state.
|
||||
@Published var readiness: AppReadiness = .loading
|
||||
|
||||
/// Optional delegate
|
||||
weak var delegate: GhosttyAppStateDelegate?
|
||||
|
||||
/// 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
|
||||
/// in Ghostty says so (usually, only in a reload configuration callback).
|
||||
@ -242,6 +250,11 @@ extension Ghostty {
|
||||
let state = Unmanaged<AppState>.fromOpaque(userdata!).takeUnretainedValue()
|
||||
state.config = newConfig
|
||||
|
||||
// If we have a delegate, notify.
|
||||
if let delegate = state.delegate {
|
||||
delegate.configDidReload(state)
|
||||
}
|
||||
|
||||
return newConfig
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user