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:
@@ -25,6 +25,7 @@ public class PlaylistManager : IPlaylistManager
|
||||
public event EventHandler? CurrentPlaylistChanged;
|
||||
public event EventHandler<PlaylistAddedEventArgs>? PlaylistAdded;
|
||||
public event EventHandler<PlaylistRemovedEventArgs>? PlaylistRemoved;
|
||||
public event EventHandler<PlaylistSaveFailedEventArgs>? PlaylistSaveFailed;
|
||||
|
||||
public PlaylistManager(IPlaylistRepository playlistRepository)
|
||||
{
|
||||
@@ -60,7 +61,7 @@ public class PlaylistManager : IPlaylistManager
|
||||
_playlistsBySongUid[song.UID] = playlist;
|
||||
}
|
||||
|
||||
await playlistRepository.SaveAsync(playlist);
|
||||
await SavePlaylistAsync(playlist);
|
||||
|
||||
PlaylistAdded?.Invoke(this, new(playlist));
|
||||
|
||||
@@ -108,6 +109,18 @@ public class PlaylistManager : IPlaylistManager
|
||||
break;
|
||||
}
|
||||
|
||||
await playlistRepository.SaveAsync(playlist);
|
||||
await SavePlaylistAsync(playlist);
|
||||
}
|
||||
|
||||
private async Task SavePlaylistAsync(Playlist playlist)
|
||||
{
|
||||
try
|
||||
{
|
||||
await playlistRepository.SaveAsync(playlist);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
PlaylistSaveFailed?.Invoke(this, new(playlist, ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user