mirror of
https://github.com/Royce551/FRESHMusicPlayer.git
synced 2025-01-22 10:51:52 -05:00
Implement xdg-portal support for importing folders
This commit is contained in:
parent
47d11b397d
commit
d2094f50f4
1 changed files with 31 additions and 4 deletions
|
@ -731,13 +731,40 @@ namespace FRESHMusicPlayer.ViewModels
|
|||
}
|
||||
public async void BrowseFoldersCommand()
|
||||
{
|
||||
var dialog = new OpenFolderDialog()
|
||||
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 (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
if (result.Length == 1)
|
||||
{
|
||||
directory = result[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
//The dialog was closed
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (directory == null)
|
||||
{
|
||||
var directory = await dialog.ShowAsync(desktop.MainWindow);
|
||||
var dialog = new OpenFolderDialog()
|
||||
{
|
||||
|
||||
};
|
||||
if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
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")
|
||||
|
|
Loading…
Reference in a new issue