More work on manual downloader

This commit is contained in:
Timothy Baldridge 2022-05-19 22:12:16 -06:00
parent 5948af4c0d
commit 934cdd18ce
9 changed files with 49 additions and 19 deletions

View File

@ -52,6 +52,7 @@ namespace Wabbajack
services.AddTransient<MainWindow>(); services.AddTransient<MainWindow>();
services.AddTransient<MainWindowVM>(); services.AddTransient<MainWindowVM>();
services.AddTransient<BrowserWindow>();
services.AddSingleton<SystemParametersConstructor>(); services.AddSingleton<SystemParametersConstructor>();
services.AddSingleton<LauncherUpdater>(); services.AddSingleton<LauncherUpdater>();
services.AddSingleton<ResourceMonitor>(); services.AddSingleton<ResourceMonitor>();

View File

@ -1,8 +1,11 @@
using System; using System;
using System.Reactive.Disposables;
using System.Windows.Threading;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ReactiveUI; using ReactiveUI;
using Wabbajack.DTOs.Interventions; using Wabbajack.DTOs.Interventions;
using Wabbajack.Messages;
using Wabbajack.UserIntervention; using Wabbajack.UserIntervention;
namespace Wabbajack.Interventions; namespace Wabbajack.Interventions;
@ -23,18 +26,24 @@ public class UserInteventionHandler : IUserInterventionHandler
{ {
// Recast these or they won't be properly handled by the message bus // Recast these or they won't be properly handled by the message bus
case ManualDownload md: case ManualDownload md:
var view = new BrowserWindow(); {
var provider = _serviceProvider.GetRequiredService<ManualDownloadHandler>(); var provider = _serviceProvider.GetRequiredService<ManualDownloadHandler>();
view.DataContext = provider;
provider.Intervention = md; provider.Intervention = md;
view.Show(); MessageBus.Current.SendMessage(new SpawnBrowserWindow(provider));
break; break;
}
case ManualBlobDownload bd: case ManualBlobDownload bd:
MessageBus.Current.SendMessage(bd); {
var provider = _serviceProvider.GetRequiredService<ManualBlobDownloadHandler>();
provider.Intervention = bd;
MessageBus.Current.SendMessage(new SpawnBrowserWindow(provider));
break; break;
}
default: default:
_logger.LogError("No handler for user intervention: {Type}", intervention); _logger.LogError("No handler for user intervention: {Type}", intervention);
break; break;
} }
} }
} }

View File

@ -0,0 +1,5 @@
namespace Wabbajack.Messages;
public record SpawnBrowserWindow (BrowserWindowViewModel Vm)
{
}

View File

@ -14,7 +14,7 @@ public class ManualDownloadHandler : BrowserWindowViewModel
protected override async Task Run(CancellationToken token) protected override async Task Run(CancellationToken token)
{ {
await WaitForReady(); //await WaitForReady();
var archive = Intervention.Archive; var archive = Intervention.Archive;
var md = Intervention.Archive.State as Manual; var md = Intervention.Archive.State as Manual;

View File

@ -56,7 +56,14 @@ public abstract class BrowserWindowViewModel : ViewModel
} }
else else
{ {
tcs.TrySetException(new Exception($"Navigation error to {uri}")); if (a.WebErrorStatus == CoreWebView2WebErrorStatus.ConnectionAborted)
{
tcs.TrySetResult();
}
else
{
tcs.TrySetException(new Exception($"Navigation error to {uri} - {a.WebErrorStatus}"));
}
} }
} }

View File

@ -102,13 +102,9 @@ namespace Wabbajack
.Subscribe(HandleNavigateBack) .Subscribe(HandleNavigateBack)
.DisposeWith(CompositeDisposable); .DisposeWith(CompositeDisposable);
MessageBus.Current.Listen<ManualDownload>() MessageBus.Current.Listen<SpawnBrowserWindow>()
.Subscribe(HandleManualDownload) .ObserveOnGuiThread()
.DisposeWith(CompositeDisposable); .Subscribe(HandleSpawnBrowserWindow)
MessageBus.Current.Listen<ManualBlobDownload>()
.Subscribe(HandleManualBlobDownload)
.DisposeWith(CompositeDisposable); .DisposeWith(CompositeDisposable);
_resourceMonitor.Updates _resourceMonitor.Updates
@ -179,6 +175,13 @@ namespace Wabbajack
handler.Intervention = manualDownload; handler.Intervention = manualDownload;
//MessageBus.Current.SendMessage(new OpenBrowserTab(handler)); //MessageBus.Current.SendMessage(new OpenBrowserTab(handler));
} }
private void HandleSpawnBrowserWindow(SpawnBrowserWindow msg)
{
var window = _serviceProvider.GetRequiredService<BrowserWindow>();
window.DataContext = msg.Vm;
window.Show();
}
private void HandleNavigateTo(NavigateToGlobal.ScreenType s) private void HandleNavigateTo(NavigateToGlobal.ScreenType s)
{ {

View File

@ -20,7 +20,7 @@
TitleBarHeight="25" TitleBarHeight="25"
UseLayoutRounding="True" UseLayoutRounding="True"
WindowTitleBrush="{StaticResource MahApps.Brushes.Accent}" WindowTitleBrush="{StaticResource MahApps.Brushes.Accent}"
Activated="BrowserWindow_OnActivated" ContentRendered="BrowserWindow_OnActivated"
mc:Ignorable="d"> mc:Ignorable="d">
<Grid Background="#121212" MouseDown="UIElement_OnMouseDown"> <Grid Background="#121212" MouseDown="UIElement_OnMouseDown">
<Grid.RowDefinitions> <Grid.RowDefinitions>
@ -43,7 +43,7 @@
</Button> </Button>
<TextBox Grid.Row="1" Grid.Column="3" VerticalContentAlignment="Center"></TextBox> <TextBox Grid.Row="1" Grid.Column="3" VerticalContentAlignment="Center"></TextBox>
<wpf:WebView2 Grid.Row="2" Grid.ColumnSpan="3" Name="Browser" Source="https://www.wabbajack.org"></wpf:WebView2> <wpf:WebView2 Grid.Row="2" Grid.ColumnSpan="3" Name="Browser"></wpf:WebView2>
</Grid> </Grid>
</mahapps:MetroWindow> </mahapps:MetroWindow>

View File

@ -117,7 +117,6 @@ public class NexusDownloader : ADownloader<Nexus>, IUrlDownloader
{ {
if (IsManualDebugMode || await _api.IsPremium(token)) if (IsManualDebugMode || await _api.IsPremium(token))
{ {
using var _ = await _interventionLimiter.Begin("Downloading file manually", 1, token);
return await DownloadManually(archive, state, destination, job, token); return await DownloadManually(archive, state, destination, job, token);
} }
else else
@ -156,8 +155,14 @@ public class NexusDownloader : ADownloader<Nexus>, IUrlDownloader
Url = new Uri($"https://www.nexusmods.com/{state.Game.MetaData().NexusName}/mods/{state.ModID}?tab=files&file_id={state.FileID}") Url = new Uri($"https://www.nexusmods.com/{state.Game.MetaData().NexusName}/mods/{state.ModID}?tab=files&file_id={state.FileID}")
} }
}); });
_userInterventionHandler.Raise(md);
var browserState = await md.Task; ManualDownload.BrowserDownloadState browserState;
using (var _ = await _interventionLimiter.Begin("Downloading file manually", 1, token))
{
_userInterventionHandler.Raise(md);
browserState = await md.Task;
}
var msg = browserState.ToHttpRequestMessage(); var msg = browserState.ToHttpRequestMessage();

View File

@ -102,7 +102,7 @@ public static class ServiceExtensions
new Resource<IInstaller>("Installer", GetSettings(s, "Installer"))); new Resource<IInstaller>("Installer", GetSettings(s, "Installer")));
service.AddAllSingleton<IResource, IResource<IUserInterventionHandler>>(s => service.AddAllSingleton<IResource, IResource<IUserInterventionHandler>>(s =>
new Resource<IUserInterventionHandler>("User Intervention", 3)); new Resource<IUserInterventionHandler>("User Intervention", 1));
service.AddSingleton<LoggingRateLimiterReporter>(); service.AddSingleton<LoggingRateLimiterReporter>();