48 lines
2 KiB
Swift
48 lines
2 KiB
Swift
/// The top-level entry point for a Portico application.
|
|
///
|
|
/// Conforming types declare a ``Scene`` body and an optional application
|
|
/// ID. The `@main` attribute on the concrete type triggers `static func main()`,
|
|
/// which delegates to ``PorticoRuntime/run(_:)``.
|
|
///
|
|
/// Stored ``DynamicProperty`` declarations - `@Environment`, or a third-party
|
|
/// wrapper such as a preference wrapper - are resolved against an empty root
|
|
/// environment before `applicationId`, `body`, or `shutdown()` is read. A
|
|
/// key-path slot therefore resolves to the same process-wide default box an
|
|
/// uninjected view-level `@Environment` reads, so writing it from anywhere in
|
|
/// the tree re-evaluates the ``SceneBuilder`` conditional that consumed it and
|
|
/// swaps the window.
|
|
@MainActor public protocol App {
|
|
/// The type of scene representing the body of this app.
|
|
associatedtype Body: Scene
|
|
|
|
/// The top-level scene of the application, composed using ``SceneBuilder``.
|
|
/// `body` is evaluated inside a ``DependencyTracker``, so a tracking read of
|
|
/// a resolved property makes the selected window reactive.
|
|
@SceneBuilder var body: Body { get }
|
|
|
|
/// A reverse-DNS application identifier for GTK uniqueness.
|
|
///
|
|
/// Returns `nil` by default; override to enable single-instance behavior.
|
|
var applicationId: String? { get }
|
|
|
|
/// Initializes the application - required by the `App` protocol.
|
|
init()
|
|
|
|
/// Asynchronous teardown performed after the last window requests close and before exit.
|
|
///
|
|
/// Runs after every handler registered with ``ApplicationLifecycle/onShutdown(_:)``.
|
|
/// The default implementation does nothing.
|
|
func shutdown() async
|
|
|
|
}
|
|
|
|
public extension App {
|
|
/// Default - no application ID, no single-instance enforcement.
|
|
var applicationId: String? { nil }
|
|
|
|
/// Default - no teardown.
|
|
func shutdown() async {}
|
|
|
|
/// Boots the application via ``PorticoRuntime/run(_:)``.
|
|
static func main() { PorticoRuntime.run(Self()) }
|
|
}
|