Fix manual downloads sometimes launching in browser

This commit is contained in:
UrbanCMC 2023-08-09 21:03:56 +02:00
parent 77f6b8c9cb
commit ae7402be58
2 changed files with 9 additions and 10 deletions

View File

@ -1,10 +1,7 @@
using System.Security.Policy;
using System.Threading;
using System.Threading.Tasks;
using Wabbajack.DTOs;
using Wabbajack.DTOs.DownloadStates;
using Wabbajack.DTOs.Interventions;
using Wabbajack.Paths;
namespace Wabbajack.UserIntervention;
@ -21,13 +18,13 @@ public class ManualDownloadHandler : BrowserWindowViewModel
HeaderText = $"Manual download ({md.Url.Host})";
Instructions = string.IsNullOrWhiteSpace(md.Prompt) ? $"Please download {archive.Name}" : md.Prompt;
await NavigateTo(md.Url);
var uri = await WaitForDownloadUri(token, async () =>
var task = WaitForDownloadUri(token, async () =>
{
await RunJavaScript("Array.from(document.getElementsByTagName(\"iframe\")).forEach(f => f.remove())");
});
await NavigateTo(md.Url);
var uri = await task;
Intervention.Finish(uri);
}

View File

@ -112,11 +112,13 @@ public abstract class BrowserWindowViewModel : ViewModel
{
var source = new TaskCompletionSource<Uri>();
var referer = _browser.Source;
while (_browser.CoreWebView2 == null)
await Task.Delay(10, token);
_browser.CoreWebView2.DownloadStarting += (sender, args) =>
{
try
{
source.SetResult(new Uri(args.DownloadOperation.Uri));
}
catch (Exception)