Add WaitAndGetLatestDocumentAsync
MODIFY
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
@@ -17,6 +17,7 @@ using WalletWasabi.Fluent.ViewModels.HelpAndSupport;
using WalletWasabi.Fluent.ViewModels.OpenDirectory;
using WalletWasabi.Legal;
using WalletWasabi.Services;
+using WalletWasabi.Logging;
namespace WalletWasabi.Fluent.ViewModels
{
@@ -198,23 +199,24 @@ namespace WalletWasabi.Fluent.ViewModels
RxApp.MainThreadScheduler.Schedule(async () =>
{
- LegalDocuments? document;
-
- while (true)
+ try
+ {
+ await _legalChecker.WaitAndGetLatestDocumentAsync();
+ LegalDocumentsViewModel.RegisterAsyncLazy(async () =>
{
- document = _legalChecker.GetLatestDocument();
+ var document = await _legalChecker.WaitAndGetLatestDocumentAsync();
+ return new LegalDocumentsViewModel(document.Content);
+ });
- if (document is { })
+ _searchPage.RegisterSearchEntry(LegalDocumentsViewModel.MetaData);
+ }
+ catch (Exception ex)
{
- break;
+ if (ex is not OperationCanceledException)
+ {
+ Logger.LogError("Failed to get Legal documents.", ex);
}
-
- await Task.Delay(TimeSpan.FromSeconds(5));
}
-
- LegalDocumentsViewModel.RegisterLazy(() => new LegalDocumentsViewModel(document.Content));
-
- _searchPage.RegisterSearchEntry(LegalDocumentsViewModel.MetaData);
});
UserSupportViewModel.RegisterLazy(() => new UserSupportViewModel());
@@ -222,7 +224,7 @@ namespace WalletWasabi.Fluent.ViewModels
DocsLinkViewModel.RegisterLazy(() => new DocsLinkViewModel());
OpenDataFolderViewModel.RegisterLazy(() => new OpenDataFolderViewModel(_global.DataDir));
- OpenDirectory.OpenWalletsFolderViewModel.RegisterLazy(() => new OpenDirectory.OpenWalletsFolderViewModel(_walletManagerViewModel.Model.WalletDirectories.WalletsDir));
+ OpenWalletsFolderViewModel.RegisterLazy(() => new OpenWalletsFolderViewModel(_walletManagerViewModel.Model.WalletDirectories.WalletsDir));
OpenLogsViewModel.RegisterLazy(() => new OpenLogsViewModel());
OpenTorLogsViewModel.RegisterLazy(() => new OpenTorLogsViewModel(_global));
OpenConfigFileViewModel.RegisterLazy(() => new OpenConfigFileViewModel(_global));

MODIFY
WalletWasabi/Services/LegalChecker.cs
WalletWasabi/Services/LegalChecker.cs
@@ -35,6 +35,7 @@ namespace WalletWasabi.Services
public string ProvisionalLegalFolder { get; }
public LegalDocuments? CurrentLegalDocument { get; private set; }
private LegalDocuments? ProvisionalLegalDocument { get; set; }
+ private TaskCompletionSource<LegalDocuments> LatestDocumentTaskCompletion { get; } = new();
public async Task InitializeAsync(UpdateChecker updateChecker)
{
@@ -44,7 +45,7 @@ namespace WalletWasabi.Services
ProvisionalLegalDocument = await LegalDocuments.LoadAgreedAsync(ProvisionalLegalFolder).ConfigureAwait(false);
}
- public LegalDocuments? GetLatestDocument()
+ public async Task<LegalDocuments> WaitAndGetLatestDocumentAsync()
{
if (TryGetNewLegalDocs(out var provisionalLegal))
{
@@ -55,7 +56,7 @@ namespace WalletWasabi.Services
return currentLegal;
}
- return null;
+ return await LatestDocumentTaskCompletion.Task.ConfigureAwait(false);
}
public bool TryGetNewLegalDocs([NotNullWhen(true)] out LegalDocuments? legalDocuments)
@@ -90,6 +91,7 @@ namespace WalletWasabi.Services
await provisionalLegalDocument.ToFileAsync(ProvisionalLegalFolder).ConfigureAwait(false);
ProvisionalLegalDocument = provisionalLegalDocument;
+ LatestDocumentTaskCompletion.TrySetResult(ProvisionalLegalDocument);
}
}
@@ -133,6 +135,7 @@ namespace WalletWasabi.Services
{
updateChecker.UpdateStatusChanged -= UpdateChecker_UpdateStatusChangedAsync;
}
+ LatestDocumentTaskCompletion.TrySetCanceled();
}
_disposedValue = true;

Add WaitAndGetLatestDocumentAsync