diff --git a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.Designer.cs b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.Designer.cs index dcd4766d..27f8ce66 100644 --- a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.Designer.cs +++ b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.Designer.cs @@ -6846,6 +6846,15 @@ namespace Snap.Hutao.Resource.Localization { } } + /// + /// 查找类似 已复制到剪贴板 的本地化字符串。 + /// + internal static string WebBridgeShareCopyToClipboardSuccess { + get { + return ResourceManager.GetString("WebBridgeShareCopyToClipboardSuccess", resourceCulture); + } + } + /// /// 查找类似 {0} 时 的本地化字符串。 /// diff --git a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx index 52f3b2ef..42c2f090 100644 --- a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx +++ b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx @@ -2435,6 +2435,9 @@ {0} 小时后结束 + + 已复制到剪贴板 + {0} 时 diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSInterface.cs b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSInterface.cs index a9067aa1..c9bc081e 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSInterface.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSInterface.cs @@ -51,13 +51,13 @@ internal class MiHoYoJSInterface private readonly TypedEventHandler domContentLoadedEventHandler; private readonly TypedEventHandler navigationStartingEventHandler; - private CoreWebView2 webView; + private CoreWebView2 coreWebView2; public MiHoYoJSInterface(CoreWebView2 webView, UserAndUid userAndUid) { // 由于Webview2 的作用域特殊性,我们在此处直接使用根服务 serviceProvider = Ioc.Default; - this.webView = webView; + this.coreWebView2 = webView; this.userAndUid = userAndUid; taskContext = serviceProvider.GetRequiredService(); @@ -227,7 +227,7 @@ internal class MiHoYoJSInterface } await taskContext.SwitchToMainThreadAsync(); - webView.SetCookie(userAndUid.User.CookieToken, userAndUid.User.LToken); + coreWebView2.SetCookie(userAndUid.User.CookieToken, userAndUid.User.LToken); ArgumentNullException.ThrowIfNull(userAndUid.User.CookieToken); return new() { Data = new() { [Cookie.COOKIE_TOKEN] = userAndUid.User.CookieToken[Cookie.COOKIE_TOKEN] } }; @@ -241,9 +241,9 @@ internal class MiHoYoJSInterface public virtual async ValueTask ClosePageAsync(JsParam param) { await taskContext.SwitchToMainThreadAsync(); - if (webView.CanGoBack) + if (coreWebView2.CanGoBack) { - webView.GoBack(); + coreWebView2.GoBack(); } else { @@ -276,7 +276,7 @@ internal class MiHoYoJSInterface public virtual async ValueTask PushPageAsync(JsParam param) { await taskContext.SwitchToMainThreadAsync(); - webView.Navigate(param.Payload.Page); + coreWebView2.Navigate(param.Payload.Page); return null; } @@ -299,6 +299,17 @@ internal class MiHoYoJSInterface }; } + public virtual IJsResult? Share(JsParam param) + { + return new JsResult>() + { + Data = new() + { + ["type"] = param.Payload.Type, + }, + }; + } + public virtual ValueTask ShowAlertDialogAsync(JsParam param) { return ValueTask.FromException(new NotSupportedException()); @@ -346,10 +357,10 @@ internal class MiHoYoJSInterface public void Detach() { - webView.WebMessageReceived -= webMessageReceivedEventHandler; - webView.DOMContentLoaded -= domContentLoadedEventHandler; - webView.NavigationStarting -= navigationStartingEventHandler; - webView = default!; + coreWebView2.WebMessageReceived -= webMessageReceivedEventHandler; + coreWebView2.DOMContentLoaded -= domContentLoadedEventHandler; + coreWebView2.NavigationStarting -= navigationStartingEventHandler; + coreWebView2 = default!; } private async ValueTask ExecuteCallbackScriptAsync(string callback, string? payload = null) @@ -375,9 +386,9 @@ internal class MiHoYoJSInterface await taskContext.SwitchToMainThreadAsync(); try { - if (webView is not null) + if (coreWebView2 is not null) { - return await webView.ExecuteScriptAsync(js); + return await coreWebView2.ExecuteScriptAsync(js); } } catch (COMException) @@ -436,6 +447,7 @@ internal class MiHoYoJSInterface "hideLoading" => null, "login" => null, "pushPage" => await PushPageAsync(param).ConfigureAwait(false), + "share" => Share(param), "showLoading" => null, _ => LogUnhandledMessage("Unhandled Message Type: {method}", param.Method), }; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/Model/ShareContent.cs b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/Model/ShareContent.cs new file mode 100644 index 00000000..e7764da3 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/Model/ShareContent.cs @@ -0,0 +1,10 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Bridge.Model; + +internal sealed class ShareContent +{ + [JsonPropertyName("preview")] + public bool Preview { get; set; } +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/Model/SharePayload.cs b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/Model/SharePayload.cs new file mode 100644 index 00000000..f10a15a0 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/Model/SharePayload.cs @@ -0,0 +1,13 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Bridge.Model; + +internal sealed class SharePayload +{ + [JsonPropertyName("type")] + public string Type { get; set; } = default!; + + [JsonPropertyName("content")] + public ShareContent Content { get; set; } = default!; +} \ No newline at end of file