From dcc8fc04b2df2b1231cd635b1132cd381a99ba2a Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Sun, 2 May 2021 14:51:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=B8=AD=EF=BC=9ASteam=20?= =?UTF-8?q?=E5=BF=AB=E9=80=9F=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Application/UI/Views/Controls/WebView3.cs | 17 ++++++++-- .../UI/Views/Windows/WebView3Window.axaml.cs | 7 ++-- .../UI/ViewModels/Pages/DebugPageViewModel.cs | 32 +++++++++++++++---- .../Windows/WebView3WindowViewModel.cs | 2 ++ 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/WebView3.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/WebView3.cs index ad3494a4b..247472037 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/WebView3.cs +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/WebView3.cs @@ -46,10 +46,15 @@ namespace System.Application.UI.Views.Controls } /// - /// 在浏览器中打开新窗口 + /// 在浏览器中打开新窗口,所有新页面打开的Url会在浏览器中打开 /// public bool OpenInBrowser { get; set; } = true; + /// + /// 是否固定单页,为 时所有跳转都将在浏览器中打开 + /// + public bool FixedSinglePage { get; set; } = false; + /// /// 需要拦截响应流的Url /// @@ -170,6 +175,11 @@ namespace System.Application.UI.Views.Controls protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref CefDictionaryValue extraInfo, ref int noJavascriptAccess) { + if (webView.FixedSinglePage) + { + BrowserOpen(targetUrl); + return true; + } switch (targetDisposition) { case CefWindowOpenDisposition.NewForegroundTab: @@ -183,7 +193,10 @@ namespace System.Application.UI.Views.Controls else { // 禁止创建新窗口,仅在当前窗口跳转 - browser.MainFrame.LoadUrl(targetUrl); + if (IsHttpUrl(targetUrl)) + { + browser.MainFrame.LoadUrl(targetUrl); + } } return true; } diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/WebView3Window.axaml.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/WebView3Window.axaml.cs index db4d5a0d1..5eb3586b4 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/WebView3Window.axaml.cs +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/WebView3Window.axaml.cs @@ -32,6 +32,7 @@ namespace System.Application.UI.Views.Windows base.OnDataContextChanged(e); if (DataContext is WebView3WindowViewModel vm) { + if (!string.IsNullOrWhiteSpace(vm.Title)) webView.DocumentTitleChanged -= WebView_DocumentTitleChanged; vm.WhenAnyValue(x => x.Url).WhereNotNull().Subscribe(x => { if (x == WebView3WindowViewModel.AboutBlank) @@ -56,10 +57,8 @@ namespace System.Application.UI.Views.Windows } } }).AddTo(vm); - vm.WhenAnyValue(x => x.StreamResponseFilterUrls).Subscribe(x => - { - webView.StreamResponseFilterUrls = x; - }).AddTo(vm); + vm.WhenAnyValue(x => x.StreamResponseFilterUrls).Subscribe(x => webView.StreamResponseFilterUrls = x).AddTo(vm); + vm.WhenAnyValue(x => x.FixedSinglePage).Subscribe(x => webView.FixedSinglePage = x).AddTo(vm); webView.OnStreamResponseFilterResourceLoadComplete += vm.OnStreamResponseFilterResourceLoadComplete; } } diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/DebugPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/DebugPageViewModel.cs index f0c6361a0..3b6cbc67c 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/DebugPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/DebugPageViewModel.cs @@ -16,6 +16,7 @@ using System.Linq; using System.Security; using System.Text; using System.Threading.Tasks; +using System.Windows; using static Newtonsoft.Json.JsonConvert; namespace System.Application.UI.ViewModels @@ -209,15 +210,34 @@ namespace System.Application.UI.ViewModels DebugString = @string.ToString(); } - public async void ShowDialogButton_Click() + public /*async*/ void ShowDialogButton_Click() { - DI.Get().OpenDesktopIconsSettings(); +#if DEBUG + var apiBaseUrl = ICloudServiceClient.Instance.ApiBaseUrl; + var vm = new WebView3WindowViewModel + { + Url = apiBaseUrl + "/ExternalLogin", + StreamResponseFilterUrls = new[] + { + apiBaseUrl + "/ExternalLoginCallback" + }, + OnStreamResponseFilterResourceLoadComplete = (url, data) => + { - ToastService.Current.Notify("中文测试繁體測試🎉🧨🎇🎆🎄🖼🖼🖼🖼"); - DebugString += ToastService.Current.Message + Environment.NewLine; - DebugString += ToastService.Current.IsVisible + Environment.NewLine; + }, + FixedSinglePage = true, + Title = "Steam 快速登录", + }; + IShowWindowService.Instance.Show(CustomWindow.WebView3, vm, resizeMode: ResizeModeCompat.NoResize); +#endif - await IShowWindowService.Instance.Show(typeof(object), CustomWindow.NewVersion); + //DI.Get().OpenDesktopIconsSettings(); + + //ToastService.Current.Notify("中文测试繁體測試🎉🧨🎇🎆🎄🖼🖼🖼🖼"); + //DebugString += ToastService.Current.Message + Environment.NewLine; + //DebugString += ToastService.Current.IsVisible + Environment.NewLine; + + //await IShowWindowService.Instance.Show(typeof(object), CustomWindow.NewVersion); // var r = await MessageBoxCompat.ShowAsync(@"Steam++ v1.1.2 2021-01-29 //更新内容 diff --git a/src/ST.Client.Desktop/UI/ViewModels/Windows/WebView3WindowViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Windows/WebView3WindowViewModel.cs index 764f3bc9a..175dd8213 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Windows/WebView3WindowViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Windows/WebView3WindowViewModel.cs @@ -21,5 +21,7 @@ namespace System.Application.UI.ViewModels } public Action? OnStreamResponseFilterResourceLoadComplete { get; set; } + + public bool FixedSinglePage { get; set; } } } \ No newline at end of file