mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
ProgressBar IObservable. Basic Modal. No longer download list if exists.
.Sample() is what .Throttle() sounds like it does. ProgressBar will be changed again, this implementation feels dirty.
This commit is contained in:
parent
699252f05e
commit
d1e64e910c
@ -1,18 +1,34 @@
|
||||
@using Wabbajack.RateLimiter
|
||||
@using System
|
||||
@using System.Reactive.Linq
|
||||
|
||||
@namespace Wabbajack.App.Blazor.Components
|
||||
|
||||
<div id="progress-bar">
|
||||
<progress value="@Percentage.Value"></progress>
|
||||
<progress value="@CurrentProgress"></progress>
|
||||
<span class="text">@Text</span>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public Percent Percentage { get; set; }
|
||||
private double CurrentProgress { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string Text { get; set; }
|
||||
[Parameter] public IObservable<Percent> ProgressObserver { get; set; }
|
||||
|
||||
[Parameter] public string Text { get; set; }
|
||||
|
||||
protected override Task OnInitializedAsync()
|
||||
{
|
||||
var textPercentage = string.IsNullOrEmpty(Text);
|
||||
ProgressObserver
|
||||
.Sample(TimeSpan.FromMilliseconds(250))
|
||||
.DistinctUntilChanged()
|
||||
.Subscribe(p => {
|
||||
CurrentProgress = p.Value;
|
||||
if (textPercentage) Text = p.ToString();
|
||||
InvokeAsync(StateHasChanged);
|
||||
});
|
||||
|
||||
return base.OnInitializedAsync();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
@page "/gallery"
|
||||
|
||||
@using System.Globalization
|
||||
|
||||
@namespace Wabbajack.App.Blazor.Pages
|
||||
|
||||
<div id="content">
|
||||
@ -39,7 +37,7 @@
|
||||
{
|
||||
<BottomBar Image="@DownloadingMetaData.Links.ImageUri" Title="Downloading..." Subtitle="@DownloadingMetaData.Title">
|
||||
<div style="height:1.5rem;">
|
||||
<ProgressBar Percentage="@DownloadProgress" Text="@DownloadProgress.Value.ToString(CultureInfo.InvariantCulture)"/>
|
||||
<ProgressBar ProgressObserver="@DownloadProgress"/>
|
||||
</div>
|
||||
</BottomBar>
|
||||
}
|
||||
|
@ -4,12 +4,13 @@ using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Shell;
|
||||
using Blazored.Modal;
|
||||
using Blazored.Modal.Services;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Wabbajack.App.Blazor.Components;
|
||||
using Wabbajack.App.Blazor.State;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.DTOs;
|
||||
using Wabbajack.Paths.IO;
|
||||
using Wabbajack.RateLimiter;
|
||||
using Wabbajack.Services.OSIntegrated.Services;
|
||||
|
||||
@ -22,13 +23,14 @@ public partial class Gallery
|
||||
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
|
||||
[Inject] private ModListDownloadMaintainer Maintainer { get; set; } = default!;
|
||||
|
||||
private Percent DownloadProgress { get; set; } = Percent.Zero;
|
||||
[CascadingParameter] public IModalService Modal { get; set; }
|
||||
private IObservable<Percent> DownloadProgress { get; set; }
|
||||
private ModlistMetadata? DownloadingMetaData { get; set; }
|
||||
|
||||
private IEnumerable<ModlistMetadata> Modlists => StateContainer.Modlists;
|
||||
|
||||
private bool _errorLoadingModlists;
|
||||
|
||||
|
||||
private bool _shouldRender;
|
||||
protected override bool ShouldRender() => _shouldRender;
|
||||
|
||||
@ -44,19 +46,24 @@ public partial class Gallery
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_shouldRender = true;
|
||||
}
|
||||
|
||||
private async Task OnClickDownload(ModlistMetadata metadata)
|
||||
{
|
||||
// GlobalState.NavigationAllowed = !GlobalState.NavigationAllowed;
|
||||
await Download(metadata);
|
||||
if (!await Maintainer.HaveModList(metadata)) await Download(metadata);
|
||||
StateContainer.ModlistPath = Maintainer.ModListPath(metadata);
|
||||
StateContainer.Modlist = null;
|
||||
NavigationManager.NavigateTo(Configure.Route);
|
||||
}
|
||||
|
||||
private async Task OnClickInformation(ModlistMetadata metadata)
|
||||
{
|
||||
// TODO: [High] Implement information modal.
|
||||
var parameters = new ModalParameters();
|
||||
parameters.Add(nameof(InfoModal.Content), metadata.Description);
|
||||
Modal.Show<InfoModal>("Information", parameters);
|
||||
}
|
||||
|
||||
private async Task Download(ModlistMetadata metadata)
|
||||
@ -64,35 +71,25 @@ public partial class Gallery
|
||||
StateContainer.NavigationAllowed = false;
|
||||
DownloadingMetaData = metadata;
|
||||
|
||||
// TODO: download progress should be in ProgressBar component so it can refresh independently
|
||||
|
||||
try
|
||||
{
|
||||
var (progress, task) = Maintainer.DownloadModlist(metadata);
|
||||
|
||||
var dispose = progress
|
||||
.DistinctUntilChanged(p => p.Value)
|
||||
.Throttle(TimeSpan.FromMilliseconds(100))
|
||||
.Subscribe(p =>
|
||||
{
|
||||
DownloadProgress = p;
|
||||
StateContainer.TaskBarState = new TaskBarState
|
||||
{
|
||||
Description = $"Downloading {metadata.Title}",
|
||||
State = TaskbarItemProgressState.Indeterminate,
|
||||
ProgressValue = p.Value
|
||||
};
|
||||
|
||||
InvokeAsync(StateHasChanged);
|
||||
// Dispatcher.CreateDefault().InvokeAsync(StateHasChanged);
|
||||
}, () => { StateContainer.TaskBarState = new TaskBarState(); });
|
||||
DownloadProgress = progress;
|
||||
|
||||
var dispose = progress
|
||||
.Sample(TimeSpan.FromMilliseconds(250))
|
||||
.Subscribe(p => {
|
||||
StateContainer.TaskBarState = new TaskBarState
|
||||
{
|
||||
Description = $"Downloading {metadata.Title}",
|
||||
State = TaskbarItemProgressState.Normal,
|
||||
ProgressValue = p.Value
|
||||
};
|
||||
}, () => { StateContainer.TaskBarState = new TaskBarState(); });
|
||||
|
||||
await task;
|
||||
dispose.Dispose();
|
||||
|
||||
var path = KnownFolders.EntryPoint.Combine("downloaded_mod_lists", metadata.Links.MachineURL).WithExtension(Ext.Wabbajack);
|
||||
StateContainer.ModlistPath = path;
|
||||
NavigationManager.NavigateTo(Configure.Route);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user