diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index 7eaa264915..0e9ae18dc9 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -149,6 +149,12 @@ public class TaskQueueViewModel : Screen /// public ObservableCollection LogItemViewModels { get; private set; } = []; + /// + /// Gets or private sets the view models of download-related log items. + /// This is a separate area dedicated to showing download progress/messages. + /// + public ObservableCollection DownloadLogItemViewModels { get; private set; } = []; + #region ActionAfterTasks private bool _enableAfterActionSetting; @@ -889,11 +895,35 @@ public class TaskQueueViewModel : Screen Execute.OnUIThread(() => { LogItemViewModels.Clear(); + DownloadLogItemViewModels.Clear(); _logger.Information("Main windows log clear."); _logger.Information("{Empty}", string.Empty); }); } + /// + /// Update the dedicated download log area. Thread-safe and will run on UI thread. + /// Mirrors previous logic which updated the first download log entry. + /// + /// The full text to show in download area. + /// Optional tooltip. + public void UpdateDownloadLog(string fullText, ToolTip? toolTip = null) + { + Execute.OnUIThread(() => + { + // Keep download area limited to a single entry. + if (string.IsNullOrEmpty(fullText)) + { + DownloadLogItemViewModels.Clear(); + return; + } + + var log = new LogItemViewModel(fullText, UiLogColor.Download, toolTip: toolTip); + DownloadLogItemViewModels.Clear(); + DownloadLogItemViewModels.Add(log); + }); + } + /// /// Selects all. /// UI 绑定的方法 diff --git a/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs b/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs index db557ed267..4febbf79b2 100644 --- a/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs @@ -1170,8 +1170,6 @@ public class VersionUpdateViewModel : Screen } } - private static ObservableCollection? _logItemViewModels; - public static void OutputDownloadProgress(long value = 0, long maximum = 1, int len = 0, double ts = 1, string? toolTip = null) { string progress = $"[{value / 1048576.0:F}MiB/{maximum / 1048576.0:F}MiB ({value * 100.0 / maximum:F}%)"; @@ -1191,22 +1189,6 @@ public class VersionUpdateViewModel : Screen { globalSource ??= _globalSource; _globalSource = globalSource.Value; - if (_logItemViewModels == null) - { - try - { - _logItemViewModels = Instances.TaskQueueViewModel.LogItemViewModels; - } - catch - { - return; - } - - if (_logItemViewModels == null) - { - return; - } - } string fullText; if (downloading) @@ -1219,26 +1201,7 @@ public class VersionUpdateViewModel : Screen fullText = output; } - Execute.OnUIThread(() => - { - var log = new LogItemViewModel(fullText, UiLogColor.Download, toolTip: toolTip?.CreateTooltip()); - if (_logItemViewModels.Count > 0 && _logItemViewModels[0].Color == UiLogColor.Download) - { - if (!string.IsNullOrEmpty(output)) - { - _logItemViewModels[0] = log; - } - else - { - _logItemViewModels.RemoveAt(0); - } - } - else if (!string.IsNullOrEmpty(output)) - { - _logItemViewModels.Clear(); - _logItemViewModels.Add(log); - } - }); + Instances.TaskQueueViewModel?.UpdateDownloadLog(fullText, toolTip?.CreateTooltip()); } public bool IsDebugVersion(string? version = null) diff --git a/src/MaaWpfGui/Views/UI/TaskQueueView.xaml b/src/MaaWpfGui/Views/UI/TaskQueueView.xaml index 3eea8caf50..671d38cd9e 100644 --- a/src/MaaWpfGui/Views/UI/TaskQueueView.xaml +++ b/src/MaaWpfGui/Views/UI/TaskQueueView.xaml @@ -373,21 +373,23 @@ - + + + + + + + VerticalAlignment="Top" + d:ItemsSource="{d:SampleData ItemCount=1}" + ItemsSource="{Binding DownloadLogItemViewModels}"> @@ -424,37 +426,83 @@ ForegroundKey="{Binding Color}" Text="{Binding Content}" TextWrapping="Wrap" /> - - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + +