Add task bar status

This commit is contained in:
Timothy Baldridge 2022-01-20 21:57:59 -07:00
parent 87e0a59371
commit 8782aeca94
5 changed files with 51 additions and 2 deletions

View File

@ -14,4 +14,7 @@
</blazor:BlazorWebView.RootComponents>
</blazor:BlazorWebView>
</Grid>
<Window.TaskbarItemInfo>
<TaskbarItemInfo x:Name="TaskBarItem"/>
</Window.TaskbarItemInfo>
</Window>

View File

@ -1,6 +1,7 @@
using System;
using Microsoft.Extensions.Logging;
using Wabbajack.App.Blazor.Models;
using Wabbajack.App.Blazor.State;
using Wabbajack.App.Blazor.Utility;
using Wabbajack.Common;
using Wabbajack.Installer;
@ -13,13 +14,25 @@ public partial class MainWindow
private readonly ILogger<MainWindow> _logger;
private readonly LoggerProvider _loggerProvider;
private readonly SystemParametersConstructor _systemParams;
private readonly GlobalState _globalState;
public MainWindow(ILogger<MainWindow> logger, IServiceProvider serviceProvider, LoggerProvider loggerProvider,
SystemParametersConstructor systemParams)
SystemParametersConstructor systemParams, GlobalState globalState)
{
_logger = logger;
_loggerProvider = loggerProvider;
_systemParams = systemParams;
_globalState = globalState;
_globalState.OnTaskBarStateChange += state =>
{
Dispatcher.InvokeAsync(() =>
{
TaskBarItem.Description = state.Description;
TaskBarItem.ProgressState = state.State;
TaskBarItem.ProgressValue = state.ProgressValue;
});
};
InitializeComponent();
BlazorWebView.Services = serviceProvider;

View File

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Shell;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Logging;
using Wabbajack.App.Blazor.State;
@ -68,11 +69,20 @@ public partial class Gallery
try
{
(IObservable<Percent> progress, Task task) = _maintainer.DownloadModlist(metadata);
IDisposable dispose = progress.Subscribe(p => DownloadProgress = p);
GlobalState.SetTaskBarState(TaskbarItemProgressState.Indeterminate,$"Downloading {metadata.Title}");
var dispose = progress.Subscribe(p =>
{
DownloadProgress = p;
GlobalState.SetTaskBarState(TaskbarItemProgressState.Indeterminate,$"Downloading {metadata.Title}", p.Value);
});
await task;
//await _wjClient.SendMetric("downloading", Metadata.Title);
dispose.Dispose();
GlobalState.SetTaskBarState();
AbsolutePath path = KnownFolders.EntryPoint.Combine("downloaded_mod_lists", metadata.Links.MachineURL).WithExtension(Ext.Wabbajack);
GlobalState.ModListPath = path;

View File

@ -1,4 +1,5 @@
using System;
using System.Windows.Shell;
using Wabbajack.DTOs;
using Wabbajack.Paths;
@ -34,6 +35,18 @@ public class GlobalState
public event Action OnModListChange;
public event Action OnInstallStateChange;
public event Action<TaskBarState> OnTaskBarStateChange;
public void SetTaskBarState(TaskbarItemProgressState state = TaskbarItemProgressState.None, string description="", double progress = 0)
{
OnTaskBarStateChange?.Invoke(new TaskBarState
{
State = state,
ProgressValue = progress,
Description = description
});
}
public AbsolutePath ModListPath
{
get => _modListPath;

View File

@ -0,0 +1,10 @@
using System.Windows.Shell;
namespace Wabbajack.App.Blazor.State;
public class TaskBarState
{
public string Description { get; set; }
public double ProgressValue { get; set; }
public TaskbarItemProgressState State { get; set; }
}