diff --git a/macos/Sources/AppDelegate.swift b/macos/Sources/AppDelegate.swift index 4f7a16c4e..8d307209c 100644 --- a/macos/Sources/AppDelegate.swift +++ b/macos/Sources/AppDelegate.swift @@ -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() } diff --git a/macos/Sources/Ghostty/AppState.swift b/macos/Sources/Ghostty/AppState.swift index ff8bdf0e9..6367e6ad4 100644 --- a/macos/Sources/Ghostty/AppState.swift +++ b/macos/Sources/Ghostty/AppState.swift @@ -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.fromOpaque(userdata!).takeUnretainedValue() state.config = newConfig + // If we have a delegate, notify. + if let delegate = state.delegate { + delegate.configDidReload(state) + } + return newConfig }