1
0
mirror of https://github.com/wangdage12/Snap.Hutao.git synced 2026-03-28 05:52:16 +08:00
This commit is contained in:
fanbook-wangdage
2026-02-20 13:21:48 +08:00
parent e9ed7928d6
commit 640686a837
5 changed files with 44 additions and 1 deletions

View File

@@ -38,6 +38,15 @@ internal sealed partial class GachaLogService : IGachaLogService
}
}
public async ValueTask<IAdvancedDbCollectionView<GachaArchive>> RefreshArchiveCollectionAsync()
{
using (await archivesLock.LockAsync().ConfigureAwait(false))
{
archives = null;
return archives = gachaLogRepository.GetGachaArchiveCollection().ToAdvancedDbCollectionView(serviceProvider);
}
}
public async ValueTask<GachaStatistics> GetStatisticsAsync(GachaLogServiceMetadataContext context, GachaArchive archive)
{
using (ValueStopwatch.MeasureExecution(logger))

View File

@@ -22,4 +22,6 @@ internal interface IGachaLogService
ValueTask RemoveArchiveAsync(GachaArchive archive);
ValueTask<IAdvancedDbCollectionView<GachaArchive>> GetArchiveCollectionAsync();
ValueTask<IAdvancedDbCollectionView<GachaArchive>> RefreshArchiveCollectionAsync();
}

View File

@@ -4,6 +4,7 @@ using Snap.Hutao.Core.ExceptionService;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Model.InterChange.GachaLog;
using Snap.Hutao.Service.GachaLog;
using Snap.Hutao.ViewModel.GachaLog;
using Snap.Hutao.Web.Hoyolab.Hk4e.Event.GachaInfo;
using System.Collections.Immutable;
@@ -13,6 +14,7 @@ internal abstract partial class AbstractUIGF40ImportService : IUIGFImportService
{
private readonly IServiceProvider serviceProvider;
private readonly ITaskContext taskContext;
private readonly IMessenger messenger;
[GeneratedConstructor]
public partial AbstractUIGF40ImportService(IServiceProvider serviceProvider);
@@ -21,6 +23,7 @@ internal abstract partial class AbstractUIGF40ImportService : IUIGFImportService
{
await taskContext.SwitchToBackgroundAsync();
ImportGachaArchives(importOptions.UIGF.Hk4e, importOptions.GachaArchiveUids);
messenger.Send(GachaLogImportedMessage.Empty);
}
private void ImportGachaArchives(ImmutableArray<UIGFEntry<Hk4eItem>> entries, HashSet<uint> uids)

View File

@@ -0,0 +1,13 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.ViewModel.GachaLog;
internal sealed class GachaLogImportedMessage
{
public static readonly GachaLogImportedMessage Empty = new();
private GachaLogImportedMessage()
{
}
}

View File

@@ -26,7 +26,7 @@ namespace Snap.Hutao.ViewModel.GachaLog;
[BindableCustomPropertyProvider]
[Service(ServiceLifetime.Scoped)]
internal sealed partial class GachaLogViewModel : Abstraction.ViewModel
internal sealed partial class GachaLogViewModel : Abstraction.ViewModel, IRecipient<GachaLogImportedMessage>
{
private readonly IContentDialogFactory contentDialogFactory;
private readonly IServiceProvider serviceProvider;
@@ -127,6 +127,22 @@ internal sealed partial class GachaLogViewModel : Abstraction.ViewModel
UpdateStatisticsAsync(Archives?.CurrentItem).SafeForget();
}
public async void Receive(GachaLogImportedMessage message)
{
await RefreshArchiveCollectionAsync().ConfigureAwait(false);
}
private async ValueTask RefreshArchiveCollectionAsync()
{
using (await EnterCriticalSectionAsync().ConfigureAwait(false))
{
IAdvancedDbCollectionView<GachaArchive> archives = await gachaLogService.RefreshArchiveCollectionAsync().ConfigureAwait(false);
await taskContext.SwitchToMainThreadAsync();
Archives = archives;
Archives.MoveCurrentTo(Archives.Source.SelectedOrFirstOrDefault());
}
}
[Command("RefreshByWebCacheCommand")]
private async Task RefreshByWebCacheAsync()
{