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