Fix potential modlists loading crash on slow connections

This commit is contained in:
trawzified 2023-12-30 13:06:50 +01:00
parent 601ee7eabe
commit a908c49f26

View File

@ -16,6 +16,7 @@ using Wabbajack.DTOs;
using Microsoft.Extensions.Logging;
using System.Reactive.Disposables;
using System.Diagnostics;
using DynamicData;
namespace Wabbajack
{
@ -23,6 +24,7 @@ namespace Wabbajack
{
private readonly ILogger<HomeVM> _logger;
private readonly Client _wjClient;
private readonly SourceCache<ModListMetadataVM, string> _modLists = new(x => x.Metadata.NamespacedName);
public HomeVM(ILogger<HomeVM> logger, Client wjClient)
{
@ -37,23 +39,28 @@ namespace Wabbajack
};
Process.Start(processStartInfo);
});
this.WhenActivated(async disposables =>
LoadModLists().FireAndForget();
}
private async Task LoadModLists()
{
using var ll = LoadingLock.WithLoading();
try
{
Modlists = await _wjClient.LoadLists().DisposeWith(disposables);
Modlists = await _wjClient.LoadLists();
}
catch (Exception ex)
{
_logger.LogError(ex, "While loading lists");
ll.Fail();
}
});
ll.Succeed();
}
public ICommand VisitModlistWizardCommand { get; }
public ICommand BrowseCommand { get; }
public ReactiveCommand<Unit, Unit> UpdateCommand { get; }
[Reactive]
public ModlistMetadata[] Modlists { get; set; }
public ModlistMetadata[] Modlists { get; private set; }
}
}