From ed5ef1bf736313681bb48b377dff830c49b774b3 Mon Sep 17 00:00:00 2001 From: Elie Bariche <33458222+ebariche@users.noreply.github.com> Date: Mon, 22 May 2023 11:20:38 -0400 Subject: [PATCH] perf(FileSavePicker): Add SaveAs binding --- .../Storage/CachedFileManager.Interop.wasm.cs | 13 ------------- src/Uno.UWP/Storage/CachedFileManager.wasm.cs | 6 +++++- .../Storage/Pickers/FileSavePicker.Interop.wasm.cs | 3 +++ 3 files changed, 8 insertions(+), 14 deletions(-) delete mode 100644 src/Uno.UWP/Storage/CachedFileManager.Interop.wasm.cs diff --git a/src/Uno.UWP/Storage/CachedFileManager.Interop.wasm.cs b/src/Uno.UWP/Storage/CachedFileManager.Interop.wasm.cs deleted file mode 100644 index d16ea6686a5c..000000000000 --- a/src/Uno.UWP/Storage/CachedFileManager.Interop.wasm.cs +++ /dev/null @@ -1,13 +0,0 @@ -#if NET7_0_OR_GREATER -using System.Runtime.InteropServices.JavaScript; - -namespace __Windows.Storage -{ - internal partial class CachedFileManager - { - internal static partial class NativeMethods - { - } - } -} -#endif \ No newline at end of file diff --git a/src/Uno.UWP/Storage/CachedFileManager.wasm.cs b/src/Uno.UWP/Storage/CachedFileManager.wasm.cs index a9f246703abb..a3877a9d4857 100644 --- a/src/Uno.UWP/Storage/CachedFileManager.wasm.cs +++ b/src/Uno.UWP/Storage/CachedFileManager.wasm.cs @@ -7,7 +7,7 @@ using Windows.Storage.Provider; #if NET7_0_OR_GREATER -using NativeMethods = __Windows.Storage.CachedFileManager.NativeMethods; +using NativeMethods = __Windows.Storage.Pickers.FileSavePicker.NativeMethods; #endif namespace Windows.Storage @@ -31,7 +31,11 @@ private static async Task CompleteUpdatesTaskAsync(IStorageFil try { +#if NET7_0_OR_GREATER + NativeMethods.SaveAs(file.Name, pinnedData, data.Length); +#else WebAssemblyRuntime.InvokeJS($"Windows.Storage.Pickers.FileSavePicker.SaveAs('{file.Name}', {pinnedData}, {data.Length})"); +#endif } finally { diff --git a/src/Uno.UWP/Storage/Pickers/FileSavePicker.Interop.wasm.cs b/src/Uno.UWP/Storage/Pickers/FileSavePicker.Interop.wasm.cs index 93354c5968d9..8eb1ce14eb7a 100644 --- a/src/Uno.UWP/Storage/Pickers/FileSavePicker.Interop.wasm.cs +++ b/src/Uno.UWP/Storage/Pickers/FileSavePicker.Interop.wasm.cs @@ -15,6 +15,9 @@ internal static partial class NativeMethods [JSImport($"{JsType}.nativePickSaveFileAsync")] internal static partial Task PickSaveFileAsync(bool showAll, string fileTypeMap, string suggestedFileName, string id, string startIn); + + [JSImport($"{JsType}.SaveAs")] + internal static partial void SaveAs(string fileName, nint pData, int length); } } }