plat/win_share.rs (Windows)#
Source: lib/plat/win_share.rs
win_share -- (share.rs) Windows' share sheet: the DataTransferManager of a window through
IDataTransferManagerInterop (Windows 10), raw COM as win_winrt.rs
share(&Share) -> SHARE_PENDING / SHARE_NONE the active window of the UI thread (else the main
window): DataRequested is registered, ShowShareUIForWindow opens
the sheet; the files become StorageFiles first (on an MTA thread,
GetFileFromPathAsync, at most 5 s each)
available() -> bool the interop factory exists (Windows 10 and later)
win_share_dismiss() (tests) the sheet in front gets Esc, the app's window comes back
DataRequested (on the UI thread, while the sheet opens) fills the request's DataPackage: the title
(the sheet requires one: the title, else the app's id), the text (SetText), the link (SetWebLink
through Windows.Foundation.Uri), the files (SetStorageItems with an IIterable of our own), and
registers ShareCompleted (IDataPackage3: SHARE_DONE) and ShareCanceled (IDataPackage4, Windows 10
2004: SHARE_CANCELLED). Before 2004 a sheet closed without a target says nothing: there the answer is
SHARE_DONE at once, when the sheet has its items (waiting for it held every later share() at
SHARE_NONE for good). The handlers are small COM objects of ours (IUnknown + Invoke, agile).
A failure inside DataRequested answers SHARE_FAILED (the sheet then says it cannot share).