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
1 change: 1 addition & 0 deletions src/Languages/lang_en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"{0} of {1} operations completed": "{0} of {1} operations completed",
"{0} is now {1}": "{0} is now {1}",
"Enabled": "Enabled",
"Disabled": "Disabled",
Expand Down
44 changes: 43 additions & 1 deletion src/UniGetUI.Avalonia/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using UniGetUI.PackageEngine.Enums;
using UniGetUI.PackageEngine.Interfaces;
using UniGetUI.PackageEngine.PackageLoader;
using UniGetUI.PackageOperations;

namespace UniGetUI.Avalonia.ViewModels;

Expand Down Expand Up @@ -67,6 +68,41 @@ public partial class MainWindowViewModel : ViewModelBase
[ObservableProperty]
private bool _operationsPanelExpanded = true;

private readonly List<AbstractOperation> _operationBatch = new();

public string OperationsHeaderText
{
get
{
int total = _operationBatch.Count;
if (total == 0)
return CoreTools.Translate("Operations");
int completed = _operationBatch.Count(o =>
o.Status is OperationStatus.Succeeded or OperationStatus.Failed or OperationStatus.Canceled);
return CoreTools.Translate("{0} of {1} operations completed", completed, total);
}
}

private void AddToBatch(AbstractOperation op)
{
if (_operationBatch.Count > 0
&& _operationBatch.All(o => o.Status is not (OperationStatus.InQueue or OperationStatus.Running)))
{
foreach (var old in _operationBatch)
old.StatusChanged -= OnOperationStatusChanged;
_operationBatch.Clear();
}

if (!_operationBatch.Contains(op))
{
_operationBatch.Add(op);
op.StatusChanged += OnOperationStatusChanged;
}
}

private void OnOperationStatusChanged(object? sender, OperationStatus e)
=> Dispatcher.UIThread.Post(() => OnPropertyChanged(nameof(OperationsHeaderText)));

[RelayCommand]
private void ToggleOperationsPanel() => OperationsPanelExpanded = !OperationsPanelExpanded;

Expand Down Expand Up @@ -221,8 +257,14 @@ public MainWindowViewModel()
AvaloniaAutoUpdater.CheckForOrphanedUpdateAttempt();

// Keep OperationsPanelVisible in sync with the live operations list
Operations.CollectionChanged += (_, _) =>
Operations.CollectionChanged += (_, e) =>
{
if (e.NewItems is not null)
foreach (OperationViewModel vm in e.NewItems)
AddToBatch(vm.Operation);
OperationsPanelVisible = Operations.Count > 0;
OnPropertyChanged(nameof(OperationsHeaderText));
};

if (OperatingSystem.IsWindows() && CoreTools.IsAdministrator() && !Settings.Get(Settings.K.AlreadyWarnedAboutAdmin))
{
Expand Down
2 changes: 1 addition & 1 deletion src/UniGetUI.Avalonia/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
</Button>

<TextBlock Grid.Column="1"
Text="{t:Translate Operations}"
Text="{Binding OperationsHeaderText}"
FontSize="11" Opacity="0.6"
VerticalAlignment="Center"
Margin="4,0,0,0"/>
Expand Down
10 changes: 10 additions & 0 deletions src/UniGetUI/Pages/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,16 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="15" />
</Grid.ColumnDefinitions>
<TextBlock
Name="OperationCountLabel"
Grid.Column="0"
Margin="4,0,0,0"
VerticalAlignment="Center"
FontSize="12"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
IsHitTestVisible="False"
TextTrimming="CharacterEllipsis"
/>
<HyperlinkButton
Name="ExpandCollapseOpList"
AutomationProperties.Name="Expand or collapse operation list"
Expand Down
40 changes: 39 additions & 1 deletion src/UniGetUI/Pages/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using UniGetUI.Controls;
using UniGetUI.Controls.OperationWidgets;
using UniGetUI.Core.Data;
using UniGetUI.Core.SettingsEngine;
using UniGetUI.Core.Tools;
Expand Down Expand Up @@ -185,8 +186,13 @@ public MainView(AutoSuggestBox mainTextBlock)
}

UpdateOperationsLayout();
MainApp.Operations._operationList.CollectionChanged += (_, _) =>
MainApp.Operations._operationList.CollectionChanged += (_, e) =>
{
if (e.NewItems is not null)
foreach (OperationControl c in e.NewItems)
AddToBatch(c.Operation);
UpdateOperationsLayout();
};

if (!Settings.Get(Settings.K.ShownTelemetryBanner))
{
Expand Down Expand Up @@ -478,6 +484,38 @@ private void UpdateOperationsLayout()
OperationSplitterMenuButton.Visibility = Visibility.Collapsed;
}
ResizingOPLayout = false;
UpdateOperationCount();
}

private readonly List<AbstractOperation> _operationBatch = new();

private void AddToBatch(AbstractOperation op)
{
if (_operationBatch.Count > 0
&& _operationBatch.All(o => o.Status is not (OperationStatus.InQueue or OperationStatus.Running)))
{
foreach (var old in _operationBatch)
old.StatusChanged -= OnAnyOperationStatusChanged;
_operationBatch.Clear();
}

if (!_operationBatch.Contains(op))
{
_operationBatch.Add(op);
op.StatusChanged += OnAnyOperationStatusChanged;
}
}

private void OnAnyOperationStatusChanged(object? sender, OperationStatus e)
=> DispatcherQueue.TryEnqueue(UpdateOperationCount);

private void UpdateOperationCount()
{
int total = _operationBatch.Count;
int completed = _operationBatch.Count(o =>
o.Status is OperationStatus.Succeeded or OperationStatus.Failed or OperationStatus.Canceled);
OperationCountLabel.Text =
total > 0 ? CoreTools.Translate("{0} of {1} operations completed", completed, total) : "";
}

private void OperationScrollView_SizeChanged(object sender, SizeChangedEventArgs e)
Expand Down
Loading