private async Task <StorageFolder?> PickSingleFolderTaskAsync(CancellationToken token) { if (!IsNativePickerSupported()) { throw new NotSupportedException("Could not handle the request using any picker implementation."); } var id = WebAssemblyRuntime.EscapeJs(SettingsIdentifier); var startIn = SuggestedStartLocation.ToStartInDirectory(); var pickedFolderJson = await WebAssemblyRuntime.InvokeAsync($"{JsType}.pickSingleFolderAsync('{id}','{startIn}')"); if (pickedFolderJson is null) { // User did not select any folder. return(null); } var info = JsonHelper.Deserialize <NativeStorageItemInfo>(pickedFolderJson); return(StorageFolder.GetFromNativeInfo(info, null)); }
private async Task <StorageFile?> NativePickerPickSaveFileAsync(CancellationToken token) { var showAllEntryParameter = "true"; var fileTypeMapParameter = JsonHelper.Serialize(BuildFileTypesMap()); var suggestedFileName = SuggestedFileName != "" ? WebAssemblyRuntime.EscapeJs(SuggestedFileName) : ""; var id = WebAssemblyRuntime.EscapeJs(SettingsIdentifier); var startIn = SuggestedStartLocation.ToStartInDirectory(); var promise = $"{JsType}.nativePickSaveFileAsync({showAllEntryParameter},'{WebAssemblyRuntime.EscapeJs(fileTypeMapParameter)}','{suggestedFileName}','{id}','{startIn}')"; var nativeStorageItemInfo = await WebAssemblyRuntime.InvokeAsync(promise); if (nativeStorageItemInfo is null) { return(null); } var info = JsonHelper.Deserialize <NativeStorageItemInfo>(nativeStorageItemInfo); return(StorageFile.GetFromNativeInfo(info)); }
private async Task <FilePickerSelectedFilesArray> NativePickerPickFilesAsync(bool multiple, CancellationToken token) { var showAllEntryParameter = FileTypeFilter.Contains("*") ? "true" : "false"; var multipleParameter = multiple ? "true" : "false"; var fileTypeAcceptTypes = BuildFileTypesMap(); var fileTypeAcceptTypesJson = JsonHelper.Serialize(fileTypeAcceptTypes); var fileTypeMapParameter = WebAssemblyRuntime.EscapeJs(fileTypeAcceptTypesJson); var id = WebAssemblyRuntime.EscapeJs(SettingsIdentifier); var startIn = SuggestedStartLocation.ToStartInDirectory(); var nativeStorageItemInfosJson = await WebAssemblyRuntime.InvokeAsync($"{JsType}.nativePickFilesAsync({multipleParameter},{showAllEntryParameter},'{fileTypeMapParameter}','{id}','{startIn}')"); var infos = JsonHelper.Deserialize <NativeStorageItemInfo[]>(nativeStorageItemInfosJson); var results = new List <StorageFile>(); foreach (var info in infos) { var storageFile = StorageFile.GetFromNativeInfo(info); results.Add(storageFile); } return(new FilePickerSelectedFilesArray(results.ToArray())); }