33
44using Files . App . Extensions ;
55using Files . App . Utils ;
6+ using Microsoft . UI . Xaml . Controls ;
67using System ;
78using System . Collections . Generic ;
89using System . Linq ;
910using Windows . ApplicationModel . DataTransfer ;
1011using Windows . Foundation ;
12+ using Windows . Foundation . Metadata ;
1113using Windows . Storage ;
1214
1315namespace Files . App . Helpers
@@ -19,15 +21,32 @@ public static bool IsItemShareable(ListedItem item)
1921 ( ! item . IsShortcut || item . IsLinkItem ) &&
2022 ( item . PrimaryItemAttribute != StorageItemTypes . Folder || item . IsArchive ) ;
2123
22- public static void ShareItems ( IEnumerable < ListedItem > itemsToShare )
24+ public static async Task ShareItemsAsync ( IEnumerable < ListedItem > itemsToShare )
2325 {
2426 var interop = DataTransferManager . As < IDataTransferManagerInterop > ( ) ;
2527 IntPtr result = interop . GetForWindow ( MainWindow . Instance . WindowHandle , InteropHelpers . DataTransferManagerInteropIID ) ;
2628
2729 var manager = WinRT . MarshalInterface < DataTransferManager > . FromAbi ( result ) ;
2830 manager . DataRequested += new TypedEventHandler < DataTransferManager , DataRequestedEventArgs > ( Manager_DataRequested ) ;
2931
30- interop . ShowShareUIForWindow ( MainWindow . Instance . WindowHandle ) ;
32+ try
33+ {
34+ interop . ShowShareUIForWindow ( MainWindow . Instance . WindowHandle ) ;
35+ }
36+ catch ( Exception ex )
37+ {
38+ var errorDialog = new ContentDialog ( )
39+ {
40+ Title = "FaildToShareItems" . GetLocalizedResource ( ) ,
41+ Content = ex . Message ,
42+ PrimaryButtonText = "OK" . GetLocalizedResource ( ) ,
43+ } ;
44+
45+ if ( ApiInformation . IsApiContractPresent ( "Windows.Foundation.UniversalApiContract" , 8 ) )
46+ errorDialog . XamlRoot = MainWindow . Instance . Content . XamlRoot ;
47+
48+ await errorDialog . TryShowAsync ( ) ;
49+ }
3150
3251 async void Manager_DataRequested ( DataTransferManager sender , DataRequestedEventArgs args )
3352 {
0 commit comments