fixed stored @State properties on App

This commit is contained in:
Casper Zandbergen 2024-06-01 13:40:14 +02:00
parent 7ac57d8a59
commit 8f9ff393fd
2 changed files with 8 additions and 5 deletions

View File

@ -24,7 +24,8 @@
public protocol App { public protocol App {
/// The app's application ID. /// The app's application ID.
var id: String { get } static var id: String { get }
/// The app's windows. /// The app's windows.
@SceneBuilder var scene: Scene { get } @SceneBuilder var scene: Scene { get }
// swiftlint:disable implicitly_unwrapped_optional // swiftlint:disable implicitly_unwrapped_optional
@ -39,8 +40,12 @@ public protocol App {
extension App { extension App {
@available(*, deprecated, message: "The 'id' property is removed. Please use the new static id instead.")
var id: String { Self.id }
/// The application's entry point. /// The application's entry point.
public static func main() { public static func main() {
GTUIApp.appID = Self.id
let app = setupApp() let app = setupApp()
app.run() app.run()
} }
@ -50,7 +55,7 @@ extension App {
/// To run the app, call the ``GTUIApp/run(automaticSetup:manualSetup:)`` function. /// To run the app, call the ``GTUIApp/run(automaticSetup:manualSetup:)`` function.
public static func setupApp() -> GTUIApp { public static func setupApp() -> GTUIApp {
var appInstance = self.init() var appInstance = self.init()
appInstance.app = GTUIApp(appInstance.id) { appInstance } appInstance.app = GTUIApp(Self.id) { appInstance }
GTUIApp.updateHandlers.append { force in GTUIApp.updateHandlers.append { force in
var removeIndices: [Int] = [] var removeIndices: [Int] = []
for (index, window) in appInstance.app.sceneStorage.enumerated() { for (index, window) in appInstance.app.sceneStorage.enumerated() {
@ -64,7 +69,6 @@ extension App {
appInstance.app.sceneStorage.remove(at: index) appInstance.app.sceneStorage.remove(at: index)
} }
} }
GTUIApp.appID = appInstance.id
return appInstance.app return appInstance.app
} }

View File

@ -13,8 +13,7 @@ public class GTUIApp {
/// The handlers which are called when a state changes. /// The handlers which are called when a state changes.
static var updateHandlers: [(Bool) -> Void] = [] static var updateHandlers: [(Bool) -> Void] = []
/// The app's id for the file name for storing the data. /// The app's id for the file name for storing the data.
static var appID = "temporary" static var appID: String!
/// The pointer to the application. /// The pointer to the application.
public var pointer: UnsafeMutablePointer<GtkApplication>? public var pointer: UnsafeMutablePointer<GtkApplication>?
/// Fields for additional information. /// Fields for additional information.