WindowsPlatformProvider class

Namespace Runic.Platform.Windows in Runic.Platform.Windows 0.23.0

public static class WindowsPlatformProvider

The Windows provider of the application-scoped Runic.Platform services.

Remarks

Every factory throws PlatformNotSupportedException on another operating system or before Windows 8. The application ID that notifications and login startup require is the AppUserModelID and the Run value name: Windows has no other identity for a process outside an MSIX package. Window services (file dialogs, the clipboard and file handoff) belong to a window: Runic's hosts create them for each window, such as DesktopPlatformServices.ForWindow of Runic.Application.Views.Desktop.

Methods

CreateApplications

public static IDesktopApplications CreateApplications()

Creates the desktop's application database from the shell's file and protocol associations.

Remarks

A content type is its MIME type when the registry's MIME database maps that type back to the same extension, else the extension, such as .txt; x-scheme-handler/<scheme> names a URL protocol and inode/directory folders. An application is the path of its executable or, for a packaged application, its AppUserModelID.

Windows lets only the user choose default applications: IDesktopApplications.SetDefaultApplicationAsync reports PlatformFailureCode.PermissionDenied with a diagnostic that points to Settings (ms-settings:defaultapps). It needs no window.

CreateGlobalShortcuts

public static IDesktopGlobalShortcuts CreateGlobalShortcuts()

Creates the application's global shortcuts, registered with RegisterHotKey.

Remarks

It needs no window: the keys belong to a message-only window on a thread of its own, created by the first IDesktopGlobalShortcuts.BindAsync. The application chooses the keys, so IDesktopGlobalShortcuts.ConfigureAsync reports PlatformUnavailableReason.BackendUnavailable. A key another application registered reports DesktopGlobalShortcutStatus.Conflict; F12, which Windows keeps for debuggers, the editing and window shortcuts such as Ctrl+C and Alt+F4, and a character the keyboard layout types only with AltGr report DesktopGlobalShortcutStatus.Refused.

CreateInhibition

public static IDesktopInhibition CreateInhibition()

Creates operation-scoped idle power inhibition.

CreateLoginStartup

public static IDesktopLoginStartup CreateLoginStartup(string applicationId)

Creates login startup through the user's Run key, under applicationId, or the package's startup task.

Remarks

An entry the user turned off in Task Manager stays off: enabling reports PermissionDenied until the application disables it.

A process installed from an MSIX package uses the desktop:StartupTask with TaskId="LoginStartup" that its manifest declares, through Windows.ApplicationModel.StartupTask: Windows redirects its writes to the Run key into the package, where they have no effect. Windows starts the application with the manifest's arguments, not the request's. A task the user or a policy turned off reports PlatformFailureCode.PermissionDenied and stays off, and a package without the task reports PlatformUnavailableReason.BackendUnavailable.

CreateNetworkStatus

public static IDesktopNetworkStatus CreateNetworkStatus()

Creates the computer's network status from the Network List Manager's connectivity hint.

Remarks

Windows reports the connectivity of its own internet check and the cost of the preferred connection (GetNetworkConnectivityHint, watched with NotifyNetworkConnectivityHintChange). A captive portal, and a network whose check failed in another way, is constrained internet access, which Runic reports as DesktopNetworkConnectivity.CaptivePortal. A fixed or variable cost, a connection over its data limit and roaming are metered.

The API needs Windows 10 version 2004 (build 19041); an older Windows reports PlatformUnavailableReason.BackendUnavailable. It needs no window.

CreateNotifications

public static IDesktopNotifications CreateNotifications(string applicationId)

Creates native toasts for an installed AppUserModelID. The application owns shell registration.

Remarks

A process installed from an MSIX package uses its package's AppUserModelID (PackageFamilyName!App), which Windows registers with the package, and ignores applicationId.

CreateOpenRegistration

public static IDesktopOpenRegistration CreateOpenRegistration(string applicationId)

Creates the per-user registration of URL schemes and file types under HKEY_CURRENT_USER\Software\Classes.

Parameters

applicationId

The application's ID: the prefix of its file types' ProgIDs (<applicationId>.notes) and the name of its Capabilities, which RegisteredApplications lists so that Settings, Default apps, shows the application.

Exceptions

ArgumentException

applicationId is empty, longer than 128 characters, or contains a backslash or NUL.

Remarks

A scheme gets a URL protocol key and a file type a ProgID, each with the command "<executable>" "%1", and the extension's OpenWithProgids lists the ProgID; the extension's default is never set, so the user keeps choosing defaults. A key in the current user's or the machine's classes that names another command belongs to another application: IDesktopOpenRegistration.RegisterAsync reports PlatformFailureCode.Conflict before writing anything. Registering and unregistering notify the shell (SHChangeNotify).

A process installed from an MSIX package reports PlatformUnavailableReason.BackendUnavailable: Windows redirects its writes into the package, whose manifest declares uap:Protocol and uap:FileTypeAssociation extensions instead.

CreatePowerEvents

public static IDesktopPowerEvents CreatePowerEvents()

Creates sleep, wake, session lock and battery events.

Remarks

Each watch runs a hidden top-level window on its own thread: WM_POWERBROADCAST (with RegisterSuspendResumeNotification, also on modern standby) gives DesktopPowerEventKind.Suspending and DesktopPowerEventKind.Resumed, WTSRegisterSessionNotification the lock and unlock of the current session, and GetSystemPowerStatus, read again on each power status or Battery Saver change, the battery and saver state. A read takes the lock state from WTSQuerySessionInformation.

Windows gives an application about two seconds after Suspending; Runic does not delay the sleep. It needs no window of the application.

CreateSecretStore

public static IDesktopSecretStore CreateSecretStore()

Creates secret storage in the user's Credential Manager, as generic credentials.

Remarks

Each secret is a credential whose target is service/account, with / and % in the service percent-encoded, and whose user name is the account. It persists for this user on this computer. A binary secret above 2560 bytes, the blob limit, is kept in a file under %LOCALAPPDATA%\Runic\Secrets protected with DPAPI for this user (CryptProtectData), which the credential refers to; deleting the secret removes both.

CreateSecretStore

public static IDesktopSecretStore CreateSecretStore(DesktopSecretStoreOptions options)

Creates secret storage in the user's Credential Manager with options.

Exceptions

ArgumentNullException

options is null.

Remarks

The same store as WindowsPlatformProvider.CreateSecretStore: Credential Manager never prompts and transfers nothing in the clear, so DesktopSecretStoreOptions.AllowUserInteraction and DesktopSecretStoreOptions.RequireEncryption have no effect, nor has the macOS-only DesktopSecretStoreOptions.UseDataProtectionKeychain.

CreateSettings

public static IDesktopSettings CreateSettings()

Creates observable Windows appearance preferences.

CreateStatusIcon

public static IDesktopStatusIcon CreateStatusIcon()

Creates the notification-area icon with a menu.

Remarks

It needs no window: a tray-only application can create it. The icon and its menu run on a thread of their own.

CreateThumbnails

public static IDesktopThumbnails CreateThumbnails()

Creates thumbnails from the shell's thumbnail providers and cache, as Explorer shows them.

Remarks

It needs no window. A file without a thumbnail provider gets no thumbnail, never its icon. Each request extracts on a single-threaded apartment thread of its own, a few at a time.

CreateTrash

public static IDesktopTrash CreateTrash()

Creates the Recycle Bin, through the shell's own file operation without UI.

Remarks

An item the shell cannot recycle, such as one on a network share or larger than the Recycle Bin, is not deleted permanently: the request reports PlatformUnavailableReason.BackendUnavailable. Listing, restoring and emptying go through the Recycle Bin's shell folder, without UI.

CreateUnownedFileDialogs

public static IPickerBackend CreateUnownedFileDialogs()

Creates the application's file dialogs without an owner window: the Common Item Dialog (IFileOpenDialog, IFileSaveDialog) shown without a parent.

Exceptions

PlatformNotSupportedException

Not Windows 8 or later.

Remarks

For a presentation without a native window, such as a CS-WebUI browser window or a tray-only application. Prefer a window's IFileDialogs while it has one, so the dialog is modal for it. Pass the result to services.AddRunicPlatformServices(...) of Runic.Application.Views.CsWebUi to make the window services' IFileDialogs show these dialogs for OwnerPolicy.PreferOwner, or call it directly.

Each dialog runs on a single-threaded apartment thread of its own, which Runic starts for it and ends when it closes; call from any thread. Dialogs that several windows show at once are independent: each answers and closes on its own. Windows' foreground rules apply to a dialog without an owner: when another application, such as the browser that showed the request, is in the foreground, the dialog may open behind it with its taskbar button flashing. Titles, filters, the initial directory, the suggested name and the selected filter behave as for an owned dialog; the buttons are Windows' own, in the user's language. Cancellation closes a shown dialog and throws OperationCanceledException; a dismissed dialog reports Dismissed. Open, multiple, directory, document and save selection are all available, and saves replace the file atomically.

A lease from the backend directly is the caller's to dispose. Through a window's IFileDialogs a second dialog while one is shown reports PlatformFailureCode.ResourceBusy, and closing the window closes a shown dialog and releases what is left. The backend itself needs no disposal.

CreateVolumes

public static IDesktopVolumes CreateVolumes()

Creates the computer's storage volumes, through the volume management API and the Configuration Manager.

Remarks

Windows mounts every volume it recognizes itself, at its drive letters and mounted folders: IDesktopVolumes.MountAsync returns a mounted volume as it is and IDesktopVolumes.UnmountAsync succeeds for a volume without a mount path; otherwise both report PlatformUnavailableReason.BackendUnavailable. IDesktopVolumes.EjectAsync safely removes the drive, as "Safely Remove Hardware" does; a program that keeps a file open on it is PlatformFailureCode.ResourceBusy; an optical drive opens its tray. A locked BitLocker volume is listed locked and unlocks through Explorer's prompt. The volumes need no window and hold no native resources except during a watch.

GetLaunch

public static ApplicationLaunch GetLaunch(IEnumerable<string> arguments)

This process's launch, with the items of an MSIX package's activation as arguments.

Parameters

arguments

The process's arguments, as Main receives them.

Remarks

Outside a package, the same as ApplicationLaunch.FromProcess. In a package it reads the activation (AppInstance.GetActivatedEventArgs): a protocol activation adds its URI and a file activation every file, several at once for a file type with MultiSelectModel="Player", in one process; items the arguments already carry are not repeated. A launch or startup task activation carries only the arguments.