mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-18 18:20:39 +08:00
修复了检测网络的相关问题
This commit is contained in:
@@ -676,7 +676,7 @@ The video aspect ratio needs to be 16:9 without interference factors such as bla
|
||||
<system:String x:Key="RemoteControlGetTaskEndpointLabel">Get Task Endpoint</system:String>
|
||||
<system:String x:Key="RemoteControlReportStatusEndpointLabel">Report Task Endpoint</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestSuccess">Connection Test Successful!</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFail">Connection Test Failed.</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFail">Connection Test Failed, reason: {0}.</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFailEmpty">Connection Test Failed, Endpoint is empty.</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFailNotHttps">Connection Test Failed. Endpoint is not an https address.</system:String>
|
||||
<system:String x:Key="RemoteControlReceivedTask">Received remote task {0}, Task Id:{1}.</system:String>
|
||||
|
||||
@@ -676,7 +676,7 @@ Bilibili: ログイン インターフェイスに表示されるアカウント
|
||||
<system:String x:Key="RemoteControlGetTaskEndpointLabel">タスクエンドポイントの取得</system:String>
|
||||
<system:String x:Key="RemoteControlReportStatusEndpointLabel">タスクステータスの報告エンドポイント</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestSuccess">接続テスト成功!</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFail">接続テスト失敗。</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFail">接続テスト失敗、理由: {0}。</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFailEmpty">接続テスト失敗、エンドポイントが空です。</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFailNotHttps">接続テスト失敗。エンドポイントはhttpsアドレスではありません。</system:String>
|
||||
<system:String x:Key="RemoteControlReceivedTask">リモートタスク{0}を受信、タスクId:{1}。</system:String>
|
||||
|
||||
@@ -676,7 +676,7 @@ Bilibili: 로그인 인터페이스에 표시되는 계정 이름(예: 장산)
|
||||
<system:String x:Key="RemoteControlGetTaskEndpointLabel">작업 엔드포인트 가져오기</system:String>
|
||||
<system:String x:Key="RemoteControlReportStatusEndpointLabel">작업 상태 보고 엔드포인트</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestSuccess">연결 테스트 성공!</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFail">연결 테스트 실패.</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFail">연결 테스트 실패, 이유: {0}.</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFailEmpty">연결 테스트 실패, 엔드포인트가 비어 있습니다.</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFailNotHttps">연결 테스트 실패. 엔드포인트가 https 주소가 아닙니다.</system:String>
|
||||
<system:String x:Key="RemoteControlReceivedTask">원격 작업 {0} 받음, 작업 Id:{1}.</system:String>
|
||||
|
||||
@@ -676,7 +676,7 @@
|
||||
<system:String x:Key="RemoteControlGetTaskEndpointLabel">获取任务端点</system:String>
|
||||
<system:String x:Key="RemoteControlReportStatusEndpointLabel">汇报任务端点</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestSuccess">连接测试成功!</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFail">连接测试失败。</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFail">连接测试失败,原因: {0}。</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFailEmpty">连接测试失败,连接端点为空。</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFailNotHttps">连接测试失败。端点不是https地址。</system:String>
|
||||
<system:String x:Key="RemoteControlReceivedTask">收到远端任务{0},任务Id:{1}。</system:String>
|
||||
|
||||
@@ -676,7 +676,7 @@
|
||||
<system:String x:Key="RemoteControlGetTaskEndpointLabel">獲取任務端點</system:String>
|
||||
<system:String x:Key="RemoteControlReportStatusEndpointLabel">匯報任務端點</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestSuccess">連接測試成功!</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFail">連接測試失敗。</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFail">連接測試失敗,原因: {0}。</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFailEmpty">連接測試失敗,連接端點為空。</system:String>
|
||||
<system:String x:Key="RemoteControlConnectionTestFailNotHttps">連接測試失敗。端點非https地址。</system:String>
|
||||
<system:String x:Key="RemoteControlReceivedTask">收到遠端任務{0},任務Id:{1}。</system:String>
|
||||
|
||||
@@ -3,18 +3,22 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
using MaaWpfGui.Constants;
|
||||
using MaaWpfGui.Helper;
|
||||
using MaaWpfGui.Services.Web;
|
||||
using MaaWpfGui.States;
|
||||
using MaaWpfGui.ViewModels.UI;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serilog;
|
||||
using Windows.Media.Protection.PlayReady;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace MaaWpfGui.Services.RemoteControl
|
||||
@@ -70,6 +74,34 @@ namespace MaaWpfGui.Services.RemoteControl
|
||||
|
||||
#region Private Method Invoker
|
||||
|
||||
private static T GetPrivateFieldValue<T>(object instance, string fieldName)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(instance));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(fieldName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fieldName));
|
||||
}
|
||||
|
||||
Type type = instance.GetType();
|
||||
FieldInfo fieldInfo = type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
if (fieldInfo == null)
|
||||
{
|
||||
throw new ArgumentException($"Field '{fieldName}' not found in type '{type.FullName}'.");
|
||||
}
|
||||
|
||||
if (!typeof(T).IsAssignableFrom(fieldInfo.FieldType))
|
||||
{
|
||||
throw new ArgumentException($"Field '{fieldName}' is not of type {typeof(T)}.");
|
||||
}
|
||||
|
||||
return (T)fieldInfo.GetValue(instance);
|
||||
}
|
||||
|
||||
private static void InvokeInstanceMethod(object instance, string methodName)
|
||||
{
|
||||
if (instance == null)
|
||||
@@ -500,14 +532,52 @@ namespace MaaWpfGui.Services.RemoteControl
|
||||
|
||||
var uid = Instances.SettingsViewModel.RemoteControlUserIdentity;
|
||||
var did = Instances.SettingsViewModel.RemoteControlDeviceIdentity;
|
||||
var response = await Instances.HttpService.PostAsJsonAsync(new Uri(endpoint), new { user = uid, device = did });
|
||||
|
||||
using var toast = new ToastNotification(
|
||||
LocalizationHelper.GetString(
|
||||
response != null ? "RemoteControlConnectionTestSuccess" : "RemoteControlConnectionTestFail"));
|
||||
try
|
||||
{
|
||||
var body = System.Text.Json.JsonSerializer.Serialize(new { user = uid, device = did });
|
||||
var message = new HttpRequestMessage(HttpMethod.Post, endpoint);
|
||||
message.Headers.Accept.ParseAdd("application/json");
|
||||
message.Content = new StringContent(body, Encoding.UTF8, "application/json");
|
||||
|
||||
toast.Show();
|
||||
var client = GetPrivateFieldValue<HttpClient>(Instances.HttpService, "_client");
|
||||
var response = await client.SendAsync(message);
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var errorMsg = string.Format(LocalizationHelper.GetString("RemoteControlConnectionTestFail"), response.StatusCode);
|
||||
using var toastFail = new ToastNotification(errorMsg);
|
||||
toastFail.Show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 一般来说不会走到这里,因为null response一定会报错
|
||||
var errorMsg = string.Format(LocalizationHelper.GetString("RemoteControlConnectionTestFail"), "Unknown");
|
||||
using var toastFail = new ToastNotification(errorMsg);
|
||||
toastFail.Show();
|
||||
return;
|
||||
}
|
||||
|
||||
using var toastSuccess = new ToastNotification(
|
||||
LocalizationHelper.GetString("RemoteControlConnectionTestSuccess"));
|
||||
toastSuccess.Show();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var error = e.Message;
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
error = e.InnerException.Message;
|
||||
}
|
||||
var errorMsg = string.Format(LocalizationHelper.GetString("RemoteControlConnectionTestFail"), error);
|
||||
using var toastErr = new ToastNotification(errorMsg);
|
||||
|
||||
toastErr.Show();
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegenerateDeviceIdentity()
|
||||
|
||||
Reference in New Issue
Block a user