perf: WpfGui优化任务进度显示 (#11055)

perf: 优化任务进度显示
This commit is contained in:
status102
2024-11-12 13:52:22 +08:00
committed by GitHub
parent a29696d15a
commit 4becaa4b02
4 changed files with 21 additions and 12 deletions

View File

@@ -132,6 +132,7 @@
<PackageReference Include="Stylet" Version="1.3.6" />
<PackageReference Include="System.Management" Version="8.0.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="WindowsAPICodePack" Version="8.0.6" />
</ItemGroup>
</Project>

View File

@@ -18,6 +18,7 @@ using System.Windows.Media;
using MaaWpfGui.Constants;
using MaaWpfGui.Helper;
using MaaWpfGui.Main;
using Microsoft.WindowsAPICodePack.Taskbar;
using Stylet;
namespace MaaWpfGui.ViewModels.UI
@@ -90,17 +91,28 @@ namespace MaaWpfGui.ViewModels.UI
set => SetAndNotify(ref _windowTitle, value);
}
private double _progress;
private (int Current, int Max)? _taskProgress;
/// <summary>
/// Gets or sets the progress.
/// Gets or sets the TaskProgress.
/// 0.0 to 1.0.
/// 置 0 以隐藏进度条.
/// </summary>
public double Progress
public (int Current, int Max)? TaskProgress
{
get => _progress;
set => SetAndNotify(ref _progress, value);
get => _taskProgress;
set
{
SetAndNotify(ref _taskProgress, value);
if (value is null)
{
TaskbarManager.Instance.SetProgressValue(0, 0);
}
else
{
TaskbarManager.Instance.SetProgressValue(value.Value.Current, value.Value.Max);
}
}
}
private bool _windowTitleScrollable = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.WindowTitleScrollable, bool.FalseString));

View File

@@ -1143,7 +1143,7 @@ namespace MaaWpfGui.ViewModels.UI
var rvm = (RootViewModel)this.Parent;
if (MainTasksSelectedCount == 0)
{
rvm.Progress = 0;
rvm.TaskProgress = null;
return;
}
@@ -1151,12 +1151,11 @@ namespace MaaWpfGui.ViewModels.UI
if (MainTasksCompletedCount >= MainTasksSelectedCount)
{
rvm.Progress = 0;
rvm.TaskProgress = null;
}
else
{
var progress = MainTasksCompletedCount / (double)MainTasksSelectedCount;
rvm.Progress = progress;
rvm.TaskProgress = (MainTasksCompletedCount, MainTasksSelectedCount);
}
}

View File

@@ -51,9 +51,6 @@
Foreground="{Binding WindowTopMostButtonForeground}" />
</Grid>
</hc:Window.NonClientAreaContent>
<Window.TaskbarItemInfo>
<TaskbarItemInfo ProgressState="Normal" ProgressValue="{Binding Progress}" />
</Window.TaskbarItemInfo>
<DockPanel>
<local:NotifyIcon x:Name="NotifyIcon" Visibility="Hidden" />
<TabControl