mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
clear multiple user selection & ignore same background
This commit is contained in:
@@ -26,7 +26,7 @@ internal sealed partial class BackgroundImageService : IBackgroundImageService
|
||||
|
||||
private HashSet<string> backgroundPathSet;
|
||||
|
||||
public async ValueTask<ValueResult<bool, BackgroundImage>> GetNextBackgroundImageAsync()
|
||||
public async ValueTask<ValueResult<bool, BackgroundImage>> GetNextBackgroundImageAsync(BackgroundImage? previous)
|
||||
{
|
||||
HashSet<string> backgroundSet = await SkipOrInitBackgroundAsync().ConfigureAwait(false);
|
||||
|
||||
@@ -37,6 +37,12 @@ internal sealed partial class BackgroundImageService : IBackgroundImageService
|
||||
|
||||
string path = System.Random.Shared.GetItems(backgroundSet.ToArray(), 1)[0];
|
||||
backgroundSet.Remove(path);
|
||||
|
||||
if (string.Equals(path, previous?.ImageSource.UriSource.ToString(), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new(false, default!);
|
||||
}
|
||||
|
||||
using (FileStream fileStream = File.OpenRead(path))
|
||||
{
|
||||
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream.AsRandomAccessStream());
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
|
||||
namespace Snap.Hutao.Service.BackgroundImage;
|
||||
|
||||
internal interface IBackgroundImageService
|
||||
{
|
||||
ValueTask<ValueResult<bool, BackgroundImage>> GetNextBackgroundImageAsync();
|
||||
ValueTask<ValueResult<bool, BackgroundImage>> GetNextBackgroundImageAsync(BackgroundImage? previous);
|
||||
}
|
||||
@@ -14,4 +14,5 @@ internal interface IUserDbService
|
||||
ValueTask<List<Model.Entity.User>> GetUserListAsync();
|
||||
|
||||
ValueTask UpdateUserAsync(Model.Entity.User user);
|
||||
ValueTask ClearUserSelectionAsync();
|
||||
}
|
||||
@@ -41,12 +41,12 @@ internal sealed partial class UserCollectionService : IUserCollectionService, ID
|
||||
public async ValueTask<ObservableReorderableDbCollection<BindingUser, EntityUser>> GetUserCollectionAsync()
|
||||
{
|
||||
// Force run in background thread, otherwise will cause reentrance
|
||||
await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding);
|
||||
await taskContext.SwitchToBackgroundAsync();
|
||||
using (await throttler.EnterAsync().ConfigureAwait(false))
|
||||
{
|
||||
if (userCollection is null)
|
||||
{
|
||||
List<Model.Entity.User> entities = await userDbService.GetUserListAsync().ConfigureAwait(false);
|
||||
List<EntityUser> entities = await userDbService.GetUserListAsync().ConfigureAwait(false);
|
||||
List<BindingUser> users = await entities.SelectListAsync(userInitializationService.ResumeUserAsync).ConfigureAwait(false);
|
||||
|
||||
midUserMap = [];
|
||||
@@ -70,9 +70,14 @@ internal sealed partial class UserCollectionService : IUserCollectionService, ID
|
||||
{
|
||||
CurrentUser = users.SelectedOrDefault();
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
ThrowHelper.UserdataCorrupted(SH.ServiceUserCurrentMultiMatched, ex);
|
||||
foreach (BindingUser user in users)
|
||||
{
|
||||
user.IsSelected = false;
|
||||
}
|
||||
|
||||
await userDbService.ClearUserSelectionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,4 +57,13 @@ internal sealed partial class UserDbService : IUserDbService
|
||||
await appDbContext.Users.ExecuteDeleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask ClearUserSelectionAsync()
|
||||
{
|
||||
using (IServiceScope scope = serviceProvider.CreateScope())
|
||||
{
|
||||
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
await appDbContext.Users.ExecuteUpdateAsync(update => update.SetProperty(user => user.IsSelected, user => false)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ internal sealed partial class MainView : UserControl
|
||||
private readonly IBackgroundImageService backgroundImageService;
|
||||
private TaskCompletionSource acutalThemeChangedTaskCompletionSource = new();
|
||||
private CancellationTokenSource periodicTimerCancellationTokenSource = new();
|
||||
private BackgroundImage? previousBackgroundImage;
|
||||
|
||||
/// <summary>
|
||||
/// 构造一个新的主视图
|
||||
@@ -51,10 +52,11 @@ internal sealed partial class MainView : UserControl
|
||||
{
|
||||
do
|
||||
{
|
||||
(bool isOk, BackgroundImage backgroundImage) = await backgroundImageService.GetNextBackgroundImageAsync().ConfigureAwait(false);
|
||||
(bool isOk, BackgroundImage backgroundImage) = await backgroundImageService.GetNextBackgroundImageAsync(previousBackgroundImage).ConfigureAwait(false);
|
||||
|
||||
if (isOk)
|
||||
{
|
||||
previousBackgroundImage = backgroundImage;
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
|
||||
await AnimationBuilder
|
||||
|
||||
Reference in New Issue
Block a user