public static class DesktopPlatformServiceCollectionExtensions Registers Desktop platform services for dependency injection.
Methods
AddRunicPlatformServices
public static IServiceCollection AddRunicPlatformServices(this IServiceCollection services) Registers every Runic platform service: one DesktopWindowPlatformServices per window scope, exposed as IWindowPlatformServices, IFileDialogs, ITextClipboard, IDesktopClipboard and IDesktopFileLauncher, IDesktopMonitors and IDesktopMessageBoxes, and one IApplicationPlatformServices (DesktopPlatformServices.ForApplication), IDesktopSettings, IDesktopNotifications, IDesktopStatusIcon, IDesktopGlobalShortcuts, IDesktopLoginStartup, IDesktopInhibition, IDesktopSecretStore, IDesktopTrash, IDesktopFileTransfers, IDesktopVolumes, IDesktopNetworkStatus, IDesktopPowerEvents, IDesktopRecentDocuments, IDesktopApplications, IDesktopThumbnails and IDesktopFileBookmarks for the application, without an application ID.
Remarks
A ViewModel resolved in the scope that OpenWindowAsync on RunicDesktopHost creates can take any of these services in its constructor. The window services need the window's native owner: they bind to it when the window opens, using DesktopPlatformServices.CurrentProvider, and stop when the window closes. A window without a native owner, such as an installed browser after an embedded-window fallback or a window served under RUNIC_APPLICATION_SERVE_ONLY=1, and any scope other than a window's, get window services that report PlatformUnavailableReason.OwnerUnavailable. The installed browser's still show file dialogs that ask for OwnerPolicy.PreferOwner, without an owner. The application services need no window, so they work the same with or without a native owner: they are singletons created by DesktopPlatformServices.CreateSettings, DesktopPlatformServices.CreateNotifications, DesktopPlatformServices.CreateStatusIcon, DesktopPlatformServices.CreateGlobalShortcuts, DesktopPlatformServices.CreateLoginStartup, DesktopPlatformServices.CreateInhibition, DesktopPlatformServices.CreateSecretStore, DesktopPlatformServices.CreateTrash, DesktopPlatformServices.CreateFileTransfers, DesktopPlatformServices.CreateVolumes, DesktopPlatformServices.CreateNetworkStatus, DesktopPlatformServices.CreatePowerEvents, DesktopPlatformServices.CreateRecentDocuments, DesktopPlatformServices.CreateApplications and DesktopPlatformServices.CreateThumbnails when first resolved, and disposed with the service provider. Without an application ID, Linux notifications use the identity the desktop portal infers and Windows notifications report PlatformUnavailableReason.ProviderNotConfigured; pass the ID to DesktopPlatformServiceCollectionExtensions.AddRunicPlatformServices instead. Existing registrations of these service types are kept. Privileged actions need declared actions and their own provider package, so the application registers IDesktopPrivilegedActions itself.
AddRunicPlatformServices
public static IServiceCollection AddRunicPlatformServices(this IServiceCollection services, string applicationId) Registers the same services as DesktopPlatformServiceCollectionExtensions.AddRunicPlatformServices, with notifications, the status icon, global shortcuts, login startup and inhibition for the application identified by applicationId, and its IDesktopOpenRegistration (DesktopPlatformServices.CreateOpenRegistration).
Parameters
servicesThe application's services.
applicationIdThe application's identity, the same string on every operating system: on Windows its AppUserModelID, which the application's installer registers with the shell (a process installed from an MSIX package uses its package's AppUserModelID instead); on Linux the reverse-DNS ID of its installed desktop entry, such as
org.example.Appfororg.example.App.desktop. macOS uses the bundle identifier instead.
Exceptions
ArgumentExceptionapplicationIdis empty or not a valid ID on this operating system.
Remarks
The ID is checked here for the running operating system. On Linux the portal registers it when the first notification request connects, and reports portal-identity-registration-failed when no matching desktop entry is installed; during development, use the overload without an ID. Portal diagnostics are logged as event 2003 through the provider's ILoggerFactory.