3
3
4
4
using Files . App . Extensions ;
5
5
using Files . App . Utils ;
6
+ using Microsoft . UI . Xaml . Controls ;
6
7
using System ;
7
8
using System . Collections . Generic ;
8
9
using System . Linq ;
9
10
using Windows . ApplicationModel . DataTransfer ;
10
11
using Windows . Foundation ;
12
+ using Windows . Foundation . Metadata ;
11
13
using Windows . Storage ;
12
14
13
15
namespace Files . App . Helpers
@@ -19,15 +21,32 @@ public static bool IsItemShareable(ListedItem item)
19
21
( ! item . IsShortcut || item . IsLinkItem ) &&
20
22
( item . PrimaryItemAttribute != StorageItemTypes . Folder || item . IsArchive ) ;
21
23
22
- public static void ShareItems ( IEnumerable < ListedItem > itemsToShare )
24
+ public static async Task ShareItemsAsync ( IEnumerable < ListedItem > itemsToShare )
23
25
{
24
26
var interop = DataTransferManager . As < IDataTransferManagerInterop > ( ) ;
25
27
IntPtr result = interop . GetForWindow ( MainWindow . Instance . WindowHandle , InteropHelpers . DataTransferManagerInteropIID ) ;
26
28
27
29
var manager = WinRT . MarshalInterface < DataTransferManager > . FromAbi ( result ) ;
28
30
manager . DataRequested += new TypedEventHandler < DataTransferManager , DataRequestedEventArgs > ( Manager_DataRequested ) ;
29
31
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
+ }
31
50
32
51
async void Manager_DataRequested ( DataTransferManager sender , DataRequestedEventArgs args )
33
52
{
0 commit comments