Skip to content

Lifecycle owns an effect for one composed scope. Application hooks own activation and application-lifetime policy even when every window is closed. Translate external input into application-owned documents or typed routes before presenting UI.

Lifecycle([document_id] {
auto subscription = ObserveDocument(document_id);
return [subscription = std::move(subscription)]() mutable {
subscription.Close();
};
}, document_id);

Setup runs after commit. A dependency change runs the previous cleanup before replacement setup; unmount runs the final cleanup. The move transfers the subscription into its cleanup owner. Return void when no cleanup is needed. Use Lifecycle for subscriptions and external resources, not for copying one controlled UI value into another.

StartupActivation is an immutable optional: a background-only launch may have no startup value. Install later activation handling in ApplicationContext. It does not belong to a page that can unmount.

#include <huxerui/huxerui.h>
#include <memory>
using namespace huxerui;
struct ActivationModel {
State<std::string> latest{std::string{"No startup payload"}};
};
std::string DescribeActivation(const ApplicationActivation& activation) {
if (const auto* url = std::get_if<UrlActivation>(&activation)) {
return "URL: " + url->url.ToString();
}
if (const auto* files = std::get_if<FileActivation>(&activation)) {
return files->files.empty() ? "No files" : "File: " + files->files.front().Name();
}
if (const auto* notification = std::get_if<NotificationActivation>(&activation)) {
return "Notification: " + notification->identifier;
}
return "Ordinary launch";
}
void InstallActivation(ApplicationContext& context) {
auto model = std::make_shared<ActivationModel>();
context.Provide(model);
const auto& startup = UseApplication().StartupActivation();
if (startup) {
model->latest = DescribeActivation(*startup);
}
context.OnActivation([model](ApplicationActivation activation) {
model->latest = DescribeActivation(activation);
});
}
View App() {
auto model = UseService<ActivationModel>();
return Column {
Text("Latest activation", TextRole::Title),
Text(model->latest),
}.With(Padding(24.0F), Spacing(12.0F));
}
const Application application{App, {.application_hooks = {InstallActivation}}};

LaunchActivation, UrlActivation, FileActivation and NotificationActivation are alternatives of ApplicationActivation. URL/file startup is available through StartupActivation; later requests enter the installed handler. Notification interactions enter the handler even when launching the process. Do not process the same startup payload again whenever a window composes.

There is one application activation handler. Put fan-out, deduplication and destination-window selection in application policy. Inspect variant alternatives explicitly; a URI, display name or submitted notification payload is not proof that the requested action is authorized.

Keep URL decoding independent of rendering:

void ApplyActivation(AppModel& model, const ApplicationActivation& activation) {
if (const auto* url = std::get_if<UrlActivation>(&activation)) {
if (auto path = model.codec.Decode(url->url)) {
model.path = *path;
}
}
}

AppModel owns the controlled NavigationPath and any required FileReference values. A window observes that model and supplies its route resolver to NavigationStack. Keep capability-bearing file references in document state rather than converting them to a filename route. See Navigation and routing.

If the product wants a new document window, OpenWindow can run from a later application callback on supported desktop hosts. It cannot run during application installation. Queue startup window policy through UseApplicationTaskScope().Post when it must run after installation.

This example keeps the newest requested document authoritative by canceling the previous task’s continuation. Reads belong to the application, so closing a preview window does not abandon the document operation.

#include <huxerui/huxerui.h>
#include <memory>
using namespace huxerui;
struct DocumentModel {
State<std::string> content{std::string{"Open a UTF-8 text file"}};
TaskHandle pending;
};
Task<void> ReadActivatedText(FileReference file, State<std::string> content) {
content = "Opening " + file.Name();
auto result = co_await file.ReadStringAsync();
content = result.Succeeded() ? result.Value() : "Could not open file: " + result.Error().message;
}
void InstallDocuments(ApplicationContext& context) {
auto model = std::make_shared<DocumentModel>();
auto tasks = UseApplicationTaskScope();
context.Provide(model);
auto open = [model, tasks](const ApplicationActivation& activation) {
const auto* files = std::get_if<FileActivation>(&activation);
if (!files || files->files.empty()) {
return;
}
model->pending.Cancel();
model->pending = tasks.Launch(ReadActivatedText(files->files.front(), model->content));
};
const auto& startup = UseApplication().StartupActivation();
if (startup) {
open(*startup);
}
context.OnActivation(open);
}
View App() {
auto model = UseService<DocumentModel>();
return ScrollView(SelectionArea(Text(model->content))).With(Padding(16.0F));
}
const Application application{App, {.application_hooks = {InstallDocuments}}};

The coroutine owns a FileReference copy, preserving its provider authority. It chooses the first file and reads all content; a production editor should decide how to handle multiple files and enforce size/type limits. ReadStringAsync validates UTF-8. Use incremental Streams for large input.

Application task cancellation suppresses continuation, not a transaction on external side effects. If the operation should stop with one preview panel instead, launch from that component’s UseTaskScope.

ApplicationHandle::LifecycleState observes aggregate Active, Inactive or Background. WindowHandle::LifecycleState reports only its original window. A background inspector does not imply the whole application is backgrounded.

auto window = UseWindow();
const bool active = window.LifecycleState() == WindowLifecycleState::Active;
window.OnLifecycleChanged([](WindowLifecycleState state) {
SetPreviewPaused(state != WindowLifecycleState::Active);
});

Use OnLifecycleChanged on an application/window handle for a composition-bound observer. Use ApplicationContext::OnLifecycleChanged for application-lifetime policy. Observers receive distinct queued transitions without initial replay: read LifecycleState for the current value. A background event grants no OS execution entitlement.

Activation and lifecycle are independent: bringing a window forward need not produce activation input, and a new activation can arrive while the application is already active.

Platform Application-owned configuration
Windows URL protocol or file association, plus notification identity when used. RegisterUrlScheme and RegisterLocalNotifications are explicit entry-time APIs.
Android Intent filters, MIME types, exported activity rules and URI grants in the app shell.
iOS / macOS URL/document declarations and the platform’s file access rules.
Web BrowserNavigationStack handles location/history routing; the Web shell owns activation and visibility delivery.

Application handlers do not register file associations or URL schemes. See platform guides and Local notifications before testing external delivery.

Capture ApplicationHandle and a task owner, then request the specific permission from the feature’s user action. Supply the corresponding platform declarations. Requests and settings retain their original presentation endpoint and report unavailable if it expires.

Check authorization again after settings. See the permission example and application/window lifetime.