Browse Source

Added progress to taskbar icon

pull/5/head
JT 1 year ago
parent
commit
d02f8b4a39
  1. 16
      StabilityMatrix/Helper/EventManager.cs
  2. 6
      StabilityMatrix/MainWindow.xaml
  3. 5
      StabilityMatrix/ViewModels/InstallerViewModel.cs
  4. 42
      StabilityMatrix/ViewModels/MainWindowViewModel.cs

16
StabilityMatrix/Helper/EventManager.cs

@ -0,0 +1,16 @@
using System;
namespace StabilityMatrix.Helper;
public class EventManager
{
public static EventManager Instance { get; } = new();
private EventManager()
{
}
public event EventHandler<int>? GlobalProgressChanged;
public void OnGlobalProgressChanged(int progress) => GlobalProgressChanged?.Invoke(this, progress);
}

6
StabilityMatrix/MainWindow.xaml

@ -19,6 +19,12 @@
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:viewModels="clr-namespace:StabilityMatrix.ViewModels"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ui:FluentWindow.TaskbarItemInfo>
<TaskbarItemInfo ProgressState="{Binding ProgressState}"
ProgressValue="{Binding ProgressValue}"/>
</ui:FluentWindow.TaskbarItemInfo>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />

5
StabilityMatrix/ViewModels/InstallerViewModel.cs

@ -9,6 +9,7 @@ using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.Logging;
using EventManager = StabilityMatrix.Helper.EventManager;
namespace StabilityMatrix.ViewModels;
@ -86,7 +87,7 @@ public partial class InstallerViewModel : ObservableObject
InstalledText = "Done";
IsIndeterminate = false;
ProgressValue = 100;
SelectedPackageOnProgressChanged(this, 100);
if (settingsManager.Settings.InstalledPackages.FirstOrDefault(x => x.PackageName == SelectedPackage.Name) ==
null)
@ -133,6 +134,8 @@ public partial class InstallerViewModel : ObservableObject
IsIndeterminate = false;
ProgressValue = progress;
}
EventManager.Instance.OnGlobalProgressChanged(progress);
}
private async Task<bool> InstallGitIfNecessary()

42
StabilityMatrix/ViewModels/MainWindowViewModel.cs

@ -1,8 +1,14 @@
using System.Windows;
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Shell;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Python.Runtime;
using StabilityMatrix.Helper;
using Wpf.Ui.Appearance;
using Dispatcher = System.Windows.Threading.Dispatcher;
using EventManager = StabilityMatrix.Helper.EventManager;
namespace StabilityMatrix.ViewModels;
@ -20,11 +26,45 @@ public partial class MainWindowViewModel : ObservableObject
[ObservableProperty]
private Visibility simpleModeVisibility;
[ObservableProperty]
private float progressValue;
[ObservableProperty]
private TaskbarItemProgressState progressState;
public void OnLoaded()
{
SetTheme();
GoAdvancedMode();
EventManager.Instance.GlobalProgressChanged += OnGlobalProgressChanged;
}
private void OnGlobalProgressChanged(object? sender, int progress)
{
if (progress == -1)
{
ProgressState = TaskbarItemProgressState.Indeterminate;
ProgressValue = 0;
}
else
{
ProgressState = TaskbarItemProgressState.Normal;
ProgressValue = progress / 100f;
}
if (Math.Abs(ProgressValue - 1) < 0.01f)
{
Task.Run(async () =>
{
await Task.Delay(5000);
Dispatcher.CurrentDispatcher.Invoke(() =>
{
ProgressState = TaskbarItemProgressState.None;
ProgressValue = 0;
});
});
}
}
[RelayCommand]

Loading…
Cancel
Save