Application and services API
Declared by <huxerui/app.h>; window installation and WindowHandle are declared by <huxerui/window.h>. See Application and windows for a complete shared-model example.
Application declaration
Section titled “Application declaration”RootFactory is View (*)(). Application(root_factory, AppOptions = {}) retains the immutable declaration used by RunApplication. The declaration must outlive the application Runtime. A window’s root already owns a composition scope; do not annotate the app root.
| AppOptions field | Contract |
|---|---|
window |
WindowOptions for the initial window. |
system_tasks |
Application-owned declarations installed at startup. See System tasks. |
system_task_stop_timeout |
Positive, finite cooperative stop budget for system tasks. Defaults to five seconds and yields to any earlier platform deadline. |
viewport_breakpoints |
Width thresholds for responsive composition. |
show_debug_overlay |
Defaults on in debug builds and off in release builds; applies to each UI window. |
show_composition_error_details |
Shows the operation and exception message on the built-in window error page. Defaults on in debug builds and off when NDEBUG is defined. Diagnostics are logged in either mode. |
quit_on_last_window_closed |
Defaults true for framework-owned desktop windows. Hidden windows still count; an initially windowless application does not immediately quit. |
application_hooks |
ApplicationHook callbacks installed once, in declaration order, before windows or queued application work. |
window_hooks |
WindowHook callbacks installed before each UiWindow first composes. |
RunApplication enters the platform shell. Creating an Application value alone does not create a window or start an event loop.
ApplicationContext and ApplicationHook
Section titled “ApplicationContext and ApplicationHook”An ApplicationHook receives a borrowed ApplicationContext on the application thread. Do not retain it. Provide<Service>(shared_ptr<Service>) installs a non-null service under its exact C++ type. Duplicate types and installation after freeze throw logic_error.
RegisterPlatformModule<Module>(name, factory) and its options overload install lazy factories accepting Runtime& or UiWindow&. RegisterPlatformView<Properties[, Controller]> installs factories prepared for their actual mounting window. The catalog freezes after application installation; registration does not construct a module or platform view.
OnActivation(function<void(ApplicationActivation)>) installs the single application-level activation policy. OnLifecycleChanged(function<void(ApplicationLifecycleState)>) installs an application-lifetime observer. These handlers can work without a composed window. See Lifecycle and activation for startup handling and queued delivery.
WindowContext and WindowHook
Section titled “WindowContext and WindowHook”A WindowHook receives a borrowed WindowContext for one UiWindow. Provide<Service> installs a window-local service; Layers() borrows its LayerController. A service type cannot be installed both at application and window scope. Factory registration belongs to ApplicationContext.
Use a window service for presentation coordination or per-window editor policy. Use an application service for a shared document model, networking client, or a capability needed while no window is attached.
UseService and UseApplication
Section titled “UseService and UseApplication”UseService<Service>() returns the installed shared_ptr for the exact type or throws logic_error. It finds application services first, then services from the current window Environment. It does not construct missing services or search derived types.
Frozen application services can be acquired without composition, including from another thread without a window execution context. That does not make their methods or State thread-safe. Window services require their original live window context.
UseApplication() -> ApplicationHandle works in application hooks, ordinary application-thread callbacks, events, tasks and composition. A captured handle keeps access to its original application service, not a replacement Runtime after shutdown. Calling without a valid application context or from the wrong thread throws logic_error.
Activation and lifecycle
Section titled “Activation and lifecycle”ApplicationActivation is LaunchActivation, UrlActivation, FileActivation, or NotificationActivation. StartupActivation() returns const optional<ApplicationActivation>&: background-only startup may have no initial activation. Later input does not replace that value.
LifecycleState() observes aggregate Active, Inactive or Background state. OnLifecycleChanged(handler, dependencies...) observes distinct transitions while the declaring composition Lifecycle is mounted and does not replay the initial state. Use ApplicationContext observers when the policy must outlive every window. WindowHandle has a separate WindowLifecycleState and observer.
Create and control windows
Section titled “Create and control windows”SupportsMultipleWindows() queries synchronous desktop window creation. WindowSupport() reports optional desktop behavior including transparency, always-on-top, non-activating windows, and pointer pass-through. OpenWindow(ViewFactory, WindowOptions = {}) creates and presents a separately composed window sharing application services and State. Call it on the original application thread, outside composition and installation.
The factory executes later with a fresh root Environment. Options and local theme/locale do not inherit from the caller. Copy required values into the factory; captured references do not gain ownership. Discarding the WindowHandle leaves the window open. Success does not guarantee the first frame has rendered.
Invalid configuration throws invalid_argument, invalid thread/lifetime throws logic_error, and unsupported or failed native creation throws runtime_error. Quit() requests whole-application termination; WindowHandle::Close() requests only that window’s close path.
Permission requests
Section titled “Permission requests”CheckPermissionAsync(permission) and RequestPermissionAsync(permission) return Task<PermissionStatus>. The check reads current authorization without a prompt. A request may prompt or return the current status if the user needs to change Settings. See the permission states and platform capabilities.
#include <huxerui/huxerui.h>
using namespace huxerui;
[[huxerui::composable]]View LocationAccess() { auto application = UseApplication(); auto tasks = UseTaskScope(); auto status = UseState(PermissionStatus::NotDetermined); auto settings = UseState(std::string{}); const PermissionStatus authorization = status; return Column { Text(authorization == PermissionStatus::Granted ? "Location allowed" : "Location not enabled"), Button("Check access").OnClick([application, tasks, status] { tasks.Launch([application, status]() -> Task<void> { status = co_await application.CheckPermissionAsync(Permission::Location); }); }), Button("Request location").OnClick([application, tasks, status] { tasks.Launch([application, status]() -> Task<void> { status = co_await application.RequestPermissionAsync(Permission::Location); }); }), Button("Location settings").OnClick([application, tasks, settings, authorization] { const auto target = authorization == PermissionStatus::SystemDisabled ? PermissionSettingsTarget::System : PermissionSettingsTarget::Application; tasks.Launch([application, settings, target]() -> Task<void> { const bool opened = co_await application.OpenPermissionSettingsAsync(Permission::Location, target); settings = opened ? "Check access after returning" : "These settings are unavailable"; }); }), Text(settings), }.With(Spacing(8.0F));}Requests and settings capture the original platform presentation endpoint at the call. Some hosts can present without a UiWindow. If the original endpoint expires or the operation is unsupported, requests report Unavailable and settings return false. Supply required Android manifest declarations, Apple usage descriptions, and other platform configuration in the application package.
OpenPermissionSettingsAsync(permission, target = PermissionSettingsTarget::Application) returns Task<bool> for whether the platform accepted opening Settings. Recheck authorization when the application becomes active. Invalid permissions or settings targets throw std::invalid_argument before returning a task. The application example includes a fallback to the system settings target where the app-specific page is unavailable.
UIKit scene requests
Section titled “UIKit scene requests”On iOS and iPadOS, CanOpenWindow() queries whether the current application can request another scene. OpenWindowAsync(ViewFactory, WindowOptions = {}) returns Task<WindowHandle> and may be awaited after a user action, outside composition or installation. UIKit may reject an individual request even when the query succeeds. A task canceled before initialization suppresses a late window. These APIs require scene configuration.
Clipboard and directories
Section titled “Clipboard and directories”Clipboard() returns the same non-null shared_ptr<Clipboard> on each call. Start operations on the application thread and inspect their results. Retained objects report unavailable after shutdown. See Clipboard for supported representations, synchronous versus asynchronous operations, and a Web-compatible example.
Directories returns a borrowed AppDirectories captured at initialization; copy File values for independent ownership. Unavailable directories throw logic_error. CurrentDirectory queries the process working directory and throws runtime_error on failure. Captured directory values remain usable as paths after Runtime shutdown; paths do not grant filesystem access.
Notifications and tray
Section titled “Notifications and tray”LocalNotifications returns an application service handle without capturing a composition Environment. Text resolution follows the resource context of each submission. See System capabilities and Local notifications.
SystemTray returns the shared application tray handle without requiring composition. Show replaces the shared presentation; Hide removes it. OnActivate installs one committed application handler, normally in an ApplicationHook. There is no dependency-list overload. Keep callbacks application-owned and use an explicit Quit action for a tray-only workflow.
Platform implementation boundary
Section titled “Platform implementation boundary”Runtime owns application services, ordinary timers, dispatch and the frozen factory catalog. UiWindow owns composition, retained nodes, layout, input, semantics, animation, layers and RenderScene generation. Each platform derives these bases to implement genuine native operations. These are host implementation contracts, not objects an ordinary component constructs or subclasses.
Built-in hosts use BuildFrameOrErrorPage() for composition failure isolation. Direct UiWindow::BuildFrame() calls propagate exceptions. See composition failures.
ProcessMetrics contains cumulative CPU time, memory footprint and processor count. Shared application and UI work uses one application thread. See extension points before choosing a lower-level integration boundary.

