Skip to content

Commit

Permalink
fix playstate deserialization across restrts
Browse files Browse the repository at this point in the history
  • Loading branch information
zznty committed Apr 12, 2024
1 parent 731fb19 commit 32e9697
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions MusicX/Services/Player/Playlists/IPlaylist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ public class PlaylistJsonConverter : JsonConverter<IPlaylist>
reader.Read();
var type = reader.GetString();
reader.Read();
reader.Read();

return type switch
IPlaylist? playlist = type switch
{
"single" => JsonSerializer.Deserialize<SinglePlaylist>(ref reader, options),
"list" => JsonSerializer.Deserialize<ListPlaylist>(ref reader, options),
Expand All @@ -71,6 +70,11 @@ public class PlaylistJsonConverter : JsonConverter<IPlaylist>
"vkPlaylist" => JsonSerializer.Deserialize<VkPlaylistPlaylist>(ref reader, options),
_ => throw new JsonException("Unsupported playlist type.")
};

if (playlist is null || !reader.Read())
throw new JsonException("Unexpected end when reading playlist.");

return playlist;
}

public override void Write(Utf8JsonWriter writer, IPlaylist value, JsonSerializerOptions options)
Expand Down
2 changes: 1 addition & 1 deletion MusicX/Views/StartingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ await container.GetRequiredService<IVkApiAuthAsync>()
var playArgIndex = Array.BinarySearch(_args, "--play",
StringComparer.OrdinalIgnoreCase);
if (playArgIndex >= 0 && playArgIndex + 1 < _args.Length &&
JsonSerializer.Deserialize<PlayerState>(_args[playArgIndex + 1]) is { } state)
JsonSerializer.Deserialize<PlayerState>(string.Join(string.Empty, _args[(playArgIndex + 1)..])) is { } state)
await container.GetRequiredService<PlayerService>()
.RestoreFromStateAsync(state);
}
Expand Down

0 comments on commit 32e9697

Please sign in to comment.