diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Properties/Resources.Designer.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Properties/Resources.Designer.cs index 9784da0..4ae7358 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Properties/Resources.Designer.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Properties/Resources.Designer.cs @@ -536,5 +536,11 @@ namespace FRESHMusicPlayer.Properties { return ResourceManager.GetString("FileFilter_Other", resourceCulture); } } + + public static string FileFilter_PlaylistFiles { + get { + return ResourceManager.GetString("FileFilter_PlaylistFiles", resourceCulture); + } + } } } diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Properties/Resources.resx b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Properties/Resources.resx index 3f987f4..44ac5ad 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Properties/Resources.resx +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Properties/Resources.resx @@ -365,4 +365,7 @@ Other + + Playlist Files + \ No newline at end of file diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs index 5c0c232..0947b4f 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs @@ -670,39 +670,64 @@ namespace FRESHMusicPlayer.ViewModels } public async void BrowsePlaylistFilesCommand() { - var dialog = new OpenFileDialog() + string[] acceptableFiles = {"xspf", "asx", "wvx", "b4s", "m3u", "m3u8", "pls", "smil", "smi", "zpl"}; + string[] files = null; + + if (await FreedesktopPortal.IsPortalAvailable()) { - Filters = new List + files = await FreedesktopPortal.OpenFiles(Resources.ImportPlaylistFiles, new Dictionary() { - new FileDialogFilter() + {"multiple", true}, + {"accept_label", Resources.ImportPlaylistFiles}, + {"filters", new[] { - Name = "Playlist Files", - Extensions = new(){ "xspf", "asx", "wvx", "b4s", "m3u", "m3u8", "pls", "smil", "smi", "zpl"} - } - } - }; - if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) - { - var files = await dialog.ShowAsync(desktop.MainWindow); - IPlaylistIO reader = PlaylistIOFactory.GetInstance().GetPlaylistIO(files[0]); - foreach (string s in reader.FilePaths) - { - if (!File.Exists(s)) - { - Notifications.Add(new() - { - ContentText = string.Format(Properties.Resources.Notification_FileInPlaylistMissing, Path.GetFileName(s)), - DisplayAsToast = true, - IsImportant = true, - Type = NotificationType.Failure - }); - continue; - } - } - Player.Queue.Add(reader.FilePaths.ToArray()); - await Task.Run(() => Library.Import(reader.FilePaths.ToArray())); - Player.PlayMusic(); + (Resources.FileFilter_PlaylistFiles, acceptableFiles.Select(type => (0u, "*." + type)).ToArray()), + }} + }); } + + if (files == null) + { + var dialog = new OpenFileDialog() + { + Filters = new List + { + new FileDialogFilter() + { + Name = Resources.FileFilter_PlaylistFiles, + Extensions = acceptableFiles.ToList() + } + } + }; + + if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + files = await dialog.ShowAsync(desktop.MainWindow); + } + } + + if (files is not {Length: > 0}) return; + + var reader = PlaylistIOFactory.GetInstance().GetPlaylistIO(files[0]); + foreach (var s in reader.FilePaths) + { + if (!File.Exists(s)) + { + Notifications.Add(new() + { + ContentText = string.Format(Properties.Resources.Notification_FileInPlaylistMissing, + Path.GetFileName(s)), + DisplayAsToast = true, + IsImportant = true, + Type = NotificationType.Failure + }); + continue; + } + } + + Player.Queue.Add(reader.FilePaths.ToArray()); + await Task.Run(() => Library.Import(reader.FilePaths.ToArray())); + Player.PlayMusic(); } public async void BrowseFoldersCommand() {