Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<local:ThemedIcon x:Name="StatusCenterIcon" Width="16" Height="16" Style="{StaticResource App.ThemedIcons.StatusCenter}" Visibility="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}, Converter={ThemeResource NullToVisibilityReConverter}, Mode=OneWay}" />
</Grid>

<ProgressRing x:Name="MedianOperationProgressRing" HorizontalAlignment="Center" VerticalAlignment="Center" AutomationProperties.Name="Status center progress ring" IsIndeterminate="False" Visibility="{Binding ShowProgressRing, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" Value="{Binding AverageOperationProgressValue, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
<ProgressRing x:Name="MedianOperationProgressRing" HorizontalAlignment="Center" VerticalAlignment="Center" AutomationProperties.Name="Status center progress ring" IsIndeterminate="{Binding IsOperationProgressIndeterminate, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" Visibility="{Binding ShowProgressRing, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" Value="{Binding AverageOperationProgressValue, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />

<InfoBadge x:Name="StatusInfoBadge" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="{Binding ShowProgressRing, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" Value="{Binding InfoBadgeValue, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public sealed partial class StatusCenterButton : Control
public static readonly DependencyProperty AverageOperationProgressValueProperty =
DependencyProperty.Register(nameof(AverageOperationProgressValue), typeof(double), typeof(StatusCenterButton), new PropertyMetadata(0d));

public static readonly DependencyProperty IsOperationProgressIndeterminateProperty =
DependencyProperty.Register(nameof(IsOperationProgressIndeterminate), typeof(bool), typeof(StatusCenterButton), new PropertyMetadata(false));

public static readonly DependencyProperty InfoBadgeValueProperty =
DependencyProperty.Register(nameof(InfoBadgeValue), typeof(int), typeof(StatusCenterButton), new PropertyMetadata(-1));

Expand Down Expand Up @@ -61,6 +64,12 @@ public double AverageOperationProgressValue
private set => SetValue(AverageOperationProgressValueProperty, value);
}

public bool IsOperationProgressIndeterminate
{
get => (bool)GetValue(IsOperationProgressIndeterminateProperty);
private set => SetValue(IsOperationProgressIndeterminateProperty, value);
}

public int InfoBadgeValue
{
get => (int)GetValue(InfoBadgeValueProperty);
Expand Down Expand Up @@ -88,6 +97,7 @@ public StatusCenterButton()

ShowProgressRing = ViewModel.ShowProgressRing;
AverageOperationProgressValue = ViewModel.AverageOperationProgressValue;
IsOperationProgressIndeterminate = ViewModel.IsOperationProgressIndeterminate;
InfoBadgeValue = ViewModel.InfoBadgeValue;
InfoBadgeState = ViewModel.InfoBadgeState;
}
Expand Down Expand Up @@ -177,6 +187,9 @@ private void OnViewModelPropertyChanged(object? sender, PropertyChangedEventArgs
case nameof(StatusCenterViewModel.AverageOperationProgressValue):
AverageOperationProgressValue = ViewModel.AverageOperationProgressValue;
break;
case nameof(StatusCenterViewModel.IsOperationProgressIndeterminate):
IsOperationProgressIndeterminate = ViewModel.IsOperationProgressIndeterminate;
break;
case nameof(StatusCenterViewModel.InfoBadgeValue):
InfoBadgeValue = ViewModel.InfoBadgeValue;
break;
Expand Down
8 changes: 4 additions & 4 deletions dev/DevWinUI/Controls/Ported/StatusCenter/StatusCenterItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public StatusCenterItemProgressModel Progress
set => SetProperty(ref _Progress, value);
}

public ReturnResult FileSystemOperationReturnResult { get; set; }
public ReturnResult OperationReturnResult { get; set; }

private StatusCenterItemKind _ItemKind;
public StatusCenterItemKind ItemKind
Expand Down Expand Up @@ -277,7 +277,7 @@ internal StatusCenterItem(
_operationCancellationToken = operationCancellationToken;
Header = header;
SubHeader = subHeader;
FileSystemOperationReturnResult = status;
OperationReturnResult = status;
ProgressEventSource = new Progress<StatusCenterItemProgressModel>(ReportProgress);
Progress = new(ProgressEventSource, status: ReturnResult.InProgress);
IsCancelable = _operationCancellationToken is not null;
Expand All @@ -293,7 +293,7 @@ internal StatusCenterItem(
if (Application.Current.Resources["App.Theme.FillColorAttentionBrush"] is not SolidColorBrush accentBrush)
return;

switch (FileSystemOperationReturnResult)
switch (OperationReturnResult)
{
case ReturnResult.InProgress:
{
Expand Down Expand Up @@ -365,7 +365,7 @@ private void ReportProgress(StatusCenterItemProgressModel value)

// Update status code
if (value.Status is ReturnResult status)
FileSystemOperationReturnResult = status;
OperationReturnResult = status;

// Update the percentage and processing item name
if (value.Percentage is double p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,59 @@ public static void Report(IntPtr windowHandle)
if (!_windows.TryGetValue(windowHandle, out var windowProgress))
return;

var progressValues = windowProgress.ViewModels
var allItems = windowProgress.ViewModels
.SelectMany(vm => vm.StatusCenterItems)
.ToList();

var inProgressItems = allItems
.Where(item => item.IsInProgress)
.ToList();

var activeItems = inProgressItems.Where(item => !item.IsPaused).ToList();
var determinateActiveValues = activeItems
.Where(item => !item.IsIndeterminateProgress)
.Select(item => (double)item.ProgressPercentage)
.ToList();

var determinateValues = inProgressItems
.Where(item => !item.IsIndeterminateProgress)
.Select(item => (double)item.ProgressPercentage)
.ToList();

try
{
if (progressValues.Count > 0)
if (activeItems.Count > 0)
{
TaskbarHelper.SetProgressState(windowHandle, TaskbarStates.Normal);
TaskbarHelper.SetProgressValue(windowHandle, (int)progressValues.Average(), 100);
windowProgress.HasError = false;
if (determinateActiveValues.Count > 0)
{
TaskbarHelper.SetProgressState(windowHandle, TaskbarStates.Normal);
TaskbarHelper.SetProgressValue(windowHandle, (int)determinateActiveValues.Average(), 100);
}
else
{
TaskbarHelper.SetProgressState(windowHandle, TaskbarStates.Indeterminate);
}
}
else if (inProgressItems.Count > 0)
{
windowProgress.HasError = false;
TaskbarHelper.SetProgressState(windowHandle, TaskbarStates.Paused);
if (determinateValues.Count > 0)
TaskbarHelper.SetProgressValue(windowHandle, (int)determinateValues.Average(), 100);
}
else if (allItems.Any(item => item.OperationReturnResult is ReturnResult.Failed or ReturnResult.Cancelled))
{
if (!windowProgress.HasError)
TaskbarHelper.FlashWindow(windowHandle);

windowProgress.HasError = true;
TaskbarHelper.SetProgressValue(windowHandle, 100, 100);
TaskbarHelper.SetProgressState(windowHandle, TaskbarStates.Error);
}
else
{
windowProgress.HasError = false;
TaskbarHelper.SetProgressState(windowHandle, TaskbarStates.NoProgress);
}
}
Expand All @@ -70,6 +108,8 @@ private sealed partial class WindowTaskbarProgress
{
public HashSet<StatusCenterViewModel> ViewModels { get; } = [];

public bool HasError { get; set; }

public WindowTaskbarProgress(IntPtr windowHandle)
{
var window = WindowHelper.ActiveWindows
Expand Down
25 changes: 22 additions & 3 deletions dev/DevWinUI/Controls/Ported/StatusCenter/StatusCenterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public int AverageOperationProgressValue
private set => SetProperty(ref _AverageOperationProgressValue, value);
}

private bool _isOperationProgressIndeterminate;
public bool IsOperationProgressIndeterminate
{
get => _isOperationProgressIndeterminate;
private set => SetProperty(ref _isOperationProgressIndeterminate, value);
}

public int InProgressItemCount
{
get
Expand Down Expand Up @@ -80,8 +87,8 @@ public int InfoBadgeState
get
{
var anyFailure = StatusCenterItems.Any(i =>
i.FileSystemOperationReturnResult != ReturnResult.InProgress &&
i.FileSystemOperationReturnResult != ReturnResult.Success);
i.OperationReturnResult != ReturnResult.InProgress &&
i.OperationReturnResult != ReturnResult.Success);

var anyActiveOperation = StatusCenterItems.Any(i => i.IsInProgress && !i.IsPaused);
var anyPausedOperation = StatusCenterItems.Any(i => i.IsInProgress && i.IsPaused);
Expand Down Expand Up @@ -225,9 +232,21 @@ public void NotifyChanges()
public void UpdateAverageProgressValue()
{
if (HasAnyItemInProgress)
AverageOperationProgressValue = (int)StatusCenterItems.Where((item) => item.IsInProgress).Average(x => x.ProgressPercentage);
{
var determinateItems = StatusCenterItems
.Where(item => item.IsInProgress && !item.IsIndeterminateProgress)
.ToList();

IsOperationProgressIndeterminate = determinateItems.Count == 0;
AverageOperationProgressValue = determinateItems.Count > 0
? (int)determinateItems.Average(x => x.ProgressPercentage)
: 0;
}
else
{
IsOperationProgressIndeterminate = false;
AverageOperationProgressValue = 0;
}
}

private void UpdateTaskbarProgress()
Expand Down