Updated certain events to have more concrete event arguments. Added try-catch block around playlist save logic. Added DispatchQueue where necessary.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Harmonia.Core.Player;
|
||||
using Harmonia.Core.Playlists;
|
||||
using Microsoft.UI.Dispatching;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
@@ -10,6 +11,7 @@ public partial class PlaylistsViewModel : ViewModelBase
|
||||
{
|
||||
private readonly IPlaylistManager _playlistManager;
|
||||
private readonly IAudioPlayer _audioPlayer;
|
||||
private readonly DispatcherQueue _dispatcherQueue;
|
||||
|
||||
private ObservableCollection<PlaylistItemViewModel> _playlists = [];
|
||||
public ObservableCollection<PlaylistItemViewModel> Playlists
|
||||
@@ -63,6 +65,8 @@ public partial class PlaylistsViewModel : ViewModelBase
|
||||
_audioPlayer = audioPlayer;
|
||||
_audioPlayer.PlayingSongChanged += OnPlayingSongChanged;
|
||||
|
||||
_dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||
|
||||
_playlists = new ObservableCollection<PlaylistItemViewModel>(_playlistManager.Playlists.Select(p => new PlaylistItemViewModel(p)));
|
||||
_selectedPlaylist = _playlists.FirstOrDefault(pv => pv.Playlist == _playlistManager.CurrentPlaylist);
|
||||
}
|
||||
@@ -88,7 +92,12 @@ public partial class PlaylistsViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayingSongChanged(object? sender, EventArgs e)
|
||||
private void OnPlayingSongChanged(object? sender, PlayingSongChangedEventArgs e)
|
||||
{
|
||||
_dispatcherQueue.TryEnqueue(UpdateActivePlaylist);
|
||||
}
|
||||
|
||||
private void UpdateActivePlaylist()
|
||||
{
|
||||
ActivePlaylist = Playlists.FirstOrDefault(pv => pv.Playlist == _audioPlayer.Playlist);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user