From ed5e319afebf47e7d9bfe93c8b8d82e940abf33b Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Wed, 8 Sep 2021 10:28:35 +0800 Subject: [PATCH] Browser2 --- .../Application/Essentials/Browser2.cs | 137 ++++++++++++++++++ .../Services/ISteamService.cs | 4 +- .../UI/ViewModels/FastLRBHelper.cs | 2 +- .../Pages/About/AboutPageViewModel.shared.cs | 2 +- .../ViewModels/Pages/GameListPageViewModel.cs | 13 +- .../Pages/LocalAuthPageViewModel.shared.cs | 2 +- .../Pages/ProxyScriptManagePageViewModel.cs | 4 +- .../Pages/SteamAccountPageViewModel.cs | 4 +- .../LoginOrRegisterWindowViewModel.shared.cs | 10 +- .../ScriptStoreWindowViewModel.cs | 134 ++++++++--------- .../SteamAccountPage/ShareManageViewModel.cs | 4 +- .../UI/Activities/AboutActivity.cs | 42 +++--- .../Implementation/AppUpdateServiceImpl.cs | 2 +- .../Implementation/HttpProxyServiceImpl.cs | 4 +- .../Implementation/HttpServiceImpl.cs | 9 +- .../Services.CloudService/Constants.cs | 51 ------- src/Startup2.cs | 8 +- 17 files changed, 257 insertions(+), 175 deletions(-) create mode 100644 src/Common.ClientLib/Application/Essentials/Browser2.cs diff --git a/src/Common.ClientLib/Application/Essentials/Browser2.cs b/src/Common.ClientLib/Application/Essentials/Browser2.cs new file mode 100644 index 000000000..a2ec692ca --- /dev/null +++ b/src/Common.ClientLib/Application/Essentials/Browser2.cs @@ -0,0 +1,137 @@ +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; +using Xamarin.Essentials; + +namespace System.Application +{ + public static class Browser2 + { + public static event Action? OnError; + + public static bool HttpsOnly { get; set; } + + public const string Prefix_HTTPS = "https://"; + + public const string Prefix_HTTP = "http://"; + + public const string Prefix_MSStore = "ms-windows-store://"; + + /// + /// 判断字符串是否为 Http Url + /// + /// + /// 是否仅Https + /// + public static bool IsHttpUrl([NotNullWhen(true)] string? url, bool httpsOnly = false) => url != null && + (url.StartsWith(Prefix_HTTPS, StringComparison.OrdinalIgnoreCase) || + (!httpsOnly && url.StartsWith(Prefix_HTTP, StringComparison.OrdinalIgnoreCase))); + + /// + /// 判断字符串是否为 Store Url + /// + /// + /// + public static bool IsStoreUrl([NotNullWhen(true)] string? url) => url != null && url.StartsWith(Prefix_MSStore, StringComparison.OrdinalIgnoreCase); + + static sbyte OpenCore(string? url) + { + if (IsStoreUrl(url)) + { + return OpenCoreByProcess(url); + } + else if (IsHttpUrl(url, HttpsOnly)) + { + if (DeviceInfo.Platform == DevicePlatform.Unknown) + { + return OpenCoreByProcess(url); + } + else + { + return 0; + } + } + return -2; + + static sbyte OpenCoreByProcess(string url) + { + try + { + Process2.Start(url, useShellExecute: true); + return 1; + } + catch (Win32Exception e) + { + // [Win32Exception: 找不到应用程序] 39次报告 + // 疑似缺失没有默认浏览器设置会导致此异常,可能与杀毒软件有关 + if (OnError == null) + { + try + { + Toast.Show(e.GetAllMessage()); + } + catch + { + + } + } + else + { + OnError(e); + } + return -1; + } + } + } + + /// + /// 兼容 Linux/macOS/.Net Core/Android/iOS 的打开链接方法 + /// + /// + /// + public static Task OpenAsync(string? url) => OpenCore(url) switch + { + 0 => Browser.OpenAsync(url), + _ => Task.CompletedTask, + }; + + /// + public static async void Open(string? url) => await OpenAsync(url); + + /// + public static Task OpenAsync(string? url, BrowserLaunchMode launchMode) => OpenCore(url) switch + { + 0 => Browser.OpenAsync(url, launchMode), + _ => Task.CompletedTask, + }; + + /// + public static Task OpenAsync(string? url, BrowserLaunchOptions options) => OpenCore(url) switch + { + 0 => Browser.OpenAsync(url, options), + _ => Task.CompletedTask, + }; + + /// + public static Task OpenAsync(Uri uri) => OpenCore(uri.ToString()) switch + { + 0 => Browser.OpenAsync(uri), + _ => Task.CompletedTask, + }; + + /// + public static Task OpenAsync(Uri uri, BrowserLaunchMode launchMode) => OpenCore(uri.ToString()) switch + { + 0 => Browser.OpenAsync(uri, launchMode), + _ => Task.CompletedTask, + }; + + /// + public static Task OpenAsync(Uri uri, BrowserLaunchOptions options) => OpenCore(uri.ToString()) switch + { + 0 => Browser.OpenAsync(uri, options), + 1 => Task.FromResult(true), + _ => Task.FromResult(false), + }; + } +} \ No newline at end of file diff --git a/src/ST.Client.Desktop/Services/ISteamService.cs b/src/ST.Client.Desktop/Services/ISteamService.cs index 6d4af8e57..2d9bedd85 100644 --- a/src/ST.Client.Desktop/Services/ISteamService.cs +++ b/src/ST.Client.Desktop/Services/ISteamService.cs @@ -1,9 +1,7 @@ using System.Application.Models; using System.Collections.Generic; -using System.IO; -using System.Net; using System.Threading.Tasks; -using static System.Application.Services.CloudService.Constants; +using static System.Application.Browser2; namespace System.Application.Services { diff --git a/src/ST.Client.Desktop/UI/ViewModels/FastLRBHelper.cs b/src/ST.Client.Desktop/UI/ViewModels/FastLRBHelper.cs index 4c3bdafe5..622a769c9 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/FastLRBHelper.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/FastLRBHelper.cs @@ -269,7 +269,7 @@ namespace System.Application.UI.ViewModels } } var url = $"{apiBaseUrl}/ExternalLoginDetection/{(int)channel}?port={vm.ServerWebSocketListenerPort}&sKey={skey_str}&sKeyPadding={padding.OaepHashAlgorithm}&version={csc.Settings.AppVersionStr}&isBind={isBind}&access_token_expires={access_token_expires}&access_token={access_token}"; - BrowserOpen(url); + await Browser2.OpenAsync(url); } } diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/About/AboutPageViewModel.shared.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/About/AboutPageViewModel.shared.cs index 80216dd84..3bb240cf0 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/About/AboutPageViewModel.shared.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/About/AboutPageViewModel.shared.cs @@ -19,7 +19,7 @@ namespace System.Application.UI.ViewModels IconKey = nameof(AboutPageViewModel); #endif - OpenBrowserCommand = ReactiveCommand.Create(BrowserOpen); + OpenBrowserCommand = ReactiveCommand.CreateFromTask(Browser2.OpenAsync); //#if !__MOBILE__ // CopyLinkCommand = diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/GameListPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/GameListPageViewModel.cs index df7310244..c40ccbf5a 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/GameListPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/GameListPageViewModel.cs @@ -12,7 +12,6 @@ using System.Reactive.Linq; using System.Reactive.Subjects; using System.Threading.Tasks; using System.Diagnostics; -using static System.Application.Services.CloudService.Constants; using System.Globalization; using System.IO; using System.Windows; @@ -255,19 +254,19 @@ namespace System.Application.UI.ViewModels IDesktopPlatformService.Instance.OpenFolder(app.InstalledDir); } - public void OpenAppStoreUrl(SteamApp app) + public async void OpenAppStoreUrl(SteamApp app) { - BrowserOpen(string.Format(SteamApiUrls.STEAMSTORE_APP_URL, app.AppId)); + await Browser2.OpenAsync(string.Format(SteamApiUrls.STEAMSTORE_APP_URL, app.AppId)); } - public void OpenSteamDBUrl(SteamApp app) + public async void OpenSteamDBUrl(SteamApp app) { - BrowserOpen(string.Format(SteamApiUrls.STEAMDBINFO_APP_URL, app.AppId)); + await Browser2.OpenAsync(string.Format(SteamApiUrls.STEAMDBINFO_APP_URL, app.AppId)); } - public void OpenSteamCardUrl(SteamApp app) + public async void OpenSteamCardUrl(SteamApp app) { - BrowserOpen(string.Format(SteamApiUrls.STEAMCARDEXCHANGE_APP_URL, app.AppId)); + await Browser2.OpenAsync(string.Format(SteamApiUrls.STEAMCARDEXCHANGE_APP_URL, app.AppId)); } public void AddAFKAppList(SteamApp app) diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.shared.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.shared.cs index 2f1a40320..f10bc95fe 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.shared.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.shared.cs @@ -25,7 +25,7 @@ namespace System.Application.UI.ViewModels IconKey = nameof(LocalAuthPageViewModel); #endif - OpenBrowserCommand = ReactiveCommand.Create(Services.CloudService.Constants.BrowserOpen); + OpenBrowserCommand = ReactiveCommand.CreateFromTask(Browser2.OpenAsync); AddAuthCommand = ReactiveCommand.Create(AddAuthMenu_Click); RefreshAuthCommand = ReactiveCommand.CreateFromTask(async () => { diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs index cb755a685..a78563bdd 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs @@ -198,9 +198,9 @@ namespace System.Application.UI.ViewModels } - public void OpenHomeScriptItemButton(ScriptDTO script) + public async void OpenHomeScriptItemButton(ScriptDTO script) { - Services.CloudService.Constants.BrowserOpen(script.SourceLink); + await Browser2.OpenAsync(script.SourceLink); } public async void RefreshScriptItemButton(ScriptDTO script) diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/SteamAccountPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/SteamAccountPageViewModel.cs index 52b55bacf..2ec9417c0 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/SteamAccountPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/SteamAccountPageViewModel.cs @@ -220,9 +220,9 @@ namespace System.Application.UI.ViewModels } } - public void OpenUserProfileUrl(SteamUser user) + public async void OpenUserProfileUrl(SteamUser user) { - BrowserOpen(user.ProfileUrl); + await Browser2.OpenAsync(user.ProfileUrl); } public void LoginNewSteamAccount() diff --git a/src/ST.Client.Desktop/UI/ViewModels/Windows/LoginOrRegisterWindowViewModel.shared.cs b/src/ST.Client.Desktop/UI/ViewModels/Windows/LoginOrRegisterWindowViewModel.shared.cs index 419af0c81..60e8f81d3 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Windows/LoginOrRegisterWindowViewModel.shared.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Windows/LoginOrRegisterWindowViewModel.shared.cs @@ -80,7 +80,7 @@ namespace System.Application.UI.ViewModels } public ICommand ManualLogin { get; } - + private string? _CurrentSelectChannel; public string? CurrentSelectChannel { @@ -221,7 +221,7 @@ namespace System.Application.UI.ViewModels public const string Agreement = "Agreement"; public const string Privacy = "Privacy"; - void OpenHyperlink_(string parameter) + async void OpenHyperlink_(string parameter) { if (string.IsNullOrWhiteSpace(parameter)) return; switch (parameter) @@ -234,18 +234,18 @@ namespace System.Application.UI.ViewModels break; } #if __MOBILE__ - BrowserOpen(parameter); + await Browser2.OpenAsync(parameter); #else if (AppHelper.IsSystemWebViewAvailable) { - IShowWindowService.Instance.Show(CustomWindow.WebView3, new WebView3WindowViewModel + await IShowWindowService.Instance.Show(CustomWindow.WebView3, new WebView3WindowViewModel { Url = parameter, }, resizeMode: ResizeModeCompat.NoResize); } else { - BrowserOpen(parameter); + await Browser2.OpenAsync(parameter); } #endif } diff --git a/src/ST.Client.Desktop/UI/ViewModels/Windows/ProxyScriptManagePage/ScriptStoreWindowViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Windows/ProxyScriptManagePage/ScriptStoreWindowViewModel.cs index d357d3167..25a517dc2 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Windows/ProxyScriptManagePage/ScriptStoreWindowViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Windows/ProxyScriptManagePage/ScriptStoreWindowViewModel.cs @@ -11,79 +11,79 @@ using System.Reactive.Linq; using System.Linq; namespace System.Application.UI.ViewModels { - public class ScriptStoreWindowViewModel : WindowViewModel - { - public ScriptStoreWindowViewModel() : base() + public class ScriptStoreWindowViewModel : WindowViewModel + { + public ScriptStoreWindowViewModel() : base() { - Title = ThisAssembly.AssemblyTrademark + " | " + AppResources.ScriptStore; - _ScriptsSourceList = new SourceList(); + Title = ThisAssembly.AssemblyTrademark + " | " + AppResources.ScriptStore; + _ScriptsSourceList = new SourceList(); - _ScriptsSourceList - .Connect() - //.Filter(scriptFilter) - .ObserveOn(RxApp.MainThreadScheduler) - .Sort(SortExpressionComparer.Ascending(x => x.Order).ThenBy(x => x.Name)) - .Bind(out _Scripts) - .Subscribe(_ => this.RaisePropertyChanged(nameof(IsScriptsEmpty))); + _ScriptsSourceList + .Connect() + //.Filter(scriptFilter) + .ObserveOn(RxApp.MainThreadScheduler) + .Sort(SortExpressionComparer.Ascending(x => x.Order).ThenBy(x => x.Name)) + .Bind(out _Scripts) + .Subscribe(_ => this.RaisePropertyChanged(nameof(IsScriptsEmpty))); - this.WhenAnyValue(x => x.SearchText) - .Subscribe(x => - { - //x - InitializeScriptList(); - }); - } + this.WhenAnyValue(x => x.SearchText) + .Subscribe(x => + { + //x + InitializeScriptList(); + }); + } - private readonly ReadOnlyObservableCollection _Scripts; - public ReadOnlyObservableCollection Scripts => _Scripts; + private readonly ReadOnlyObservableCollection _Scripts; + public ReadOnlyObservableCollection Scripts => _Scripts; - private readonly SourceList _ScriptsSourceList; + private readonly SourceList _ScriptsSourceList; - public bool IsScriptsEmpty => !Scripts.Any_Nullable(); + public bool IsScriptsEmpty => !Scripts.Any_Nullable(); - private string? _SearchText; - public string? SearchText - { - get => _SearchText; - set => this.RaiseAndSetIfChanged(ref _SearchText, value); - } - public void RefreshScriptButton() - { - InitializeScriptList(); - } - public void DownloadScriptItemButton(ScriptDTO model) - { - ProxyService.Current.DownloadScript(model); - } - public void OpenHomeScriptItemButton(ScriptDTO script) - { - Services.CloudService.Constants.BrowserOpen(script.SourceLink); - } + private string? _SearchText; + public string? SearchText + { + get => _SearchText; + set => this.RaiseAndSetIfChanged(ref _SearchText, value); + } + public void RefreshScriptButton() + { + InitializeScriptList(); + } + public void DownloadScriptItemButton(ScriptDTO model) + { + ProxyService.Current.DownloadScript(model); + } + public async void OpenHomeScriptItemButton(ScriptDTO script) + { + await Browser2.OpenAsync(script.SourceLink); + } - private async void InitializeScriptList() - { - var client = ICloudServiceClient.Instance.Script; - var response = await client.ScriptTable(name: SearchText,pageSize:100,errormsg:AppResources.ScriptShop_GetTableError); - if (!response.IsSuccess || response.Content == null) - { - return; - } - response.Content.DataSource.ForEach(item => - { - var old = ProxyService.Current.ProxyScripts.Items.FirstOrDefault(x => x.Id == item.Id); - if (old != null) - { - item.IsExist = true; - if (old.Version != item.Version) - { - item.IsUpdate = true; - item.NewVersion = item.Version; - item.Version = old.Version; - } - } - }); - _ScriptsSourceList.Clear(); - _ScriptsSourceList.AddRange(response.Content.DataSource); - } - } + private async void InitializeScriptList() + { + var client = ICloudServiceClient.Instance.Script; + var response = await client.ScriptTable(name: SearchText, pageSize: 100, errormsg: AppResources.ScriptShop_GetTableError); + if (!response.IsSuccess || response.Content == null) + { + return; + } + response.Content.DataSource.ForEach(item => + { + var old = ProxyService.Current.ProxyScripts.Items.FirstOrDefault(x => x.Id == item.Id); + if (old != null) + { + item.IsExist = true; + if (old.Version != item.Version) + { + item.IsUpdate = true; + item.NewVersion = item.Version; + item.Version = old.Version; + } + } + }); + _ScriptsSourceList.Clear(); + _ScriptsSourceList.AddRange(response.Content.DataSource); + } + } } \ No newline at end of file diff --git a/src/ST.Client.Desktop/UI/ViewModels/Windows/SteamAccountPage/ShareManageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Windows/SteamAccountPage/ShareManageViewModel.cs index f5c16f19b..232cb86eb 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Windows/SteamAccountPage/ShareManageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Windows/SteamAccountPage/ShareManageViewModel.cs @@ -107,9 +107,9 @@ namespace System.Application.UI.ViewModels _AuthorizedSourceList.Refresh(); } - public void OpenUserProfileUrl(AuthorizedDevice user) + public async void OpenUserProfileUrl(AuthorizedDevice user) { - BrowserOpen(user.ProfileUrl); + await Browser2.OpenAsync(user.ProfileUrl); } public void About_Click() diff --git a/src/ST.Client.Mobile.Droid/UI/Activities/AboutActivity.cs b/src/ST.Client.Mobile.Droid/UI/Activities/AboutActivity.cs index 38d006d45..72bd5ddc4 100644 --- a/src/ST.Client.Mobile.Droid/UI/Activities/AboutActivity.cs +++ b/src/ST.Client.Mobile.Droid/UI/Activities/AboutActivity.cs @@ -68,7 +68,7 @@ namespace System.Application.UI.Activities }).AddTo(this); var adapter = new SmallPreferenceButtonAdapter(ViewModel!.PreferenceButtons); - adapter.ItemClick += (_, e) => + adapter.ItemClick += async (_, e) => { switch (e.Current.Id) { @@ -77,13 +77,13 @@ namespace System.Application.UI.Activities //ViewModel!.CheckUpdateCommand.Invoke(); break; case PreferenceButton.更新日志: - BrowserOpen(string.Format( + await Browser2.OpenAsync(string.Format( UrlConstants.OfficialWebsite_Box_Changelog_, MainApplication.GetTheme(), R.Language)); break; case PreferenceButton.常见问题疑难解答: - BrowserOpen(string.Format( + await Browser2.OpenAsync(string.Format( UrlConstants.OfficialWebsite_Box_Faq_, MainApplication.GetTheme(), R.Language)); @@ -96,7 +96,7 @@ namespace System.Application.UI.Activities }); break; case PreferenceButton.源码仓库: - ComboBoxHelper.Dialog(this, SourceRepositories, x => BrowserOpen(x switch + ComboBoxHelper.Dialog(this, SourceRepositories, async x => await Browser2.OpenAsync(x switch { GitHub => UrlConstants.GitHub_Repository, Gitee => UrlConstants.Gitee_Repository, @@ -104,13 +104,13 @@ namespace System.Application.UI.Activities })); break; case PreferenceButton.产品官网: - BrowserOpen(UrlConstants.OfficialWebsite); + await Browser2.OpenAsync(UrlConstants.OfficialWebsite); break; case PreferenceButton.联系我们: - BrowserOpen(UrlConstants.OfficialWebsite_Contact); + await Browser2.OpenAsync(UrlConstants.OfficialWebsite_Contact); break; case PreferenceButton.Bug反馈: - ComboBoxHelper.Dialog(this, SourceRepositories, x => BrowserOpen(x switch + ComboBoxHelper.Dialog(this, SourceRepositories, async x => await Browser2.OpenAsync(x switch { GitHub => UrlConstants.GitHub_Issues, Gitee => UrlConstants.Gitee_Issues, @@ -438,23 +438,23 @@ namespace System.Application.UI.Activities StringBuilder str = new(Developers_0); length = str.Length; str.Append(At_Rmbadmin); - list.Add((new HyperlinkClickableSpan(_ => + list.Add((new HyperlinkClickableSpan(async _ => { - BrowserOpen(UrlConstants.GitHub_User_Rmbadmin); + await Browser2.OpenAsync(UrlConstants.GitHub_User_Rmbadmin); }), length, str.Length, SpanTypes.ExclusiveExclusive)); str.Append(Separator); length = str.Length; str.Append(At_AigioL); - list.Add((new HyperlinkClickableSpan(_ => + list.Add((new HyperlinkClickableSpan(async _ => { - BrowserOpen(UrlConstants.GitHub_User_AigioL); + await Browser2.OpenAsync(UrlConstants.GitHub_User_AigioL); }), length, str.Length, SpanTypes.ExclusiveExclusive)); str.Append(Separator); length = str.Length; str.Append(At_Mossimos); - list.Add((new HyperlinkClickableSpan(_ => + list.Add((new HyperlinkClickableSpan(async _ => { - BrowserOpen(UrlConstants.GitHub_User_Mossimos); + await Browser2.OpenAsync(UrlConstants.GitHub_User_Mossimos); }), length, str.Length, SpanTypes.ExclusiveExclusive)); return str; }); @@ -465,9 +465,9 @@ namespace System.Application.UI.Activities StringBuilder str = new(BusinessCooperationContact_0); length = str.Length; str.Append(At_Cliencer); - list.Add((new HyperlinkClickableSpan(_ => + list.Add((new HyperlinkClickableSpan(async _ => { - BrowserOpen(UrlConstants.BILI_User_Cliencer); + await Browser2.OpenAsync(UrlConstants.BILI_User_Cliencer); }), length, str.Length, SpanTypes.ExclusiveExclusive)); return str; }); @@ -478,16 +478,16 @@ namespace System.Application.UI.Activities StringBuilder str = new(); length = str.Length; str.Append(AppResources.User_Agreement); - list.Add((new HyperlinkClickableSpan(_ => + list.Add((new HyperlinkClickableSpan(async _ => { - BrowserOpen(UrlConstants.OfficialWebsite_Box_Agreement); + await Browser2.OpenAsync(UrlConstants.OfficialWebsite_Box_Agreement); }), length, str.Length, SpanTypes.ExclusiveExclusive)); str.Append(Separator2); length = str.Length; str.Append(AppResources.User_Privacy); - list.Add((new HyperlinkClickableSpan(_ => + list.Add((new HyperlinkClickableSpan(async _ => { - BrowserOpen(UrlConstants.OfficialWebsite_Box_Privacy); + await Browser2.OpenAsync(UrlConstants.OfficialWebsite_Box_Privacy); }), length, str.Length, SpanTypes.ExclusiveExclusive)); return str; }); @@ -498,9 +498,9 @@ namespace System.Application.UI.Activities StringBuilder str = new(OpenSourceLicensed_0); length = str.Length; str.Append(OpenSourceLicensed_1); - list.Add((new HyperlinkClickableSpan(_ => + list.Add((new HyperlinkClickableSpan(async _ => { - BrowserOpen(UrlConstants.License_GPLv3); + await Browser2.OpenAsync(UrlConstants.License_GPLv3); }), length, str.Length, SpanTypes.ExclusiveExclusive)); return str; }); diff --git a/src/ST.Client/Services/Implementation/AppUpdateServiceImpl.cs b/src/ST.Client/Services/Implementation/AppUpdateServiceImpl.cs index 019f251a3..dec314b40 100644 --- a/src/ST.Client/Services/Implementation/AppUpdateServiceImpl.cs +++ b/src/ST.Client/Services/Implementation/AppUpdateServiceImpl.cs @@ -9,7 +9,7 @@ using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Threading.Tasks; using System.Windows.Input; -using static System.Application.Services.CloudService.Constants; +using static System.Application.Browser2; using static System.Application.Services.IAppUpdateService; using CC = System.Common.Constants; diff --git a/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs b/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs index 74afd7d15..45ba4b0d3 100644 --- a/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs +++ b/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs @@ -209,7 +209,7 @@ namespace System.Application.Services.Implementation } if (item.Redirect) { - if (CloudService.Constants.IsHttpUrl(item.ForwardDomainName)) + if (Browser2.IsHttpUrl(item.ForwardDomainName)) { e.Redirect(e.HttpClient.Request.RequestUri.AbsoluteUri.Replace(e.HttpClient.Request.RequestUri.Scheme + "://" + e.HttpClient.Request.RequestUri.Host, item.ForwardDomainName)); return; @@ -400,7 +400,7 @@ namespace System.Application.Services.Implementation if (OperatingSystem2.IsLinux) { IPlatformService.Instance.AdminShell($"sudo cp -f \"{filePath}\" \"{Path.Combine(IOPath.AppDataDirectory, $@"{CertificateName}.Certificate.pem")}\"", false); - CloudService.Constants.BrowserOpen("https://www.steampp.net/liunxSetupCer"); + Browser2.Open("https://www.steampp.net/liunxSetupCer"); return true; } return IsCertificateInstalled(proxyServer.CertificateManager.RootCertificate); diff --git a/src/ST.Client/Services/Implementation/HttpServiceImpl.cs b/src/ST.Client/Services/Implementation/HttpServiceImpl.cs index 152a6cbb9..7f3160d13 100644 --- a/src/ST.Client/Services/Implementation/HttpServiceImpl.cs +++ b/src/ST.Client/Services/Implementation/HttpServiceImpl.cs @@ -12,7 +12,6 @@ using System.Threading; using System.Threading.Tasks; using System.Xml.Serialization; using static System.Application.ForwardHelper; -using static System.Application.Services.CloudService.Constants; using static System.Application.Services.IHttpService; namespace System.Application.Services.Implementation @@ -54,7 +53,7 @@ namespace System.Application.Services.Implementation request = requestFactory(); requestUri ??= request.RequestUri.ToString(); - if (!isCheckHttpUrl && !IsHttpUrl(requestUri)) return default; + if (!isCheckHttpUrl && !Browser2.IsHttpUrl(requestUri)) return default; if (enableForward && IsAllowUrl(requestUri)) { @@ -178,7 +177,7 @@ namespace System.Application.Services.Implementation CancellationToken cancellationToken, string? cookie = null) where T : notnull { - if (!IsHttpUrl(requestUri)) return Task.FromResult(default(T?)); + if (!Browser2.IsHttpUrl(requestUri)) return Task.FromResult(default(T?)); return SendAsync(isCheckHttpUrl: true, requestUri, () => { var request = new HttpRequestMessage(HttpMethod.Get, requestUri); @@ -347,7 +346,7 @@ namespace System.Application.Services.Implementation public async Task GetImageLocalFilePathAsync(string requestUri, string channelType, CancellationToken cancellationToken) { - if (!IsHttpUrl(requestUri)) return null; + if (!Browser2.IsHttpUrl(requestUri)) return null; if (get_image_pipeline.ContainsKey(channelType)) { @@ -377,7 +376,7 @@ namespace System.Application.Services.Implementation public async Task GetImageStreamAsync(string requestUri, CancellationToken cancellationToken) { - if (!IsHttpUrl(requestUri)) return null; + if (!Browser2.IsHttpUrl(requestUri)) return null; try { diff --git a/src/ST.Services.CloudService.Models/Services.CloudService/Constants.cs b/src/ST.Services.CloudService.Models/Services.CloudService/Constants.cs index 465cf4afd..e3a3e09d0 100644 --- a/src/ST.Services.CloudService.Models/Services.CloudService/Constants.cs +++ b/src/ST.Services.CloudService.Models/Services.CloudService/Constants.cs @@ -1,7 +1,4 @@ using System.Application.Properties; -using System.ComponentModel; -using System.Diagnostics; -using Xamarin.Essentials; namespace System.Application.Services.CloudService { @@ -38,10 +35,6 @@ namespace System.Application.Services.CloudService /// public const double SMSIntervalActually = 79.5; - public const string Prefix_HTTPS = "https://"; - - public const string Prefix_HTTP = "http://"; - public static string IsNotOfficialChannelPackageWarning => SR.IsNotOfficialChannelPackageWarning; /// @@ -67,49 +60,5 @@ namespace System.Application.Services.CloudService } return cacheValuesArray; } - - /// - /// 判断字符串是否为 Http Url - /// - /// - /// 是否仅Https - /// - public static bool IsHttpUrl(string? url, bool httpsOnly = false) => url != null && - (url.StartsWith(Prefix_HTTPS, StringComparison.OrdinalIgnoreCase) || - (!httpsOnly && url.StartsWith(Prefix_HTTP, StringComparison.OrdinalIgnoreCase))); - - /// - /// 兼容 Linux/Mac/.NetCore/Android/iOS 的打开链接方法 - /// - /// - public static async void BrowserOpen(string? url) - { - //if (IsHttpUrl(url)) - //{ - if (DeviceInfo.Platform == DevicePlatform.Unknown) - { - try - { - Process.Start(new ProcessStartInfo - { - FileName = url, - UseShellExecute = true, - }); - } - catch (Win32Exception e) - { -#if MVVM_VM - // [Win32Exception: 找不到应用程序] 39次报告 - // 疑似缺失没有默认浏览器设置会导致此异常,可能与杀毒软件有关 - Toast.Show(e.GetAllMessage()); -#endif - } - } - else - { - await Browser.OpenAsync(url); - } - //} - } } } \ No newline at end of file diff --git a/src/Startup2.cs b/src/Startup2.cs index aaf07e1a6..24985ee7c 100644 --- a/src/Startup2.cs +++ b/src/Startup2.cs @@ -20,7 +20,7 @@ using System.Collections.Generic; using System.Reflection; using System.Application.Services.CloudService.Clients.Abstractions; using System.Linq; -using CSConst = System.Application.Services.CloudService.Constants; +using static System.Application.Browser2; using System.Properties; using System.IO; using static System.Application.AppClientAttribute; @@ -416,7 +416,7 @@ namespace System.Application // { // try // { - // var url = CSConst.Prefix_HTTPS + "localhost:5001"; + // var url = Prefix_HTTPS + "localhost:5001"; // var request = WebRequest.CreateHttp(url); // request.Timeout = 1888; // request.GetResponse(); @@ -431,8 +431,8 @@ namespace System.Application //#endif var value = (_ThisAssembly.Debuggable || !s.GetIsOfficialChannelPackage()) ? - CSConst.Prefix_HTTPS + "pan.mossimo.net:8862" : - CSConst.Prefix_HTTPS + "api.steampp.net"; + Prefix_HTTPS + "pan.mossimo.net:8862" : + Prefix_HTTPS + "api.steampp.net"; s.ApiBaseUrl = value; } }