diff --git a/src/Starward/Controls/HyperionWebBridge.xaml.cs b/src/Starward/Controls/HyperionWebBridge.xaml.cs index 6bd662341..b844cb112 100644 --- a/src/Starward/Controls/HyperionWebBridge.xaml.cs +++ b/src/Starward/Controls/HyperionWebBridge.xaml.cs @@ -1,6 +1,8 @@ -using Microsoft.UI.Xaml; +using CommunityToolkit.Mvvm.Messaging; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Starward.Core.GameRecord; +using Starward.Messages; using System; using System.Collections.Generic; using System.Diagnostics; @@ -154,7 +156,7 @@ private async void CoreWebView2_WebMessageReceived(Microsoft.Web.WebView2.Core.C JsResult? result = param.Method switch { - "closePage" => null, + "closePage" => ClosePage(param), "configure_share" => null, "eventTrack" => null, //"getActionTicket" => await GetActionTicketAsync(param).ConfigureAwait(false), @@ -234,6 +236,20 @@ private async Task CallbackAsync(string? callback, JsResult? result) } + private JsResult? ClosePage(JsParam param) + { + if (webview2.CoreWebView2.CanGoBack) + { + webview2.CoreWebView2.GoBack(); + } + else + { + this.DispatcherQueue.TryEnqueue(() => WeakReferenceMessenger.Default.Send(new GameRecordPageNavigationGoBackMessage())); + + } + return null; + } + private JsResult? PushPage(JsParam param) { diff --git a/src/Starward/Messages/GameRecordPageNavigationGoBackMessage.cs b/src/Starward/Messages/GameRecordPageNavigationGoBackMessage.cs new file mode 100644 index 000000000..f908f09c9 --- /dev/null +++ b/src/Starward/Messages/GameRecordPageNavigationGoBackMessage.cs @@ -0,0 +1,3 @@ +namespace Starward.Messages; + +public record GameRecordPageNavigationGoBackMessage(); diff --git a/src/Starward/Pages/HoyolabToolbox/HoyolabToolboxPage.xaml.cs b/src/Starward/Pages/HoyolabToolbox/HoyolabToolboxPage.xaml.cs index 2eb64b1da..93620550c 100644 --- a/src/Starward/Pages/HoyolabToolbox/HoyolabToolboxPage.xaml.cs +++ b/src/Starward/Pages/HoyolabToolbox/HoyolabToolboxPage.xaml.cs @@ -84,6 +84,10 @@ protected override async void OnLoaded() { NavigateTo(typeof(HyperionWebBridgePage), new HyperionWebBridgePage.PageParameter(m.GameRole, m.TargetUrl)); }); + WeakReferenceMessenger.Default.Register(this, (r, m) => + { + if (frame.CanGoBack) { frame.GoBack(); } + }); await Task.Delay(16); NavigateTo(typeof(BlankPage)); await CheckAgreementAsync();