gstack/ios-qa/templates/DebugBridgeManager.swift.te...

50 lines
1.8 KiB
Plaintext

// AUTO-GENERATED from gstack/ios-qa/templates/DebugBridgeManager.swift.template
//
// Bootstraps StateServer on app launch. Lives in DebugBridgeCore (no UIKit
// dependency). The DebugOverlay install is wired separately by the consuming
// app — it lives in DebugBridgeUI which depends on DebugBridgeCore (not the
// other way around). Everything is #if DEBUG-gated; this file does not exist
// in Release builds.
#if DEBUG
import Foundation
@MainActor
public final class DebugBridgeManager {
public static let shared = DebugBridgeManager()
public func start(appState: AppState) {
// 1. Register the canonical AppState struct + accessor wiring.
// AppStateAccessor.register(_:) is generated by gen-accessors-tool.
AppStateAccessor.register(appState)
// 2. Boot the StateServer.
StateServer.shared.start()
// 3. The consuming app installs DebugOverlayWindow separately. See
// the example in DebugBridgeWiring.swift.template:
//
// #if canImport(UIKit)
// DebugOverlayWindow.shared.install(recording: recording)
// #endif
}
}
// Placeholder. gen-accessors-tool emits the real `AppStateAccessor` enum next
// to the app's canonical state struct. Apps that haven't run codegen get a
// stub that registers no accessors (snapshot is empty, restore returns
// missing-key for every key).
@MainActor
public enum AppStateAccessor {
public static var register: (Any) -> Void = { _ in }
}
// Apps declare their canonical state struct; codegen reads it and emits
// AppStateAccessor.register. The app's struct must be `@Observable` and
// must hold all snapshot-eligible state in `@Snapshotable`-marked fields.
@MainActor
public protocol AppState: AnyObject {}
#endif // DEBUG