public interface IRunicWindowPresentation : INotifyPropertyChanged The Window whose DI scope resolved the service, as it appears on the desktop: a ViewModel brings it to the front, minimizes, hides or shows it, makes it full-screen, marks its document edited, switches it between light and dark, and reads whether it is active, minimized and visible. Take it in a constructor:
public sealed partial class InboxViewModel : ObservableObject
{
public InboxViewModel(IRunicWindowPresentation window)
{
_window = window;
// Poll less while the user works in another window.
window.ActivityChanged += (_, e) => _poll.Interval = e.Activity.IsActive ? Fast : Slow;
}
[RelayCommand]
private async Task HideToTrayAsync() => await _window.SetVisibleAsync(false);
}Remarks
RunicWindowServiceCollectionExtensions.AddRunicWindowService registers it per scope, next to IRunicWindowContext. It works on every host without naming one: Runic Desktop's embedded windows (WebView2, WKWebView, WebKitGTK with GTK 3 or GTK 4), a WPF window through WpfPlatformServices.ForWindowPresentation, and CS-WebUI as far as it can. IRunicWindowPresentation.Features says what the host can do; a request it cannot do returns Unavailable with PlatformUnavailableReason.BackendUnavailable instead of throwing. Before the Window opens, and in a scope that no Window opened, requests report PlatformUnavailableReason.OwnerUnavailable; once it has closed, PlatformUnavailableReason.OwnerClosed. Code outside the scope reads the same object from IRunicWindow.Presentation.
The state changes (IRunicWindowPresentation.ActivityChanged and INotifyPropertyChanged.PropertyChanged for IRunicWindowPresentation.Activity, IRunicWindowPresentation.IsActive, IRunicWindowPresentation.IsMinimized, IRunicWindowPresentation.IsVisible and IRunicWindowPresentation.ColorScheme) are raised in a turn of the Window's model context, as a command runs, so a handler sets ViewModel state directly. With CommunityToolkit, subscribe to the event; with ReactiveUI, use WhenAnyValue(x => x.IsActive) on the service, or RunicWindowPresentationExtensions.ObserveActivity. Where the host reports no activity (IRunicWindowPresentation.Features without RunicWindowPresentationFeatures.Activity), the Window counts as active and visible (RunicWindowActivity.Assumed), so work that pauses while it is inactive keeps running.
This is not a ViewModel activation hook (the dropped I-142): it reports the native window, not whether a View shows the ViewModel. In tests, use RunicTestWindowPresentation from Runic.Application.Testing, which records every request and lets the test set the activity.
Properties
Activity
RunicWindowActivity Activity { get; } Gets whether the Window is active, minimized and visible, as last reported.
ColorScheme
DesktopColorScheme ColorScheme { get; } Gets the light or dark appearance the Window shows now, as Runic set it: its own scheme, the application's, or the last one set for every Window that shares it (RunicWindowPresentationFeatures.PerWindowColorScheme); DesktopColorScheme.NoPreference when it follows the system.
Remarks
INotifyPropertyChanged.PropertyChanged reports a change, also one that another Window or the application made.
Features
RunicWindowPresentationFeatures Features { get; } Gets what the Window's host can do now; RunicWindowPresentationFeatures.None before it opens and after it closed.
IsActive
bool IsActive { get; } Gets whether the Window has the desktop's keyboard focus: RunicWindowActivity.IsActive of IRunicWindowPresentation.Activity.
IsMinimized
bool IsMinimized { get; } Gets whether the Window is minimized: RunicWindowActivity.IsMinimized of IRunicWindowPresentation.Activity.
IsVisible
bool IsVisible { get; } Gets whether the Window is shown: RunicWindowActivity.IsVisible of IRunicWindowPresentation.Activity.
Placement
RunicWindowPlacement? Placement { get; } Gets the Window's placement as last reported: the bounds it restores to and whether it is maximized or full-screen; null where the host reports none (IRunicWindowPresentation.Features without RunicWindowPresentationFeatures.Placement).
Remarks
Save it when the Window closes and pass it to IRunicWindowPresentation.SetPlacementAsync to put the Window back where it was. On Runic Desktop it is the window's DesktopWindowState.Placement, converted with ToRunicPlacement() of Runic.Application.Views.Desktop, so a placement saved by either reads in the other.
INotifyPropertyChanged.PropertyChanged reports a change in a turn of the Window's model context. While the user drags or resizes the Window the changes are combined, so a handler reads the latest placement. The value stays readable after the Window closed. The default implementation returns null.
SidePanel
IRunicSidePanel? SidePanel { get; } Gets the Window's open side panel, or null.
Remarks
Set when IRunicWindowPresentation.OpenSidePanelAsync returns the panel; null again in the turn of the Window's model context that raises the panel's IRunicSidePanel.Closed, and INotifyPropertyChanged.PropertyChanged reports both changes. The default implementation returns null.
Methods
MaximizeAsync
ValueTask<PlatformResult<PlatformUnit>> MaximizeAsync(CancellationToken cancellationToken = default) Maximizes the Window (zooms it on macOS); a Window that already is stays maximized.
Parameters
cancellationTokenCancels before the request reaches the window.
Returns
Success once the window was asked to maximize; IRunicWindowPresentation.Placement then reports it. PlatformUnavailableReason.BackendUnavailable where IRunicWindowPresentation.Features lacks RunicWindowPresentationFeatures.Maximize, PlatformFailureCode.PermissionDenied when a host application's policy refused it, and PlatformFailureCode.Conflict for a kiosk window, which stays full-screen.
Remarks
A full-screen Window leaves full screen first, a minimized one is restored maximized, and a hidden one stays hidden and shows maximized. An open side panel stays open. Windows activates a window that it maximizes, as it does when the user maximizes one; macOS animates the zoom, and a Linux window manager decides when the window is maximized.
The default implementation, for a presentation of 0.18 or earlier, reports PlatformUnavailableReason.BackendUnavailable.
MinimizeAsync
ValueTask<PlatformResult<PlatformUnit>> MinimizeAsync(CancellationToken cancellationToken = default) Minimizes the Window to the taskbar or Dock.
Parameters
cancellationTokenCancels before the request reaches the window.
Returns
Success once the window was asked to minimize.
OpenSidePanelAsync
ValueTask<RunicSidePanelResult> OpenSidePanelAsync(RunicSidePanelOptions options, CancellationToken cancellationToken = default) Opens a page of the Window beside its page, growing the Window by the panel's width on one edge, so its page keeps its size and its place on the screen.
Parameters
optionsThe edge, width and page of the panel.
cancellationTokenCancels waiting for the panel's page; a cancelled open leaves the Window unchanged.
Returns
Opened with the panel, also IRunicWindowPresentation.SidePanel from then on, or Refused with the reason, after which the Window is unchanged and the ViewModel shows the content another way, such as an overlay of its page.
Exceptions
ArgumentNullExceptionoptionsisnull.ArgumentOutOfRangeExceptionThe width is smaller than
RunicSidePanelOptions.MinimumWidth, the edge is not defined, or the load timeout is not positive.ArgumentExceptionThe path is empty, absolute, or leaves the Window's page.
OperationCanceledExceptioncancellationTokenwas cancelled.
Remarks
The panel's page is a second connection of the Window and binds to the same ViewModel tree, for example to a SidePanel property of the root ViewModel; its address and history are its own. Runic Desktop's own windows open one on Windows (WebView2), macOS (WKWebView) and Linux (WebKitGTK, on GTK 3 and GTK 4); every other presentation refuses with RunicSidePanelRefusal.Unsupported: an installed browser, a serve-only application, a custom window host, WPF, CS-WebUI and a hosted application's Window or region. RunicWindowPresentationFeatures.SidePanel in IRunicWindowPresentation.Features says the host has one; the Window's state can still refuse (maximized, full-screen, snapped, minimized, no room). Once the Window closed, the result is RunicSidePanelRefusal.Closed.
The default implementation, for a presentation of 0.18 or earlier, refuses with RunicSidePanelRefusal.Unsupported.
PresentAsync
ValueTask<PlatformResult<PlatformUnit>> PresentAsync(DesktopActivationContext? activation = null, CancellationToken cancellationToken = default) Brings the Window to the front and gives it the keyboard focus: shows it when it is hidden and restores it when it is minimized.
Parameters
activationThe activation token or startup ID that lets the desktop grant focus, such as
ApplicationLaunch.PlatformContextof a launch that a second instance forwarded, ornull. Use it once, promptly.cancellationTokenCancels before the request reaches the window.
Returns
Success when the desktop presented the Window. A desktop may refuse to take the focus from the application the user works in: Windows then flashes the taskbar button and reports PlatformFailureCode.PermissionDenied, and a Wayland compositor without an activation token only asks for attention.
RestoreAsync
ValueTask<PlatformResult<PlatformUnit>> RestoreAsync(CancellationToken cancellationToken = default) Returns the Window to its normal bounds: leaves full screen, un-maximizes and un-minimizes it; a normal Window stays as it is.
Parameters
cancellationTokenCancels before the request reaches the window.
Returns
Success once the window was asked to restore, with the results of IRunicWindowPresentation.MaximizeAsync otherwise.
Remarks
The Window ends at its normal bounds, the ones IRunicWindowPresentation.Placement reports, also when it was minimized while maximized, where the platform itself would bring it back maximized; IRunicWindowPresentation.PresentAsync keeps that behaviour. A hidden Window stays hidden and shows at its normal bounds. Windows restores a visible maximized window without activating it, but activates one that it brings back from minimized. On Wayland an application is not told that its window is minimized, so only IRunicWindowPresentation.PresentAsync brings it back there.
The default implementation reports PlatformUnavailableReason.BackendUnavailable.
SetColorSchemeAsync
ValueTask<PlatformResult<PlatformUnit>> SetColorSchemeAsync(DesktopColorScheme colorScheme, CancellationToken cancellationToken = default) Switches the Window between light and dark while it is open.
Parameters
colorSchemeDesktopColorScheme.LightorDesktopColorScheme.Dark, orDesktopColorScheme.NoPreferenceto follow the application's scheme, which by default follows the system.cancellationTokenCancels before the request reaches the window.
Returns
Success once the window and its page show the scheme.
Exceptions
ArgumentOutOfRangeExceptioncolorSchemeis not a defined value.
Remarks
The page's prefers-color-scheme follows. Where IRunicWindowPresentation.Features lacks RunicWindowPresentationFeatures.PerWindowColorScheme, the scheme is not this Window's alone: on Linux the GTK windows share one scheme for the whole process, and on Windows the windows that share a WebView2 profile share its scheme, so the call changes all of them and IRunicWindowPresentation.ColorScheme of each reports it.
On Runic Desktop, DesktopHost.SetColorSchemeAsync switches the whole application; on such a shared scheme it wins over the Windows' own, whatever order they were set in.
SetDocumentEditedAsync
ValueTask<PlatformResult<PlatformUnit>> SetDocumentEditedAsync(bool edited, CancellationToken cancellationToken = default) Marks whether the Window's document has unsaved changes, where the platform shows it: the dot in the macOS close button.
Parameters
editedtruewhile the document has unsaved changes.cancellationTokenCancels before the request reaches the window.
Returns
Success once the window shows it; PlatformUnavailableReason.BackendUnavailable on Windows, Linux and in WPF, which have no such convention. Show unsaved changes in the page or title there.
SetFullScreenAsync
ValueTask<PlatformResult<PlatformUnit>> SetFullScreenAsync(bool fullScreen, CancellationToken cancellationToken = default) Enters or leaves full screen.
Parameters
fullScreentrueto fill the Window's monitor;falseto return to its bounds.cancellationTokenCancels before the request reaches the window.
Returns
Success once the window was asked to change.
SetPlacementAsync
ValueTask<PlatformResult<PlatformUnit>> SetPlacementAsync(RunicWindowPlacement placement, CancellationToken cancellationToken = default) Gives the open Window a placement: the bounds it restores to and whether it is maximized or full-screen, as a placement saved from IRunicWindowPresentation.Placement gives it.
Parameters
placementThe placement, in the units of
IRunicWindowPresentation.Placement(seeRunicWindowPlacement).RunicWindowPlacement.XandRunicWindowPlacement.Ybothnullkeep the position; aRunicWindowPlacement.WidthorRunicWindowPlacement.Heightof zero or less keeps that dimension.cancellationTokenCancels before the request reaches the window.
Returns
Success once the window was asked to take the placement, with the results of IRunicWindowPresentation.MaximizeAsync otherwise. Where the platform cannot position a window (Wayland), a placement with a position reports PlatformUnavailableReason.BackendUnavailable and changes nothing: pass one without RunicWindowPlacement.X and RunicWindowPlacement.Y, as IRunicWindowPresentation.Placement reports there.
Exceptions
ArgumentNullExceptionplacementisnull.ArgumentExceptionOnly one of
RunicWindowPlacement.XandRunicWindowPlacement.Yis set.
Remarks
A maximized, minimized, full-screen or hidden Window takes the bounds as the ones it restores to, and the placement's state when it is next shown or restored. The bounds are kept on a monitor that exists now: bounds off every monitor's work area move onto the nearest one, and bounds larger than it shrink to fit, so IRunicWindowPresentation.Placement can report other bounds than the ones passed. A host application's policy can also change them. With a side panel open, the placement is that of the Window's page, without the panel.
Windows activates a window that the placement maximizes or brings back from minimized. The default implementation reports PlatformUnavailableReason.BackendUnavailable.
SetVisibleAsync
ValueTask<PlatformResult<PlatformUnit>> SetVisibleAsync(bool visible, CancellationToken cancellationToken = default) Hides the Window without closing it, for example to a status icon, or shows it again.
Parameters
visibletrueto show the Window;falseto hide it.cancellationTokenCancels before the request reaches the window.
Returns
Success once the window was shown or hidden.
Remarks
A hidden Window stays open: its page keeps running and its Bridge stays connected. Only the application can show it again, so keep a way back, such as a status icon whose command calls IRunicWindowPresentation.PresentAsync.
Events
ActivityChanged
event EventHandler<RunicWindowActivityChangedEventArgs>? ActivityChanged Occurs after IRunicWindowPresentation.Activity has changed, in a turn of the Window's model context.