Implement xdg-portal support for importing folders

This commit is contained in:
Victor Tran 2021-08-13 01:39:39 +10:00
parent 47d11b397d
commit d2094f50f4
No known key found for this signature in database
GPG key ID: 1F0729FE016CDC3E

View file

@ -730,6 +730,29 @@ namespace FRESHMusicPlayer.ViewModels
Player.PlayMusic();
}
public async void BrowseFoldersCommand()
{
string directory = null;
if (await FreedesktopPortal.IsPortalAvailable())
{
var result = await FreedesktopPortal.OpenFiles(Resources.ImportFolders, new Dictionary<string, object>()
{
{"multiple", true},
{"accept_label", Resources.ImportFolders},
{"directory", true}
});
if (result.Length == 1)
{
directory = result[0];
}
else
{
//The dialog was closed
return;
}
}
if (directory == null)
{
var dialog = new OpenFolderDialog()
{
@ -737,7 +760,11 @@ namespace FRESHMusicPlayer.ViewModels
};
if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var directory = await dialog.ShowAsync(desktop.MainWindow);
directory = await dialog.ShowAsync(desktop.MainWindow);
}
}
if (directory != null) {
var paths = Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories)
.Where(name => name.EndsWith(".mp3")
|| name.EndsWith(".wav") || name.EndsWith(".m4a") || name.EndsWith(".ogg")