Move notification handling outside of the current render loop

This commit is contained in:
Trevor Elkins
2024-12-26 17:44:06 -05:00
parent 4b4d4062df
commit 5867fe425f

View File

@ -361,17 +361,23 @@ extension Ghostty {
@objc private func onUpdateRendererHealth(notification: SwiftUI.Notification) { @objc private func onUpdateRendererHealth(notification: SwiftUI.Notification) {
guard let healthAny = notification.userInfo?["health"] else { return } guard let healthAny = notification.userInfo?["health"] else { return }
guard let health = healthAny as? ghostty_action_renderer_health_e else { return } guard let health = healthAny as? ghostty_action_renderer_health_e else { return }
healthy = health == GHOSTTY_RENDERER_HEALTH_OK DispatchQueue.main.async { [weak self] in
self?.healthy = health == GHOSTTY_RENDERER_HEALTH_OK
}
} }
@objc private func ghosttyDidContinueKeySequence(notification: SwiftUI.Notification) { @objc private func ghosttyDidContinueKeySequence(notification: SwiftUI.Notification) {
guard let keyAny = notification.userInfo?[Ghostty.Notification.KeySequenceKey] else { return } guard let keyAny = notification.userInfo?[Ghostty.Notification.KeySequenceKey] else { return }
guard let key = keyAny as? Ghostty.KeyEquivalent else { return } guard let key = keyAny as? Ghostty.KeyEquivalent else { return }
keySequence.append(key) DispatchQueue.main.async { [weak self] in
self?.keySequence.append(key)
}
} }
@objc private func ghosttyDidEndKeySequence(notification: SwiftUI.Notification) { @objc private func ghosttyDidEndKeySequence(notification: SwiftUI.Notification) {
keySequence = [] DispatchQueue.main.async { [weak self] in
self?.keySequence = []
}
} }
@objc private func ghosttyConfigDidChange(_ notification: SwiftUI.Notification) { @objc private func ghosttyConfigDidChange(_ notification: SwiftUI.Notification) {
@ -381,7 +387,9 @@ extension Ghostty {
] as? Ghostty.Config else { return } ] as? Ghostty.Config else { return }
// Update our derived config // Update our derived config
self.derivedConfig = DerivedConfig(config) DispatchQueue.main.async { [weak self] in
self?.derivedConfig = DerivedConfig(config)
}
} }
@objc private func ghosttyColorDidChange(_ notification: SwiftUI.Notification) { @objc private func ghosttyColorDidChange(_ notification: SwiftUI.Notification) {
@ -391,7 +399,9 @@ extension Ghostty {
switch (change.kind) { switch (change.kind) {
case .background: case .background:
self.backgroundColor = change.color DispatchQueue.main.async { [weak self] in
self?.backgroundColor = change.color
}
default: default:
// We don't do anything for the other colors yet. // We don't do anything for the other colors yet.