Currently methods like ShowDirectoryPickerAsync return a non-nullable object and throw when the user cancels. It's quite awkward to use:
FileSystemDirectoryHandleInProcess folder;
try
{
folder = await Fs.ShowDirectoryPickerAsync(new DirectoryPickerOptions()
{
Mode = FileSystemPermissionMode.ReadWrite,
Id = "id",
});
}
catch (JSException ex) when (ex.Message.Contains("AbortError"))
{
return; // When cancel
}
// Use folder here
I understand it would be breaking change to make it nullable, so we can either add a method to the services directly or write extension methods for them. Suggestion:
static async<T?> TryShowAsync<T>(Func<Task<T>> action); // Common wrapper to be reused for all picker methods.
public async<FileSystemDirectoryHandleInProcess> TryShowDirectoryPickerAsync() => await TryShowAsync(async() => Fs.ShowDirectoryPickerAsync());
// ...
I am happy to make a PR if you agree and choose the preferred way to implement it.
Currently methods like
ShowDirectoryPickerAsyncreturn a non-nullable object and throw when the user cancels. It's quite awkward to use:I understand it would be breaking change to make it nullable, so we can either add a method to the services directly or write extension methods for them. Suggestion:
I am happy to make a PR if you agree and choose the preferred way to implement it.