diff --git a/Wabbajack.App.Wpf/App.xaml.cs b/Wabbajack.App.Wpf/App.xaml.cs index cbb9de0d..b628982e 100644 --- a/Wabbajack.App.Wpf/App.xaml.cs +++ b/Wabbajack.App.Wpf/App.xaml.cs @@ -52,6 +52,7 @@ namespace Wabbajack services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/Wabbajack.App.Wpf/Interventions/InteventionHandler.cs b/Wabbajack.App.Wpf/Interventions/InteventionHandler.cs index 998beba3..49f05bb5 100644 --- a/Wabbajack.App.Wpf/Interventions/InteventionHandler.cs +++ b/Wabbajack.App.Wpf/Interventions/InteventionHandler.cs @@ -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(); - 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(); + provider.Intervention = bd; + MessageBus.Current.SendMessage(new SpawnBrowserWindow(provider)); break; + } default: _logger.LogError("No handler for user intervention: {Type}", intervention); break; + } + } } \ No newline at end of file diff --git a/Wabbajack.App.Wpf/Messages/SpawnBrowserWindow.cs b/Wabbajack.App.Wpf/Messages/SpawnBrowserWindow.cs new file mode 100644 index 00000000..840d5486 --- /dev/null +++ b/Wabbajack.App.Wpf/Messages/SpawnBrowserWindow.cs @@ -0,0 +1,5 @@ +namespace Wabbajack.Messages; + +public record SpawnBrowserWindow (BrowserWindowViewModel Vm) +{ +} \ No newline at end of file diff --git a/Wabbajack.App.Wpf/UserIntervention/ManualDownloadHandler.cs b/Wabbajack.App.Wpf/UserIntervention/ManualDownloadHandler.cs index 6fa4f3a3..8ed9e354 100644 --- a/Wabbajack.App.Wpf/UserIntervention/ManualDownloadHandler.cs +++ b/Wabbajack.App.Wpf/UserIntervention/ManualDownloadHandler.cs @@ -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; diff --git a/Wabbajack.App.Wpf/View Models/BrowserWindowViewModel.cs b/Wabbajack.App.Wpf/View Models/BrowserWindowViewModel.cs index 0cbe36db..5bfe7c64 100644 --- a/Wabbajack.App.Wpf/View Models/BrowserWindowViewModel.cs +++ b/Wabbajack.App.Wpf/View Models/BrowserWindowViewModel.cs @@ -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}")); + } } } diff --git a/Wabbajack.App.Wpf/View Models/MainWindowVM.cs b/Wabbajack.App.Wpf/View Models/MainWindowVM.cs index 33229848..8ab8f7e5 100644 --- a/Wabbajack.App.Wpf/View Models/MainWindowVM.cs +++ b/Wabbajack.App.Wpf/View Models/MainWindowVM.cs @@ -102,13 +102,9 @@ namespace Wabbajack .Subscribe(HandleNavigateBack) .DisposeWith(CompositeDisposable); - MessageBus.Current.Listen() - .Subscribe(HandleManualDownload) - .DisposeWith(CompositeDisposable); - - - MessageBus.Current.Listen() - .Subscribe(HandleManualBlobDownload) + MessageBus.Current.Listen() + .ObserveOnGuiThread() + .Subscribe(HandleSpawnBrowserWindow) .DisposeWith(CompositeDisposable); _resourceMonitor.Updates @@ -179,6 +175,13 @@ namespace Wabbajack handler.Intervention = manualDownload; //MessageBus.Current.SendMessage(new OpenBrowserTab(handler)); } + + private void HandleSpawnBrowserWindow(SpawnBrowserWindow msg) + { + var window = _serviceProvider.GetRequiredService(); + window.DataContext = msg.Vm; + window.Show(); + } private void HandleNavigateTo(NavigateToGlobal.ScreenType s) { diff --git a/Wabbajack.App.Wpf/Views/BrowserWindow.xaml b/Wabbajack.App.Wpf/Views/BrowserWindow.xaml index c26b21b1..ea3d5f5f 100644 --- a/Wabbajack.App.Wpf/Views/BrowserWindow.xaml +++ b/Wabbajack.App.Wpf/Views/BrowserWindow.xaml @@ -20,7 +20,7 @@ TitleBarHeight="25" UseLayoutRounding="True" WindowTitleBrush="{StaticResource MahApps.Brushes.Accent}" - Activated="BrowserWindow_OnActivated" + ContentRendered="BrowserWindow_OnActivated" mc:Ignorable="d"> @@ -43,7 +43,7 @@ - + diff --git a/Wabbajack.Downloaders.Nexus/NexusDownloader.cs b/Wabbajack.Downloaders.Nexus/NexusDownloader.cs index 4899c8b1..37d460dd 100644 --- a/Wabbajack.Downloaders.Nexus/NexusDownloader.cs +++ b/Wabbajack.Downloaders.Nexus/NexusDownloader.cs @@ -117,7 +117,6 @@ public class NexusDownloader : ADownloader, 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, 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(); diff --git a/Wabbajack.Services.OSIntegrated/ServiceExtensions.cs b/Wabbajack.Services.OSIntegrated/ServiceExtensions.cs index 836f6ca9..00130379 100644 --- a/Wabbajack.Services.OSIntegrated/ServiceExtensions.cs +++ b/Wabbajack.Services.OSIntegrated/ServiceExtensions.cs @@ -102,7 +102,7 @@ public static class ServiceExtensions new Resource("Installer", GetSettings(s, "Installer"))); service.AddAllSingleton>(s => - new Resource("User Intervention", 3)); + new Resource("User Intervention", 1)); service.AddSingleton();