diff --git a/LANCommander.Launcher.Services/ImportService.cs b/LANCommander.Launcher.Services/ImportService.cs index 75fe6bd9..de0db980 100644 --- a/LANCommander.Launcher.Services/ImportService.cs +++ b/LANCommander.Launcher.Services/ImportService.cs @@ -39,6 +39,8 @@ namespace LANCommander.Launcher.Services { try { + OnImportStarted?.Invoke(this, EventArgs.Empty); + await ImportLibraryAsync(); OnImportComplete?.Invoke(this, EventArgs.Empty); @@ -54,6 +56,8 @@ namespace LANCommander.Launcher.Services var remoteLibrary = await libraryClient.GetAsync(); Logger?.LogInformation("Starting library import"); + + OnImportStarted?.Invoke(this, EventArgs.Empty); var importContext = importContextFactory.Create(); @@ -70,10 +74,14 @@ namespace LANCommander.Launcher.Services catch (Exception ex) { Logger?.LogError(ex, "Could not add game with ID {GameId} to import queue", game.Id); + + OnImportError?.Invoke(this, ex); } } await importContext.ImportQueueAsync(); + + OnImportComplete?.Invoke(this, EventArgs.Empty); } public async Task ImportGameAsync(Guid gameId) diff --git a/LANCommander.Launcher/UI/Components/ImportHandler.razor b/LANCommander.Launcher/UI/Components/ImportHandler.razor index 13602477..5147a79b 100644 --- a/LANCommander.Launcher/UI/Components/ImportHandler.razor +++ b/LANCommander.Launcher/UI/Components/ImportHandler.razor @@ -1,4 +1,3 @@ -@using LANCommander.Launcher.Models @using LANCommander.Launcher.Services.Import @implements IDisposable @inject ImportManagerService ImportManagerService @@ -30,9 +29,10 @@ if (ImportService != null) { // Clear any existing handlers - //ImportService.OnImportComplete -= OnImportCompleteHandler; - //ImportService.OnImportFailed -= OnImportFailedHandler; - //ImportService.OnImportUpdated -= OnImportUpdatedHandler; + ImportService.OnImportStarted -= ImportStarted; + ImportService.OnImportComplete -= OnImportComplete; + ImportService.OnImportError -= OnImportFailed; + ImportService.OnImportStatusUpdate -= OnImportStatusUpdate; } } @@ -43,14 +43,17 @@ Logger?.LogInformation("Starting import process"); // Clear any existing handlers - //ImportService.OnImportComplete -= OnImportCompleteHandler; - //ImportService.OnImportFailed -= OnImportFailedHandler; - //ImportService.OnImportUpdated -= OnImportUpdatedHandler; + ImportService.OnImportStarted -= ImportStarted; + ImportService.OnImportComplete -= OnImportComplete; + ImportService.OnImportError -= OnImportFailed; + ImportService.OnImportStatusUpdate -= OnImportStatusUpdate; // Add our handlers - //ImportService.OnImportComplete += OnImportCompleteHandler; - //ImportService.OnImportFailed += OnImportFailedHandler; - //ImportService.OnImportUpdated += OnImportUpdatedHandler; + ImportService.OnImportStarted += ImportStarted; + ImportService.OnImportComplete += OnImportComplete; + ImportService.OnImportError += OnImportFailed; + ImportService.OnImportStatusUpdate += OnImportStatusUpdate; + // Now start the import process Importing = true; @@ -80,8 +83,13 @@ Total = ImportStatusTotal, }); } + + private void ImportStarted(object? sender, EventArgs e) + { + NotifyProgress(ImportProgressState.Importing); + } - private async Task OnImportCompleteHandler() + private async void OnImportComplete(object? sender, EventArgs e) { Logger?.LogInformation("Import Complete handler called"); Importing = false; @@ -92,7 +100,7 @@ MessageService.Success(LocalizationService.GetString("ImportComplete"), 3); } - private async Task OnImportFailedHandler(Exception ex) + private async void OnImportFailed(object? sender, Exception? ex) { Importing = false; ImportStatusIndex = 0; @@ -102,7 +110,7 @@ MessageService.Error(LocalizationService.GetString("ImportFailed"), 3); } - private async Task OnImportUpdatedHandler(ImportStatusUpdate status) + private async void OnImportStatusUpdate(object? sender, ImportStatusUpdate? status) { Logger?.LogInformation("Import Update handler called: {Index}/{Total}", status.Index, status.Total); ImportStatusIndex = status.Index;