From c1fe1f664624b172667cdc1795a385a070954c73 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 13 Sep 2023 15:06:41 -0700 Subject: [PATCH] macos: AppState config must be published and observed Fixes #440 We previously weren't observing changes so they weren't being automatically propagated. We were using an old pointer which at best returned the wrong value and at worst crashed. I was able to make it crash eventually, too. This changes the fields to be properly published and observed and as a result the config is immediately available to all users. --- macos/Sources/Features/Primary Window/PrimaryView.swift | 2 +- macos/Sources/Ghostty/AppState.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/macos/Sources/Features/Primary Window/PrimaryView.swift b/macos/Sources/Features/Primary Window/PrimaryView.swift index c3020ba3e..da110011b 100644 --- a/macos/Sources/Features/Primary Window/PrimaryView.swift +++ b/macos/Sources/Features/Primary Window/PrimaryView.swift @@ -2,7 +2,7 @@ import SwiftUI import GhosttyKit struct PrimaryView: View { - let ghostty: Ghostty.AppState + @ObservedObject var ghostty: Ghostty.AppState // We need access to our app delegate to know if we're quitting or not. // Make sure to use `@ObservedObject` so we can keep track of `appDelegate.confirmQuit`. diff --git a/macos/Sources/Ghostty/AppState.swift b/macos/Sources/Ghostty/AppState.swift index 99ddf04ac..b6dec9dec 100644 --- a/macos/Sources/Ghostty/AppState.swift +++ b/macos/Sources/Ghostty/AppState.swift @@ -23,7 +23,7 @@ extension Ghostty { /// 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). - var config: ghostty_config_t? = nil { + @Published var config: ghostty_config_t? = nil { didSet { // Free the old value whenever we change guard let old = oldValue else { return } @@ -33,7 +33,7 @@ extension Ghostty { /// The ghostty app instance. We only have one of these for the entire app, although I guess /// in theory you can have multiple... I don't know why you would... - var app: ghostty_app_t? = nil { + @Published var app: ghostty_app_t? = nil { didSet { guard let old = oldValue else { return } ghostty_app_free(old)