mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
fix #880
This commit is contained in:
@@ -10,6 +10,7 @@ using Snap.Hutao.Service.Notification;
|
||||
using Snap.Hutao.Service.User;
|
||||
using Snap.Hutao.ViewModel.User;
|
||||
using Snap.Hutao.Web.Bridge;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Snap.Hutao.View.Control;
|
||||
|
||||
@@ -22,7 +23,6 @@ internal partial class WebViewer : UserControl, IRecipient<UserChangedMessage>
|
||||
|
||||
[SuppressMessage("", "IDE0052")]
|
||||
private MiHoYoJSInterface? jsInterface;
|
||||
private bool isFirstNavigate = true;
|
||||
|
||||
public WebViewer()
|
||||
{
|
||||
@@ -90,13 +90,12 @@ internal partial class WebViewer : UserControl, IRecipient<UserChangedMessage>
|
||||
|
||||
coreWebView2.SetCookie(user.CookieToken, user.LToken, user.SToken).SetMobileUserAgent();
|
||||
jsInterface = serviceProvider.CreateInstance<MiHoYoJSInterface>(coreWebView2, userAndUid);
|
||||
if (!isFirstNavigate)
|
||||
{
|
||||
coreWebView2.Reload();
|
||||
}
|
||||
|
||||
coreWebView2.Navigate(source);
|
||||
isFirstNavigate = false;
|
||||
CoreWebView2Navigator navigator = new(coreWebView2);
|
||||
await navigator.NavigateAsync("about:blank");
|
||||
Debug.WriteLine($"Before {source}");
|
||||
await navigator.NavigateAsync(source);
|
||||
Debug.WriteLine($"After {WebView.Source}");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using Windows.Foundation;
|
||||
|
||||
namespace Snap.Hutao.Web.Bridge;
|
||||
|
||||
internal sealed class CoreWebView2Navigator
|
||||
{
|
||||
private readonly TypedEventHandler<CoreWebView2, CoreWebView2NavigationCompletedEventArgs> coreWebView2NavigationCompletedEventHandler;
|
||||
private readonly CoreWebView2 coreWebView2;
|
||||
private TaskCompletionSource navigationTask = new();
|
||||
|
||||
public CoreWebView2Navigator(CoreWebView2 coreWebView2)
|
||||
{
|
||||
coreWebView2NavigationCompletedEventHandler = OnWebviewNavigationCompleted;
|
||||
this.coreWebView2 = coreWebView2;
|
||||
}
|
||||
|
||||
public async ValueTask NavigateAsync(string url)
|
||||
{
|
||||
coreWebView2.NavigationCompleted += coreWebView2NavigationCompletedEventHandler;
|
||||
coreWebView2.Navigate(url);
|
||||
await navigationTask.Task.ConfigureAwait(false);
|
||||
coreWebView2.NavigationCompleted -= coreWebView2NavigationCompletedEventHandler;
|
||||
}
|
||||
|
||||
private void OnWebviewNavigationCompleted(CoreWebView2 webView2, CoreWebView2NavigationCompletedEventArgs args)
|
||||
{
|
||||
navigationTask.TrySetResult();
|
||||
navigationTask = new();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user