fix: Use async database check for IsInLibrary status

This commit is contained in:
Aaron Powell 2026-01-19 22:12:18 +11:00
parent 281bf14af3
commit b45944ebab
2 changed files with 10 additions and 3 deletions

View file

@ -103,7 +103,7 @@ public partial class GameDetailViewModel : ViewModelBase
/// Load game from local cache (Data.Models.Game)
/// Used when selecting from the library sidebar
/// </summary>
public void LoadGame(Data.Models.Game game)
public async void LoadGame(Data.Models.Game game)
{
Id = game.Id;
Title = game.Title ?? "Unknown";
@ -117,7 +117,7 @@ public partial class GameDetailViewModel : ViewModelBase
// Check library status
using var scope = _serviceProvider.CreateScope();
var libraryService = scope.ServiceProvider.GetRequiredService<LibraryService>();
IsInLibrary = libraryService.IsInLibrary(game.Id);
IsInLibrary = await libraryService.IsInLibraryAsync(game.Id);
// Get media paths from local storage
var mediaService = scope.ServiceProvider.GetRequiredService<MediaService>();
@ -181,7 +181,7 @@ public partial class GameDetailViewModel : ViewModelBase
var libraryService = scope.ServiceProvider.GetRequiredService<LibraryService>();
var gameService = scope.ServiceProvider.GetRequiredService<GameService>();
IsInLibrary = libraryService.IsInLibrary(game.Id);
IsInLibrary = await libraryService.IsInLibraryAsync(game.Id);
// Check if installed from local database
var localGame = await gameService.GetAsync(game.Id);

View file

@ -167,6 +167,13 @@ namespace LANCommander.Launcher.Services
return Items.Any(i => i.Key == itemId);
}
public async Task<bool> IsInLibraryAsync(Guid gameId)
{
var userId = AuthenticationService.GetUserId();
return await Context.Games
.AnyAsync(g => g.Id == gameId && g.Libraries.Any(l => l.UserId == userId));
}
public async Task<IEnumerable<ListItem>> GetItemsAsync()
{
Items.Clear();