RunicHostedApplication class

Namespace Runic.Application.Views.Desktop in Runic.Application.Views.Desktop 0.23.0

public sealed class RunicHostedApplication : IAsyncDisposable

Inherits or implements IAsyncDisposable.

A guest application that this application hosts (the Runic host protocol, runic-host/1): its process, its host channel and the native windows that show its Windows.

Remarks

IRunicHostedApplications.StartAsync returns it once the guest proved itself. From then on each Window the guest opens becomes a RunicHostedWindow (IRunicHostedApplications.WindowOpened), and each request the guest makes for it passes RunicHostedApplicationOptions.Policy.

When the guest exits or crashes, or its channel closes, the host closes its windows, ends its process tree if it still runs and completes RunicHostedApplication.Exited with its exit code; showing an error page or restarting it is the host application's choice. RunicHostedApplication.StopAsync asks it to shut down and ends it after RunicHostedApplicationOptions.StopTimeout; RunicHostedApplication.RequestStopAsync asks each window first; RunicHostedApplication.KillAsync ends it at once. Disposing stops it as RunicHostedApplication.StopAsync does.

Experimental; see docs/experimental.md.

Properties

Exited

public Task<int> Exited { get; }

Completes with the guest's exit code once it exited and its windows closed: 128 plus the signal for a guest that a signal ended on Linux and macOS, such as 137 after RunicHostedApplication.KillAsync, and -1 when the code cannot be known.

Features

public IReadOnlyList<string> Features { get; }

The protocol features in use on the channel: those both sides listed. The base protocol has none.

Guest

public RunicGuestInfo Guest { get; }

The guest application as its handshake named it.

ProcessId

public int ProcessId { get; }

The guest's process id.

Protocol

public int Protocol { get; }

The protocol version of the channel.

Windows

public IReadOnlyList<RunicHostedWindow> Windows { get; }

The guest's open windows, in the order they opened.

Methods

DisposeAsync

public ValueTask DisposeAsync()

Stops the guest as RunicHostedApplication.StopAsync does.

Returns

A task that completes when the guest exited.

KillAsync

public ValueTask<int> KillAsync()

Ends the guest and the processes it started at once, without asking it.

Returns

The guest's exit code (RunicHostedApplication.Exited).

RequestStopAsync

public ValueTask<bool> RequestStopAsync(CancellationToken cancellationToken = default)

Asks each open window's close first, as the user closing it would; when every Window allowed, stops the guest as RunicHostedApplication.StopAsync does.

Parameters

cancellationToken

Cancels the wait; the guest keeps running unless its stop already began.

Returns

Whether the guest stops: false when a Window that guards its close refused, and the guest keeps running. true also for a guest that already exited.

StopAsync

public ValueTask<int> StopAsync(CancellationToken cancellationToken = default)

Asks the guest to shut down (shutdown): its Windows close without asking their guards, and the process exits. A guest that has not exited after RunicHostedApplicationOptions.StopTimeout is ended with its process tree.

Parameters

cancellationToken

Cancels the wait: the guest's process tree is then ended at once.

Returns

The guest's exit code (RunicHostedApplication.Exited).