CsWebUiPlatformServiceCollectionExtensions class

Namespace Runic.Application.Views.CsWebUi in Runic.Application.Views.CsWebUi 0.23.0-preview.1

public static class CsWebUiPlatformServiceCollectionExtensions

Registers window platform services for CS-WebUI applications.

Methods

AddRunicPlatformServices

public static IServiceCollection AddRunicPlatformServices(this IServiceCollection services)

Registers every Runic platform service that Runic Desktop's AddRunicPlatformServices registers: IWindowPlatformServices, IFileDialogs, ITextClipboard, IDesktopClipboard, IDesktopFileLauncher and IDesktopMessageBoxes per window scope, and one IApplicationPlatformServices, IDesktopSettings, IDesktopNotifications, IDesktopStatusIcon, IDesktopGlobalShortcuts, IDesktopLoginStartup, IDesktopInhibition, IDesktopSecretStore, IDesktopTrash, IDesktopFileTransfers, IDesktopVolumes, IDesktopNetworkStatus, IDesktopPowerEvents, IDesktopRecentDocuments, IDesktopApplications and IDesktopThumbnails for the application. CS-WebUI windows have no native owner, so every window operation and the capability snapshot report PlatformUnavailableReason.OwnerUnavailable. This package selects no native provider, so every application service reports PlatformUnavailableReason.ProviderNotConfigured.

Remarks

ViewModels written against these services resolve and run on CS-WebUI and check the result or the capability snapshot; on Runic Desktop, whose AddRunicPlatformServices registers the same services, the same ViewModels get native dialogs, the clipboard, the desktop's appearance preferences, notifications, the status icon, global shortcuts, login startup, inhibition, secret storage, the trash, file transfers, the application database and thumbnails. The application services need no window, so a CS-WebUI application can use them by registering one from a platform provider, such as WindowsPlatformProvider.CreateSettings(), WindowsPlatformProvider.CreateGlobalShortcuts(), new PortalApplication().CreateInhibition(), new PortalApplication().CreateSecretStore() or MacOSPlatformProvider.CreateApplications(), or the managed file transfers from Runic.Platform.Runtime.LocalFileTransfers.Create(), before calling this method. Existing registrations of these service types are kept.

AddRunicPlatformServices

public static IServiceCollection AddRunicPlatformServices(this IServiceCollection services, IPickerBackend unownedFileDialogs)

Registers the same services as CsWebUiPlatformServiceCollectionExtensions.AddRunicPlatformServices, with file dialogs without an owner window: each window's IFileDialogs shows unownedFileDialogs for OwnerPolicy.PreferOwner.

Parameters

services

The application's services.

unownedFileDialogs

The platform's dialogs without a parent window: WindowsPlatformProvider.CreateUnownedFileDialogs() (Runic.Platform.Windows), MacOSPlatformProvider.CreateUnownedFileDialogs() (Runic.Platform.MacOS) or new PortalApplication("org.example.Notes").CreateUnparentedFileDialogs() (Runic.Platform.Linux.Portal).

Returns

services.

Exceptions

ArgumentNullException

services or unownedFileDialogs is null.

Remarks

CS-WebUI windows have no native owner, so the dialogs open on their own, in front of the application, as Runic Desktop's do for a window without native dispatch. A request with OwnerPolicy.RequireOwner, the default of the options, still reports PlatformUnavailableReason.OwnerUnavailable: ask for new OpenDirectoryOptions(OwnerPolicy.PreferOwner) where a dialog of its own is acceptable. The capability snapshot reports PlatformCapabilityIds.DialogsUnowned and the file capabilities available, and PlatformCapabilityIds.DialogsOwned unavailable (PlatformUnavailableReason.OwnerUnavailable), so a ViewModel that runs on both hosts can tell them apart. Every other window service reports PlatformUnavailableReason.OwnerUnavailable, as before.

Each window's dialogs show one at a time: a second request while one is shown reports PlatformFailureCode.ResourceBusy. Closing the window, which disposes its service scope, closes a shown dialog, releases the leases the window still holds and reports PlatformUnavailableReason.OwnerClosed from then on. On macOS the panels need the main thread, which RunicCsWebUiHost.Run serves while the application runs; a host created with its constructor leaves the main thread to the application.

A dialog opens only for a Window whose page no other computer can reach, because the user at this computer answers it. Each request checks the Window: RunicCsWebUiHost must have shown it itself (no RunicCsWebUiHostOptions.ShowWindow, which may only start the server for another device, and not under RUNIC_APPLICATION_SERVE_ONLY=1), and its server must listen on loopback only, which WebUiWindow.SetPublic(true) ends. Otherwise the dialogs report PlatformUnavailableReason.OwnerUnavailable, as every other window service does. An existing IWindowPlatformServices registration is kept, and ignores these dialogs.

Example

if (OperatingSystem.IsWindowsVersionAtLeast(8))
    services.AddRunicPlatformServices(WindowsPlatformProvider.CreateUnownedFileDialogs());
else if (OperatingSystem.IsMacOS())
    services.AddRunicPlatformServices(MacOSPlatformProvider.CreateUnownedFileDialogs());
else if (OperatingSystem.IsLinux())
    services.AddRunicPlatformServices(new PortalApplication().CreateUnparentedFileDialogs());
else
    services.AddRunicPlatformServices();