mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
More work on manual downloader
This commit is contained in:
parent
5948af4c0d
commit
934cdd18ce
@ -52,6 +52,7 @@ namespace Wabbajack
|
||||
|
||||
services.AddTransient<MainWindow>();
|
||||
services.AddTransient<MainWindowVM>();
|
||||
services.AddTransient<BrowserWindow>();
|
||||
services.AddSingleton<SystemParametersConstructor>();
|
||||
services.AddSingleton<LauncherUpdater>();
|
||||
services.AddSingleton<ResourceMonitor>();
|
||||
|
@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Windows.Threading;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ReactiveUI;
|
||||
using Wabbajack.DTOs.Interventions;
|
||||
using Wabbajack.Messages;
|
||||
using Wabbajack.UserIntervention;
|
||||
|
||||
namespace Wabbajack.Interventions;
|
||||
@ -23,18 +26,24 @@ public class UserInteventionHandler : IUserInterventionHandler
|
||||
{
|
||||
// Recast these or they won't be properly handled by the message bus
|
||||
case ManualDownload md:
|
||||
var view = new BrowserWindow();
|
||||
{
|
||||
var provider = _serviceProvider.GetRequiredService<ManualDownloadHandler>();
|
||||
view.DataContext = provider;
|
||||
provider.Intervention = md;
|
||||
view.Show();
|
||||
MessageBus.Current.SendMessage(new SpawnBrowserWindow(provider));
|
||||
break;
|
||||
}
|
||||
case ManualBlobDownload bd:
|
||||
MessageBus.Current.SendMessage(bd);
|
||||
{
|
||||
var provider = _serviceProvider.GetRequiredService<ManualBlobDownloadHandler>();
|
||||
provider.Intervention = bd;
|
||||
MessageBus.Current.SendMessage(new SpawnBrowserWindow(provider));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
_logger.LogError("No handler for user intervention: {Type}", intervention);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
5
Wabbajack.App.Wpf/Messages/SpawnBrowserWindow.cs
Normal file
5
Wabbajack.App.Wpf/Messages/SpawnBrowserWindow.cs
Normal file
@ -0,0 +1,5 @@
|
||||
namespace Wabbajack.Messages;
|
||||
|
||||
public record SpawnBrowserWindow (BrowserWindowViewModel Vm)
|
||||
{
|
||||
}
|
@ -14,7 +14,7 @@ public class ManualDownloadHandler : BrowserWindowViewModel
|
||||
|
||||
protected override async Task Run(CancellationToken token)
|
||||
{
|
||||
await WaitForReady();
|
||||
//await WaitForReady();
|
||||
var archive = Intervention.Archive;
|
||||
var md = Intervention.Archive.State as Manual;
|
||||
|
||||
|
@ -56,7 +56,14 @@ public abstract class BrowserWindowViewModel : ViewModel
|
||||
}
|
||||
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}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,13 +102,9 @@ namespace Wabbajack
|
||||
.Subscribe(HandleNavigateBack)
|
||||
.DisposeWith(CompositeDisposable);
|
||||
|
||||
MessageBus.Current.Listen<ManualDownload>()
|
||||
.Subscribe(HandleManualDownload)
|
||||
.DisposeWith(CompositeDisposable);
|
||||
|
||||
|
||||
MessageBus.Current.Listen<ManualBlobDownload>()
|
||||
.Subscribe(HandleManualBlobDownload)
|
||||
MessageBus.Current.Listen<SpawnBrowserWindow>()
|
||||
.ObserveOnGuiThread()
|
||||
.Subscribe(HandleSpawnBrowserWindow)
|
||||
.DisposeWith(CompositeDisposable);
|
||||
|
||||
_resourceMonitor.Updates
|
||||
@ -180,6 +176,13 @@ namespace Wabbajack
|
||||
//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)
|
||||
{
|
||||
if (s is NavigateToGlobal.ScreenType.Settings)
|
||||
|
@ -20,7 +20,7 @@
|
||||
TitleBarHeight="25"
|
||||
UseLayoutRounding="True"
|
||||
WindowTitleBrush="{StaticResource MahApps.Brushes.Accent}"
|
||||
Activated="BrowserWindow_OnActivated"
|
||||
ContentRendered="BrowserWindow_OnActivated"
|
||||
mc:Ignorable="d">
|
||||
<Grid Background="#121212" MouseDown="UIElement_OnMouseDown">
|
||||
<Grid.RowDefinitions>
|
||||
@ -43,7 +43,7 @@
|
||||
</Button>
|
||||
<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>
|
||||
</mahapps:MetroWindow>
|
||||
|
@ -117,7 +117,6 @@ public class NexusDownloader : ADownloader<Nexus>, IUrlDownloader
|
||||
{
|
||||
if (IsManualDebugMode || await _api.IsPremium(token))
|
||||
{
|
||||
using var _ = await _interventionLimiter.Begin("Downloading file manually", 1, token);
|
||||
return await DownloadManually(archive, state, destination, job, token);
|
||||
}
|
||||
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}")
|
||||
}
|
||||
});
|
||||
_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();
|
||||
|
||||
|
@ -102,7 +102,7 @@ public static class ServiceExtensions
|
||||
new Resource<IInstaller>("Installer", GetSettings(s, "Installer")));
|
||||
|
||||
service.AddAllSingleton<IResource, IResource<IUserInterventionHandler>>(s =>
|
||||
new Resource<IUserInterventionHandler>("User Intervention", 3));
|
||||
new Resource<IUserInterventionHandler>("User Intervention", 1));
|
||||
|
||||
service.AddSingleton<LoggingRateLimiterReporter>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user