From 1a2e00f2f9c11915294e80138a3695ec38cb8515 Mon Sep 17 00:00:00 2001 From: Elie Bariche <33458222+ebariche@users.noreply.github.com> Date: Tue, 9 May 2023 18:28:24 -0400 Subject: [PATCH] perf: Add FolderPicker bindings --- .../Storage/Pickers/FolderPicker.Interop.wasm.cs | 9 ++++++++- src/Uno.UWP/Storage/Pickers/FolderPicker.wasm.cs | 12 +++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Uno.UWP/Storage/Pickers/FolderPicker.Interop.wasm.cs b/src/Uno.UWP/Storage/Pickers/FolderPicker.Interop.wasm.cs index 1cd8bdd47b9e..b620eccf1705 100644 --- a/src/Uno.UWP/Storage/Pickers/FolderPicker.Interop.wasm.cs +++ b/src/Uno.UWP/Storage/Pickers/FolderPicker.Interop.wasm.cs @@ -8,7 +8,14 @@ internal partial class FolderPicker { internal static partial class NativeMethods { + private const string JsType = "globalThis.Windows.Storage.Pickers.FolderPicker"; + + [JSImport($"{JsType}.isNativeSupported")] + internal static partial bool IsNativeSupported(); + + [JSImport($"{JsType}.pickSingleFolderAsync")] + internal static partial Task PickSingleFolderAsync(string id, string startIn); } } } -#endif \ No newline at end of file +#endif diff --git a/src/Uno.UWP/Storage/Pickers/FolderPicker.wasm.cs b/src/Uno.UWP/Storage/Pickers/FolderPicker.wasm.cs index 01a121586d68..718e1d9478dd 100644 --- a/src/Uno.UWP/Storage/Pickers/FolderPicker.wasm.cs +++ b/src/Uno.UWP/Storage/Pickers/FolderPicker.wasm.cs @@ -16,7 +16,9 @@ namespace Windows.Storage.Pickers { public partial class FolderPicker { +#if !NET7_0_OR_GREATER private const string JsType = "Windows.Storage.Pickers.FolderPicker"; +#endif private static bool? _fileSystemAccessApiSupported; @@ -24,8 +26,12 @@ internal static bool IsNativePickerSupported() { if (_fileSystemAccessApiSupported is null) { +#if NET7_0_OR_GREATER + _fileSystemAccessApiSupported = NativeMethods.IsNativeSupported(); +#else var isSupportedString = WebAssemblyRuntime.InvokeJS($"{JsType}.isNativeSupported()"); _fileSystemAccessApiSupported = bool.TryParse(isSupportedString, out var isSupported) && isSupported; +#endif } return _fileSystemAccessApiSupported.Value; @@ -38,10 +44,14 @@ internal static bool IsNativePickerSupported() throw new NotSupportedException("Could not handle the request using any picker implementation."); } - var id = WebAssemblyRuntime.EscapeJs(SettingsIdentifier); var startIn = SuggestedStartLocation.ToStartInDirectory(); +#if NET7_0_OR_GREATER + var pickedFolderJson = await NativeMethods.PickSingleFolderAsync(SettingsIdentifier, startIn); +#else + var id = WebAssemblyRuntime.EscapeJs(SettingsIdentifier); var pickedFolderJson = await WebAssemblyRuntime.InvokeAsync($"{JsType}.pickSingleFolderAsync('{id}','{startIn}')"); +#endif if (pickedFolderJson is null) {