fix: try-catch OpenFolderPickerAsync to avoid crash when select a directory is NOT exist

This commit is contained in:
Gadfly 2024-08-27 10:40:49 +08:00
parent 492f22fcfa
commit 80559ce199
No known key found for this signature in database
6 changed files with 66 additions and 21 deletions

View file

@ -1,3 +1,4 @@
using System;
using System.IO;
using Avalonia.Controls;
@ -30,9 +31,16 @@ namespace SourceGit.Views
options.SuggestedStartLocation = folder;
}
var selected = await topLevel.StorageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
OpenOrInitRepository(selected[0].Path.LocalPath);
try
{
var selected = await topLevel.StorageProvider.OpenFolderPickerAsync(options);
if (selected.Count == 1)
OpenOrInitRepository(selected[0].Path.LocalPath);
}
catch (Exception exception)
{
App.RaiseException(string.Empty, $"Failed to open repository: {exception.Message}");
}
e.Handled = true;
}