From b45944ebabd4fd8903a222ceb0b1c41ec94882ca Mon Sep 17 00:00:00 2001 From: Aaron Powell Date: Mon, 19 Jan 2026 22:12:18 +1100 Subject: [PATCH] fix: Use async database check for IsInLibrary status --- .../ViewModels/GameDetailViewModel.cs | 6 +++--- LANCommander.Launcher.Services/LibraryService.cs | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/LANCommander.Launcher.Avalonia/ViewModels/GameDetailViewModel.cs b/LANCommander.Launcher.Avalonia/ViewModels/GameDetailViewModel.cs index 5342d5f8..e231143e 100644 --- a/LANCommander.Launcher.Avalonia/ViewModels/GameDetailViewModel.cs +++ b/LANCommander.Launcher.Avalonia/ViewModels/GameDetailViewModel.cs @@ -103,7 +103,7 @@ public partial class GameDetailViewModel : ViewModelBase /// Load game from local cache (Data.Models.Game) /// Used when selecting from the library sidebar /// - 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(); - IsInLibrary = libraryService.IsInLibrary(game.Id); + IsInLibrary = await libraryService.IsInLibraryAsync(game.Id); // Get media paths from local storage var mediaService = scope.ServiceProvider.GetRequiredService(); @@ -181,7 +181,7 @@ public partial class GameDetailViewModel : ViewModelBase var libraryService = scope.ServiceProvider.GetRequiredService(); var gameService = scope.ServiceProvider.GetRequiredService(); - IsInLibrary = libraryService.IsInLibrary(game.Id); + IsInLibrary = await libraryService.IsInLibraryAsync(game.Id); // Check if installed from local database var localGame = await gameService.GetAsync(game.Id); diff --git a/LANCommander.Launcher.Services/LibraryService.cs b/LANCommander.Launcher.Services/LibraryService.cs index 565113d9..b448fca4 100644 --- a/LANCommander.Launcher.Services/LibraryService.cs +++ b/LANCommander.Launcher.Services/LibraryService.cs @@ -167,6 +167,13 @@ namespace LANCommander.Launcher.Services return Items.Any(i => i.Key == itemId); } + public async Task 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> GetItemsAsync() { Items.Clear();