Move to backend-specific app ID logic
This commit is contained in:
parent
df275ad987
commit
6c5769517f
@ -12,8 +12,6 @@ public enum StateManager {
|
||||
|
||||
/// Whether to block updates in general.
|
||||
public static var blockUpdates = false
|
||||
/// The application identifier.
|
||||
static var appID: String?
|
||||
/// The functions handling view updates.
|
||||
static var updateHandlers: [(Bool) -> Void] = []
|
||||
|
||||
|
||||
@ -26,14 +26,10 @@ public protocol App {
|
||||
/// The app storage type.
|
||||
associatedtype Storage: AppStorage
|
||||
|
||||
/// The app's application ID.
|
||||
var id: String { get }
|
||||
/// The app's scene.
|
||||
@SceneBuilder var scene: Scene { get }
|
||||
// swiftlint:disable implicitly_unwrapped_optional
|
||||
/// The app storage.
|
||||
var app: Storage! { get set }
|
||||
// swiftlint:enable implicitly_unwrapped_optional
|
||||
var app: Storage { get set }
|
||||
|
||||
/// An app has to have an `init()` initializer.
|
||||
init()
|
||||
@ -58,8 +54,7 @@ extension App {
|
||||
///
|
||||
/// To run the app, call the ``AppStorage/run(setup:)`` function.
|
||||
public static func setupApp() -> Self {
|
||||
var appInstance = self.init()
|
||||
appInstance.app = Storage(id: appInstance.id)
|
||||
let appInstance = self.init()
|
||||
appInstance.app.storage.app = { appInstance }
|
||||
StateManager.addUpdateHandler { force in
|
||||
let updateProperties = force || appInstance.getState().contains { $0.value.content.update }
|
||||
@ -77,7 +72,6 @@ extension App {
|
||||
appInstance.app.storage.sceneStorage.remove(at: index)
|
||||
}
|
||||
}
|
||||
StateManager.appID = appInstance.id
|
||||
let state = appInstance.getState()
|
||||
appInstance.app.storage.stateStorage = state
|
||||
return appInstance
|
||||
|
||||
@ -14,10 +14,6 @@ public protocol AppStorage: AnyObject {
|
||||
/// The scene storage.
|
||||
var storage: StandardAppStorage { get set }
|
||||
|
||||
/// Initialize the app storage.
|
||||
/// - Parameters id: The app's identifier.
|
||||
init(id: String)
|
||||
|
||||
/// Run the application.
|
||||
/// - Parameter setup: A closure that is expected to be executed right at the beginning.
|
||||
func run(setup: @escaping () -> Void)
|
||||
|
||||
@ -14,11 +14,10 @@ struct TestExecutable {
|
||||
|
||||
struct DemoApp: App {
|
||||
|
||||
let id = "io.github.AparokshaUI.DemoApp"
|
||||
// #if os(...)
|
||||
var app: Backend1.Backend1App!
|
||||
var app = Backend1.Backend1App()
|
||||
// #else
|
||||
// var app: Backend2.Backend2App!
|
||||
// var app = Backend2.Backend2App()
|
||||
// #endif
|
||||
|
||||
var scene: Scene {
|
||||
|
||||
@ -156,7 +156,7 @@ public enum Backend1 {
|
||||
|
||||
public var storage: StandardAppStorage = .init()
|
||||
|
||||
public required init(id: String) { }
|
||||
public init() { }
|
||||
|
||||
public func run(setup: @escaping () -> Void) {
|
||||
setup()
|
||||
|
||||
@ -71,7 +71,7 @@ public enum Backend2 {
|
||||
|
||||
public var storage: StandardAppStorage = .init()
|
||||
|
||||
public required init(id: String) { }
|
||||
public required init() { }
|
||||
|
||||
public func run(setup: @escaping () -> Void) {
|
||||
setup()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user