2025-06-10 00:17:17 +02:00
|
|
|
@using LANCommander.Launcher.Models
|
|
|
|
|
@implements IDisposable
|
|
|
|
|
@inject ImportManagerService ImportManagerService
|
|
|
|
|
@inject ImportService ImportService
|
|
|
|
|
@inject IMessageService MessageService
|
|
|
|
|
@inject ILogger<ImportHandler> Logger
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
@inject LocalizationService LocalizationService
|
2025-06-10 00:17:17 +02:00
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
{
|
|
|
|
|
[Parameter] public EventCallback<ImportProgressEventArgs> Progress { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool Importing;
|
|
|
|
|
int ImportStatusIndex = 0;
|
|
|
|
|
int ImportStatusTotal = 0;
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
ImportManagerService.OnImportRequested += Import;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
if (ImportManagerService != null)
|
|
|
|
|
{
|
|
|
|
|
ImportManagerService.OnImportRequested -= Import;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ImportService != null)
|
|
|
|
|
{
|
|
|
|
|
// Clear any existing handlers
|
|
|
|
|
ImportService.OnImportComplete -= OnImportCompleteHandler;
|
|
|
|
|
ImportService.OnImportFailed -= OnImportFailedHandler;
|
|
|
|
|
ImportService.OnImportUpdated -= OnImportUpdatedHandler;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Import()
|
|
|
|
|
{
|
|
|
|
|
if (!Importing)
|
|
|
|
|
{
|
|
|
|
|
Logger?.LogInformation("Starting import process");
|
|
|
|
|
|
|
|
|
|
// Clear any existing handlers
|
|
|
|
|
ImportService.OnImportComplete -= OnImportCompleteHandler;
|
|
|
|
|
ImportService.OnImportFailed -= OnImportFailedHandler;
|
|
|
|
|
ImportService.OnImportUpdated -= OnImportUpdatedHandler;
|
|
|
|
|
|
|
|
|
|
// Add our handlers
|
|
|
|
|
ImportService.OnImportComplete += OnImportCompleteHandler;
|
|
|
|
|
ImportService.OnImportFailed += OnImportFailedHandler;
|
|
|
|
|
ImportService.OnImportUpdated += OnImportUpdatedHandler;
|
|
|
|
|
|
|
|
|
|
// Now start the import process
|
|
|
|
|
Importing = true;
|
|
|
|
|
ImportStatusIndex = 0;
|
|
|
|
|
ImportStatusTotal = 0;
|
|
|
|
|
await NotifyProgress(ImportProgressState.Importing);
|
|
|
|
|
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
MessageService.Info(LocalizationService.GetString("ImportStarted"), 2.5);
|
2025-06-10 00:17:17 +02:00
|
|
|
|
|
|
|
|
Logger?.LogInformation("Starting import");
|
|
|
|
|
await ImportService.ImportLibraryAsync(); // Call directly instead of using JS
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task NotifyProgress(ImportProgressState state)
|
|
|
|
|
{
|
|
|
|
|
if (!Progress.HasDelegate)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
await Progress.InvokeAsync(new ImportProgressEventArgs
|
|
|
|
|
{
|
|
|
|
|
State = state,
|
|
|
|
|
Index = ImportStatusIndex,
|
|
|
|
|
Total = ImportStatusTotal,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnImportCompleteHandler()
|
|
|
|
|
{
|
|
|
|
|
Logger?.LogInformation("Import Complete handler called");
|
|
|
|
|
Importing = false;
|
|
|
|
|
ImportStatusIndex = 0;
|
|
|
|
|
ImportStatusTotal = 0;
|
|
|
|
|
|
|
|
|
|
await NotifyProgress(ImportProgressState.Imported);
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
MessageService.Success(LocalizationService.GetString("ImportComplete"), 3);
|
2025-06-10 00:17:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnImportFailedHandler(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Importing = false;
|
|
|
|
|
ImportStatusIndex = 0;
|
|
|
|
|
ImportStatusTotal = 0;
|
|
|
|
|
|
|
|
|
|
await NotifyProgress(ImportProgressState.Failed);
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
MessageService.Error(LocalizationService.GetString("ImportFailed"), 3);
|
2025-06-10 00:17:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnImportUpdatedHandler(ImportStatusUpdate status)
|
|
|
|
|
{
|
|
|
|
|
Logger?.LogInformation("Import Update handler called: {Index}/{Total}", status.Index, status.Total);
|
|
|
|
|
ImportStatusIndex = status.Index;
|
|
|
|
|
ImportStatusTotal = status.Total;
|
|
|
|
|
|
|
|
|
|
await NotifyProgress(ImportProgressState.Updated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ImportProgressState
|
|
|
|
|
{
|
|
|
|
|
None = 0,
|
|
|
|
|
Importing,
|
|
|
|
|
Updated,
|
|
|
|
|
Imported,
|
|
|
|
|
Failed,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ImportProgressEventArgs
|
|
|
|
|
{
|
|
|
|
|
public int Index { get; set; } = 0;
|
|
|
|
|
public int Total { get; set; } = 0;
|
|
|
|
|
public ImportProgressState State { get; set; } = ImportProgressState.None;
|
|
|
|
|
public bool IsActive => State > ImportProgressState.None && State < ImportProgressState.Imported;
|
|
|
|
|
}
|
|
|
|
|
}
|