public interface IRunicHostedApplications Starts other Runic applications as guests and shows their Windows in native windows of this application, the host (the Runic host protocol, runic-host/1, in window mode).
Remarks
Get it from RunicDesktopHost.HostedApplications, or from the services after RunicHostedApplicationServiceCollectionExtensions.AddRunicHostedApplications:
var applications = host.HostedApplications;
applications.WindowOpened += (_, e) => Console.WriteLine($"{e.Window.Application.Guest.Name} opened {e.Window.Type}");
await using var tool = await applications.StartAsync(new RunicGuestStartInfo("/opt/tool/Tool", ["hosted"]));
int exitCode = await tool.Exited;Each IRunicHostedApplications.StartAsync starts a guest process of its own, which serves this host session only. The guest must support hosted mode through a parameter it defines (RunicGuestOptions), which the start information names. For each of its Windows the host opens a native window (RunicHostedWindow.DesktopWindow) that loads the guest's page from the guest's own loopback address, with a web view data store of the session's own that is not persisted, and without this application's credentials. RunicHostedApplicationOptions.Policy decides which windows open and what they may do; by default every window opens.
A serve-only application (RunicDesktopHostOptions.ServeOnly) is a browser host: its pages run in the user's browser, so it shows a guest's Windows only in regions of its pages (RunicHostedWindowDecision.Embed, RunicHostedWindowRequest.CanOpenWindow). Its guests get no dialogs, menus or window services, as in serve-only mode, serve their frames only cross-site to its pages, and an elevated guest refuses its regions.
When the Desktop host shuts down, or RunicDesktopHost.Run returns, every guest still running is stopped. The protocol and this API are experimental; see docs/experimental.md.
Properties
Applications
IReadOnlyList<RunicHostedApplication> Applications { get; } The guests that are running, in the order they started.
Methods
StartAsync
ValueTask<RunicHostedApplication> StartAsync(RunicGuestStartInfo startInfo, RunicHostedApplicationOptions? options = null, CancellationToken cancellationToken = default) Starts a guest application in hosted mode and completes the handshake with it.
Parameters
startInfoThe guest's executable and the arguments that select its hosted mode.
optionsTimeouts and the window policy;
nullfor the defaults.cancellationTokenCancels the start; the guest's process tree is then ended.
Returns
The running guest. Its Windows open in this application's windows from now on.
Exceptions
RunicHostedApplicationExceptionThe guest could not be hosted, and its process tree was ended.
RunicHostedApplicationException.Codeisguest-start-failed(the executable could not be started, or not in a job object on Windows; seeException.InnerException),host-not-elevated(RunicGuestStartInfo.AllowElevatedGuestis set and this process does not run elevated),guest-start-timeout,guest-exited,guest-not-hostable,guest-refused(withRunicHostedApplicationException.GuestCode) orprotocol-unsupported.ArgumentExceptionOn Windows, the executable is a batch file (
.bat,.cmd), which onlycmd.exeruns; orRunicGuestStartInfo.AllowElevatedGuestis set and the executable or the working directory is not a fully qualified path.InvalidOperationExceptionThe Desktop host is shutting down, or runs hosted itself. A shutdown or disposal of the Desktop host while the start is pending also fails it this way, and ends the guest's process tree.
Events
RegionAttached
event EventHandler<RunicHostedRegionEventArgs>? RegionAttached Raised when a region of one of the host's pages starts to show a guest's window (region/1, RunicHostedRegion.Attached), on a thread-pool thread, in order with the window events.
Remarks
Runic's implementation (RunicDesktopHost.HostedApplications) raises it. The interface's default implementation, which a test double of an earlier release keeps, never raises it.
RegionDetached
event EventHandler<RunicHostedRegionEventArgs>? RegionDetached Raised when a region no longer shows a guest's window, with the reason (RunicHostedRegion.Detached), on a thread-pool thread, in order with the window events.
Remarks
Runic's implementation (RunicDesktopHost.HostedApplications) raises it. The interface's default implementation, which a test double of an earlier release keeps, never raises it.
WindowClosed
event EventHandler<RunicHostedWindowEventArgs>? WindowClosed Raised when a window of any guest closed, for any reason, on a thread-pool thread.
WindowOpened
event EventHandler<RunicHostedWindowEventArgs>? WindowOpened Raised when a window of any guest opened, on a thread-pool thread. Add the handler before IRunicHostedApplications.StartAsync: a guest can open its first window before the start returns.
Remarks
IRunicHostedApplications.WindowOpened and IRunicHostedApplications.WindowClosed are raised one at a time, in order: a window's IRunicHostedApplications.WindowClosed follows its IRunicHostedApplications.WindowOpened, and a window that never opened for the host, such as one whose guest went away while it opened, raises neither.