From 54d93238c38213c9e8c079b887c808b3145283e1 Mon Sep 17 00:00:00 2001 From: Scighost Date: Sat, 20 Jan 2024 16:43:33 +0800 Subject: [PATCH] support to click go back button while verifing account --- .../Controls/HyperionWebBridge.xaml.cs | 20 +++++++++++++++++-- .../GameRecordPageNavigationGoBackMessage.cs | 3 +++ .../HoyolabToolbox/HoyolabToolboxPage.xaml.cs | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/Starward/Messages/GameRecordPageNavigationGoBackMessage.cs 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();