From f4a51be761dc59feb674edee7df90c19dd666da1 Mon Sep 17 00:00:00 2001 From: SherkeyXD <253294679@qq.com> Date: Wed, 7 Feb 2024 18:40:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A0=E9=99=90?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E8=BF=9C=E6=8E=A7=E5=9C=B0=E5=9D=80=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RemoteControl/RemoteControlService.cs | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/MaaWpfGui/Services/RemoteControl/RemoteControlService.cs b/src/MaaWpfGui/Services/RemoteControl/RemoteControlService.cs index 2b8f129a7d..e7892a65fb 100644 --- a/src/MaaWpfGui/Services/RemoteControl/RemoteControlService.cs +++ b/src/MaaWpfGui/Services/RemoteControl/RemoteControlService.cs @@ -18,6 +18,7 @@ using System.IO; using System.Linq; using System.Net.Http; using System.Reflection; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -694,7 +695,7 @@ namespace MaaWpfGui.Services.RemoteControl { var endpoint = Instances.SettingsViewModel.RemoteControlGetTaskEndpointUri; - if (!IsEndpointValid(endpoint)) + if (!IsEndpointValid(endpoint, alarm: true)) { return; } @@ -755,12 +756,11 @@ namespace MaaWpfGui.Services.RemoteControl Instances.SettingsViewModel.RemoteControlDeviceIdentity = Guid.NewGuid().ToString("N"); } - public static bool IsEndpointValid(string endpoint) + public static bool IsEndpointValid(string endpoint, bool alarm = false) { if (string.IsNullOrWhiteSpace(endpoint)) { - using var toast = new ToastNotification(LocalizationHelper.GetString("RemoteControlConnectionTestFailEmpty")); - toast.Show(); + ShowToast("RemoteControlConnectionTestFailEmpty", alarm); return false; } @@ -772,16 +772,23 @@ namespace MaaWpfGui.Services.RemoteControl } else if (lowerEndpoint.StartsWith("http://")) { - using var toast = new ToastNotification(LocalizationHelper.GetString("RemoteControlConnectionTestWarningHttpUnsafe")); - toast.Show(); + ShowToast("RemoteControlConnectionTestWarningHttpUnsafe", alarm); return true; } else { - using var toast = new ToastNotification(LocalizationHelper.GetString("RemoteControlConnectionTestFailNotHttpOrHttps")); - toast.Show(); + ShowToast("RemoteControlConnectionTestFailNotHttpOrHttps", alarm); return false; } } + + public static void ShowToast(string message, bool alarm) + { + if (alarm) + { + using var toast = new ToastNotification(LocalizationHelper.GetString(message)); + toast.Show(); + } + } } }