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 Wabbajack.RateLimiter
|
||||||
|
@using System
|
||||||
|
@using System.Reactive.Linq
|
||||||
|
|
||||||
@namespace Wabbajack.App.Blazor.Components
|
@namespace Wabbajack.App.Blazor.Components
|
||||||
|
|
||||||
<div id="progress-bar">
|
<div id="progress-bar">
|
||||||
<progress value="@Percentage.Value"></progress>
|
<progress value="@CurrentProgress"></progress>
|
||||||
<span class="text">@Text</span>
|
<span class="text">@Text</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
|
||||||
[Parameter]
|
private double CurrentProgress { get; set; }
|
||||||
public Percent Percentage { get; set; }
|
|
||||||
|
|
||||||
[Parameter]
|
[Parameter] public IObservable<Percent> ProgressObserver { get; set; }
|
||||||
public string Text { 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"
|
@page "/gallery"
|
||||||
|
|
||||||
@using System.Globalization
|
|
||||||
|
|
||||||
@namespace Wabbajack.App.Blazor.Pages
|
@namespace Wabbajack.App.Blazor.Pages
|
||||||
|
|
||||||
<div id="content">
|
<div id="content">
|
||||||
@ -39,7 +37,7 @@
|
|||||||
{
|
{
|
||||||
<BottomBar Image="@DownloadingMetaData.Links.ImageUri" Title="Downloading..." Subtitle="@DownloadingMetaData.Title">
|
<BottomBar Image="@DownloadingMetaData.Links.ImageUri" Title="Downloading..." Subtitle="@DownloadingMetaData.Title">
|
||||||
<div style="height:1.5rem;">
|
<div style="height:1.5rem;">
|
||||||
<ProgressBar Percentage="@DownloadProgress" Text="@DownloadProgress.Value.ToString(CultureInfo.InvariantCulture)"/>
|
<ProgressBar ProgressObserver="@DownloadProgress"/>
|
||||||
</div>
|
</div>
|
||||||
</BottomBar>
|
</BottomBar>
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,13 @@ using System.Linq;
|
|||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Shell;
|
using System.Windows.Shell;
|
||||||
|
using Blazored.Modal;
|
||||||
|
using Blazored.Modal.Services;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Wabbajack.App.Blazor.Components;
|
||||||
using Wabbajack.App.Blazor.State;
|
using Wabbajack.App.Blazor.State;
|
||||||
using Wabbajack.Common;
|
|
||||||
using Wabbajack.DTOs;
|
using Wabbajack.DTOs;
|
||||||
using Wabbajack.Paths.IO;
|
|
||||||
using Wabbajack.RateLimiter;
|
using Wabbajack.RateLimiter;
|
||||||
using Wabbajack.Services.OSIntegrated.Services;
|
using Wabbajack.Services.OSIntegrated.Services;
|
||||||
|
|
||||||
@ -22,7 +23,8 @@ public partial class Gallery
|
|||||||
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
|
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
|
||||||
[Inject] private ModListDownloadMaintainer Maintainer { 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 ModlistMetadata? DownloadingMetaData { get; set; }
|
||||||
|
|
||||||
private IEnumerable<ModlistMetadata> Modlists => StateContainer.Modlists;
|
private IEnumerable<ModlistMetadata> Modlists => StateContainer.Modlists;
|
||||||
@ -50,13 +52,18 @@ public partial class Gallery
|
|||||||
|
|
||||||
private async Task OnClickDownload(ModlistMetadata metadata)
|
private async Task OnClickDownload(ModlistMetadata metadata)
|
||||||
{
|
{
|
||||||
// GlobalState.NavigationAllowed = !GlobalState.NavigationAllowed;
|
if (!await Maintainer.HaveModList(metadata)) await Download(metadata);
|
||||||
await Download(metadata);
|
StateContainer.ModlistPath = Maintainer.ModListPath(metadata);
|
||||||
|
StateContainer.Modlist = null;
|
||||||
|
NavigationManager.NavigateTo(Configure.Route);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnClickInformation(ModlistMetadata metadata)
|
private async Task OnClickInformation(ModlistMetadata metadata)
|
||||||
{
|
{
|
||||||
// TODO: [High] Implement information modal.
|
// 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)
|
private async Task Download(ModlistMetadata metadata)
|
||||||
@ -64,35 +71,25 @@ public partial class Gallery
|
|||||||
StateContainer.NavigationAllowed = false;
|
StateContainer.NavigationAllowed = false;
|
||||||
DownloadingMetaData = metadata;
|
DownloadingMetaData = metadata;
|
||||||
|
|
||||||
// TODO: download progress should be in ProgressBar component so it can refresh independently
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var (progress, task) = Maintainer.DownloadModlist(metadata);
|
var (progress, task) = Maintainer.DownloadModlist(metadata);
|
||||||
|
|
||||||
|
DownloadProgress = progress;
|
||||||
|
|
||||||
var dispose = progress
|
var dispose = progress
|
||||||
.DistinctUntilChanged(p => p.Value)
|
.Sample(TimeSpan.FromMilliseconds(250))
|
||||||
.Throttle(TimeSpan.FromMilliseconds(100))
|
.Subscribe(p => {
|
||||||
.Subscribe(p =>
|
|
||||||
{
|
|
||||||
DownloadProgress = p;
|
|
||||||
StateContainer.TaskBarState = new TaskBarState
|
StateContainer.TaskBarState = new TaskBarState
|
||||||
{
|
{
|
||||||
Description = $"Downloading {metadata.Title}",
|
Description = $"Downloading {metadata.Title}",
|
||||||
State = TaskbarItemProgressState.Indeterminate,
|
State = TaskbarItemProgressState.Normal,
|
||||||
ProgressValue = p.Value
|
ProgressValue = p.Value
|
||||||
};
|
};
|
||||||
|
|
||||||
InvokeAsync(StateHasChanged);
|
|
||||||
// Dispatcher.CreateDefault().InvokeAsync(StateHasChanged);
|
|
||||||
}, () => { StateContainer.TaskBarState = new TaskBarState(); });
|
}, () => { StateContainer.TaskBarState = new TaskBarState(); });
|
||||||
|
|
||||||
await task;
|
await task;
|
||||||
dispose.Dispose();
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user