mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 09:50:40 +08:00
perf: 优化检测连接的逻辑,不再每次重置连接
This commit is contained in:
@@ -988,9 +988,8 @@ namespace MeoAsstGui
|
||||
/// 连接模拟器。
|
||||
/// </summary>
|
||||
/// <param name="error">具体的连接错误。</param>
|
||||
/// <param name="first_try">是否为第一次尝试。</param>
|
||||
/// <returns>是否成功。</returns>
|
||||
public bool AsstConnect(ref string error, bool first_try = false)
|
||||
public bool AsstConnect(ref string error)
|
||||
{
|
||||
if (!LoadGlobalResource())
|
||||
{
|
||||
@@ -999,28 +998,29 @@ namespace MeoAsstGui
|
||||
}
|
||||
|
||||
var settings = _container.Get<SettingsViewModel>();
|
||||
if (connected
|
||||
|
||||
settings.TryToSetBlueStacksHyperVAddress();
|
||||
|
||||
if (!settings.AutoDetectConnection
|
||||
&& connected
|
||||
&& connectedAdb == settings.AdbPath
|
||||
&& connectedAddress == settings.ConnectAddress)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (settings.AdbPath == string.Empty ||
|
||||
settings.ConnectAddress == string.Empty)
|
||||
if (settings.AutoDetectConnection)
|
||||
{
|
||||
if (!settings.RefreshAdbConfig(ref error))
|
||||
if (!settings.DetectAdbConfig(ref error))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
settings.TryToSetBlueStacksHyperVAddress();
|
||||
|
||||
bool ret = AsstConnect(_handle, settings.AdbPath, settings.ConnectAddress, settings.ConnectConfig);
|
||||
|
||||
// 尝试默认的备选端口
|
||||
if (!ret)
|
||||
if (!ret && settings.AutoDetectConnection)
|
||||
{
|
||||
foreach (var address in settings.DefaultAddress[settings.ConnectConfig])
|
||||
{
|
||||
@@ -1038,16 +1038,13 @@ namespace MeoAsstGui
|
||||
}
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
if (ret)
|
||||
{
|
||||
if (first_try)
|
||||
{
|
||||
error = Localization.GetString("ConnectFailed") + "\n" + Localization.GetString("TryToStartEmulator");
|
||||
}
|
||||
else
|
||||
{
|
||||
error = Localization.GetString("ConnectFailed") + "\n" + Localization.GetString("CheckSettings");
|
||||
}
|
||||
settings.AutoDetectConnection = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
error = Localization.GetString("ConnectFailed") + "\n" + Localization.GetString("CheckSettings");
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -149,7 +149,8 @@
|
||||
<system:String x:Key="CustomStageCode">Manual entry of level names</system:String>
|
||||
<system:String x:Key="CustomStageCodeTip">Support all main line level names + level names from the original list (e.g. 4-10, 6-16, etc.)</system:String>
|
||||
|
||||
<system:String x:Key="ADBTip">Tip: It will be automatically detected here. If there is an error, you can try to modify it again, otherwise you do not need to fill in it yourself</system:String>
|
||||
<system:String x:Key="AutoDetectConnection">Auto detect connection</system:String>
|
||||
<system:String x:Key="AutoDetectConnectionTip">The checkbox will be automatically unchecked after each detect is completed, and can be checked again if you need to re-detect</system:String>
|
||||
<system:String x:Key="ADBPath">ADB path (rel/abs)</system:String>
|
||||
<system:String x:Key="ConnectionAddress">Connection address</system:String>
|
||||
<system:String x:Key="ConnectionAddressTip">It will be filled in automatically when you use it for the first time. If you encounter any problems, you can try to manually modify it</system:String>
|
||||
|
||||
@@ -160,7 +160,7 @@
|
||||
<system:String x:Key="ADBTip">ヒント:接続時に自動的に検出されますが、エラーが発生した場合は変更を試みることができます。通常は自分で入力する必要はありません。</system:String>
|
||||
<system:String x:Key="ADBPath">adbパス(相対/絶対)</system:String>
|
||||
<system:String x:Key="ConnectionAddress">接続先アドレス</system:String>
|
||||
<system:String x:Key="ConnectionAddressTip">初めて使用した際に自動で記入されますが、問題があれば手動で修正してください。</system:String>
|
||||
<system:String x:Key="ConnectionAddressTip">問題があれば手動で修正してください。</system:String>
|
||||
<system:String x:Key="ConnectionPreset">接続構成</system:String>
|
||||
<system:String x:Key="RetryOnDisconnected">adb再接続失敗時にエミュレータを自動で再起動</system:String>
|
||||
<system:String x:Key="RetryOnDisconnectedTip">再接続に20回失敗した後、エミュレータを再起動してみてください,バックグラウンドのタイムドタスクを使用し、終了時にエミュレータを終了させるタスクを設定する場合は、必ずチェックを入れること</system:String>
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
<system:String x:Key="ADBTip">팁: 여기에서 자동으로 감지됩니다. 오류가 있는 경우 다시 수정을 시도할 수 있습니다. 그렇지 않으면 직접 입력할 필요가 없습니다.</system:String>
|
||||
<system:String x:Key="ADBPath">adb 경로 (상대/절대)</system:String>
|
||||
<system:String x:Key="ConnectionAddress">연결 주소</system:String>
|
||||
<system:String x:Key="ConnectionAddressTip">처음 사용할 때는 자동으로 작성되며, 문제가 있으면 수동으로 수정하십시오</system:String>
|
||||
<system:String x:Key="ConnectionAddressTip">문제가 있으면 수동으로 수정하십시오</system:String>
|
||||
<system:String x:Key="ConnectionPreset">연결 사전 설정</system:String>
|
||||
<system:String x:Key="RetryOnDisconnected">adb 재연결이 실패하면 자동으로 에뮬레이터를 다시 시작합니다</system:String>
|
||||
<system:String x:Key="RetryOnDisconnectedTip">20번의 재연결 실패 후 에뮬레이터를 다시 시작하십시오, 백그라운드 시간 지정 작업을 사용하고 작업이 완료되면 시뮬레이터를 닫도록 설정하려면 다음을 선택해야 합니다</system:String>
|
||||
|
||||
@@ -155,13 +155,14 @@
|
||||
<system:String x:Key="CustomStageCode">手动输入关卡名</system:String>
|
||||
<system:String x:Key="CustomStageCodeTip">支持所有主线关卡名 + 原列表中的关卡名(如 4-10、6-16 等)</system:String>
|
||||
|
||||
<system:String x:Key="ADBTip">小提示:这里会自动检测的,若出现问题可再尝试修改,否则不需要自行填写</system:String>
|
||||
<system:String x:Key="AutoDetectConnection">自动检测连接</system:String>
|
||||
<system:String x:Key="AutoDetectConnectionTip">每次检测完成后会自动取消勾选,若需要重新检测可再次勾选</system:String>
|
||||
<system:String x:Key="ADBPath">adb 路径 (相对/绝对)</system:String>
|
||||
<system:String x:Key="ConnectionAddress">连接地址</system:String>
|
||||
<system:String x:Key="ConnectionAddressTip">第一次使用会自动填写,若遇到问题可尝试手动修改</system:String>
|
||||
<system:String x:Key="ConnectionAddressTip">若遇到问题可尝试手动修改</system:String>
|
||||
<system:String x:Key="ConnectionPreset">连接配置</system:String>
|
||||
<system:String x:Key="RetryOnDisconnected">adb 重连失败时自动重启模拟器</system:String>
|
||||
<system:String x:Key="RetryOnDisconnectedTip">重连失败 20 次后尝试重启模拟器,使用后台定时任务且设置任务完成关闭模拟器时必须勾选</system:String>
|
||||
<system:String x:Key="RetryOnDisconnectedTip">重连失败 20 次后尝试重启模拟器,使用后台定时任务且设置任务完成关闭模拟器时请勾选</system:String>
|
||||
<!-- 设置 -->
|
||||
|
||||
<!-- 一键长草 -->
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
<system:String x:Key="ADBTip">小提示:這裡會自動檢測的,若出現問題可再嘗試修改,否則不需要自行填寫</system:String>
|
||||
<system:String x:Key="ADBPath">adb 路徑 (相對/絕對)</system:String>
|
||||
<system:String x:Key="ConnectionAddress">連接地址</system:String>
|
||||
<system:String x:Key="ConnectionAddressTip">第一次使用會自動填寫,若遇到問題可嘗試手動修改</system:String>
|
||||
<system:String x:Key="ConnectionAddressTip">若遇到問題可嘗試手動修改</system:String>
|
||||
<system:String x:Key="ConnectionPreset">連接配置</system:String>
|
||||
<system:String x:Key="RetryOnDisconnected">adb 重連失敗時自動重啟模擬器</system:String>
|
||||
<system:String x:Key="RetryOnDisconnectedTip">重連失敗 20 次後嘗試重啟模擬器,使用後台定時任務且設置任務完成關閉模擬器時必須勾選</system:String>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding"
|
||||
xmlns:dd="urn:gong-wpf-dragdrop"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
@@ -24,14 +25,15 @@
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock
|
||||
<CheckBox
|
||||
Grid.Row="0"
|
||||
Grid.ColumnSpan="3"
|
||||
Margin="10"
|
||||
Block.TextAlignment="Center"
|
||||
Style="{StaticResource TextBlockDefault}"
|
||||
Text="{DynamicResource ADBTip}"
|
||||
TextWrapping="Wrap" />
|
||||
Grid.ColumnSpan="2"
|
||||
Margin="15"
|
||||
VerticalAlignment="Center"
|
||||
IsChecked="{Binding AutoDetectConnection}"
|
||||
Content="{DynamicResource AutoDetectConnection}"
|
||||
ToolTip="{DynamicResource AutoDetectConnectionTip}"
|
||||
HorizontalAlignment="Center" />
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
@@ -46,6 +48,7 @@
|
||||
Width="250"
|
||||
Height="30"
|
||||
Margin="10"
|
||||
IsEnabled="{c:Binding !AutoDetectConnection}"
|
||||
Text="{Binding AdbPath}" />
|
||||
<Button
|
||||
Grid.Row="1"
|
||||
@@ -53,6 +56,7 @@
|
||||
Width="60"
|
||||
Height="30"
|
||||
Margin="10"
|
||||
IsEnabled="{c:Binding !AutoDetectConnection}"
|
||||
HorizontalAlignment="Left"
|
||||
Command="{s:Action SelectFile}"
|
||||
Content="{DynamicResource Select}" />
|
||||
@@ -71,6 +75,7 @@
|
||||
Width="250"
|
||||
Height="30"
|
||||
Margin="10"
|
||||
IsEnabled="{c:Binding !AutoDetectConnection}"
|
||||
Text="{Binding ConnectAddress}"
|
||||
ToolTip="{DynamicResource ConnectionAddressTip}" />
|
||||
|
||||
@@ -89,13 +94,14 @@
|
||||
Height="30"
|
||||
Margin="10"
|
||||
DisplayMemberPath="Display"
|
||||
IsEnabled="{c:Binding !AutoDetectConnection}"
|
||||
ItemsSource="{Binding ConnectConfigList}"
|
||||
SelectedValue="{Binding ConnectConfig}"
|
||||
SelectedValuePath="Value" />
|
||||
|
||||
<CheckBox
|
||||
Grid.Row="4"
|
||||
Grid.ColumnSpan="3"
|
||||
Grid.ColumnSpan="2"
|
||||
Margin="15"
|
||||
VerticalAlignment="Center"
|
||||
IsChecked="{Binding RetryOnDisconnected}"
|
||||
|
||||
@@ -1426,6 +1426,18 @@ namespace MeoAsstGui
|
||||
|
||||
/* 连接设置 */
|
||||
|
||||
private bool _autoDetectConnection = bool.Parse(ViewStatusStorage.Get("Connect.AutoDetect", true.ToString()));
|
||||
|
||||
public bool AutoDetectConnection
|
||||
{
|
||||
get => _autoDetectConnection;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _autoDetectConnection, value);
|
||||
ViewStatusStorage.Set("Connect.AutoDetect", value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private string _connectAddress = ViewStatusStorage.Get("Connect.Address", string.Empty);
|
||||
|
||||
/// <summary>
|
||||
@@ -1508,7 +1520,7 @@ namespace MeoAsstGui
|
||||
/// </summary>
|
||||
/// <param name="error">Errors when doing this operation.</param>
|
||||
/// <returns>Whether the operation is successful.</returns>
|
||||
public bool RefreshAdbConfig(ref string error)
|
||||
public bool DetectAdbConfig(ref string error)
|
||||
{
|
||||
var adapter = new WinAdapter();
|
||||
List<string> emulators;
|
||||
|
||||
@@ -628,7 +628,7 @@ namespace MeoAsstGui
|
||||
string errMsg = string.Empty;
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
return asstProxy.AsstConnect(ref errMsg, true);
|
||||
return asstProxy.AsstConnect(ref errMsg);
|
||||
});
|
||||
bool caught = await task;
|
||||
|
||||
@@ -641,6 +641,7 @@ namespace MeoAsstGui
|
||||
if (!caught)
|
||||
{
|
||||
AddLog(errMsg, LogColor.Error);
|
||||
AddLog(Localization.GetString("ConnectFailed") + "\n" + Localization.GetString("TryToStartEmulator"));
|
||||
var settingsModel = _container.Get<SettingsViewModel>();
|
||||
var subtask = Task.Run(() =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user