mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
feat: 将下载日志独立出来
This commit is contained in:
@@ -149,6 +149,12 @@ public class TaskQueueViewModel : Screen
|
||||
/// </summary>
|
||||
public ObservableCollection<LogItemViewModel> LogItemViewModels { get; private set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or private sets the view models of download-related log items.
|
||||
/// This is a separate area dedicated to showing download progress/messages.
|
||||
/// </summary>
|
||||
public ObservableCollection<LogItemViewModel> 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);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the dedicated download log area. Thread-safe and will run on UI thread.
|
||||
/// Mirrors previous logic which updated the first download log entry.
|
||||
/// </summary>
|
||||
/// <param name="fullText">The full text to show in download area.</param>
|
||||
/// <param name="toolTip">Optional tooltip.</param>
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects all.
|
||||
/// UI 绑定的方法
|
||||
|
||||
@@ -1170,8 +1170,6 @@ public class VersionUpdateViewModel : Screen
|
||||
}
|
||||
}
|
||||
|
||||
private static ObservableCollection<LogItemViewModel>? _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)
|
||||
|
||||
@@ -373,21 +373,23 @@
|
||||
|
||||
<!--<GridSplitter Grid.Column="2" Width="5" HorizontalAlignment="Stretch" />-->
|
||||
<!--<Rectangle Grid.Column="2" VerticalAlignment="Stretch" Fill="{DynamicResource BorderBrush}" Width="4" />-->
|
||||
<hc:ScrollViewer
|
||||
<Grid
|
||||
Grid.Column="2"
|
||||
Margin="10"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Top"
|
||||
properties:AutoScroll.AutoScroll="True"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
IsInertiaEnabled="True"
|
||||
PanningMode="Both"
|
||||
Visibility="{c:Binding !TaskSettingVisibilities.Guide}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Download area: always visible, placed above the main log scroll -->
|
||||
<ItemsControl
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
d:ItemsSource="{d:SampleData ItemCount=30}"
|
||||
ItemsSource="{Binding LogItemViewModels}">
|
||||
VerticalAlignment="Top"
|
||||
d:ItemsSource="{d:SampleData ItemCount=1}"
|
||||
ItemsSource="{Binding DownloadLogItemViewModels}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid MaxWidth="400">
|
||||
@@ -424,37 +426,83 @@
|
||||
ForegroundKey="{Binding Color}"
|
||||
Text="{Binding Content}"
|
||||
TextWrapping="Wrap" />
|
||||
<controls:TooltipBlock
|
||||
Grid.Column="1"
|
||||
Margin="10,0,0,0"
|
||||
PathDate="M 0 0 L 0.5 0.5 L 0 1"
|
||||
PathStrokeThickness="1.5"
|
||||
TextBlockText=""
|
||||
Visibility="{c:Binding ShowToolTip}" />
|
||||
<!--<Border
|
||||
Grid.Column="1"
|
||||
Width="15"
|
||||
Height="15"
|
||||
Margin="10,0,0,0"
|
||||
Background="{DynamicResource MouseOverRegionBrushOpacity75}"
|
||||
Style="{StaticResource BorderCircular}"
|
||||
Visibility="{c:Binding ShowToolTip}">
|
||||
<Path
|
||||
Width="8"
|
||||
Height="8"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Data="M 0 0 L 0.5 0.5 L 0 1"
|
||||
Stretch="Uniform"
|
||||
Stroke="{DynamicResource PrimaryTextBrush}"
|
||||
StrokeThickness="2" />
|
||||
</Border>-->
|
||||
</Grid>
|
||||
<controls:TooltipBlock
|
||||
Grid.Column="1"
|
||||
Margin="10,0,0,0"
|
||||
PathDate="M 0 0 L 0.5 0.5 L 0 1"
|
||||
PathStrokeThickness="1.5"
|
||||
TextBlockText=""
|
||||
Visibility="{c:Binding ShowToolTip}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</hc:ScrollViewer>
|
||||
|
||||
<!-- Main log scroll area -->
|
||||
<hc:ScrollViewer
|
||||
Grid.Row="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
properties:AutoScroll.AutoScroll="True"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
IsInertiaEnabled="True"
|
||||
PanningMode="Both">
|
||||
<ItemsControl
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
d:ItemsSource="{d:SampleData ItemCount=20}"
|
||||
ItemsSource="{Binding LogItemViewModels}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid MaxWidth="400">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<controls:TextBlock
|
||||
Grid.Column="0"
|
||||
Margin="0,5,14,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Stretch"
|
||||
Foreground="{DynamicResource TraceLogBrush}"
|
||||
Text="{Binding Time}"
|
||||
TextWrapping="Wrap" />
|
||||
<Grid
|
||||
Grid.Column="1"
|
||||
Margin="0,5"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Stretch"
|
||||
ToolTip="{Binding ToolTip}"
|
||||
ToolTipService.InitialShowDelay="200">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<controls:TextBlock
|
||||
Grid.Column="0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Stretch"
|
||||
FontWeight="{Binding Weight}"
|
||||
ForegroundKey="{Binding Color}"
|
||||
Text="{Binding Content}"
|
||||
TextWrapping="Wrap" />
|
||||
<controls:TooltipBlock
|
||||
Grid.Column="1"
|
||||
Margin="10,0,0,0"
|
||||
PathDate="M 0 0 L 0.5 0.5 L 0 1"
|
||||
PathStrokeThickness="1.5"
|
||||
TextBlockText=""
|
||||
Visibility="{c:Binding ShowToolTip}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</hc:ScrollViewer>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user