mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
fix jsbridge
This commit is contained in:
@@ -404,20 +404,12 @@ internal class MiHoYoJSBridge
|
||||
logger?.LogInformation("[{Id}][ExecuteScript: {callback}]\n{payload}", interfaceId, callback, payload);
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
try
|
||||
if (coreWebView2 is null || coreWebView2.IsDisposed())
|
||||
{
|
||||
if (coreWebView2 is not null)
|
||||
{
|
||||
return await coreWebView2.ExecuteScriptAsync(js);
|
||||
}
|
||||
}
|
||||
catch (COMException)
|
||||
{
|
||||
// COMException (0x8007139F): 组或资源的状态不是执行请求操作的正确状态。 (0x8007139F)
|
||||
// webview is disposing or disposed
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
return await coreWebView2.ExecuteScriptAsync(js);
|
||||
}
|
||||
|
||||
private async void OnWebMessageReceived(CoreWebView2 webView2, CoreWebView2WebMessageReceivedEventArgs args)
|
||||
|
||||
@@ -7,10 +7,4 @@ namespace Snap.Hutao.Web.Bridge.Model;
|
||||
/// 指示此为Js结果
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal interface IJsBridgeResult
|
||||
{
|
||||
string ToJson()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
internal interface IJsBridgeResult;
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Web.Bridge.Model;
|
||||
|
||||
internal static class JsBridgeResultExtension
|
||||
{
|
||||
public static string ToJson<T>(this T result)
|
||||
where T : IJsBridgeResult
|
||||
{
|
||||
return JsonSerializer.Serialize(result, result.GetType());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user