feat: 支持连接失败重启 ADB

This commit is contained in:
uye
2023-05-27 18:06:13 +08:00
parent a98625cdf6
commit 37ebcc0d0c
10 changed files with 102 additions and 20 deletions

View File

@@ -55,6 +55,7 @@ namespace MaaWpfGui.Constants
public const string AdbPath = "Connect.AdbPath";
public const string ConnectConfig = "Connect.ConnectConfig";
public const string RetryOnAdbDisconnected = "Connect.RetryOnDisconnected";
public const string AllowADBRestart = "Connect.AllowADBRestart";
public const string AdbLiteEnabled = "Connect.AdbLiteEnabled";
public const string KillAdbOnExit = "Connect.KillAdbOnExit";
public const string TouchMode = "Connect.TouchMode";

View File

@@ -443,7 +443,7 @@ namespace MaaWpfGui.Main
if (Instances.SettingsViewModel.RetryOnDisconnected)
{
Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("TryToStartEmulator"), UiLogColor.Error);
Instances.TaskQueueViewModel.KillEmulator();
Instances.TaskQueueViewModel.KillEmulatorModeSwitcher();
await Task.Delay(3000);
await Instances.TaskQueueViewModel.Stop();
Instances.TaskQueueViewModel.SetStopped();

View File

@@ -90,7 +90,7 @@
<system:String x:Key="StartingRoles">Starting Roles</system:String>
<system:String x:Key="StartingCoreChar">Starting Oper (single, CN name only)</system:String>
<system:String x:Key="StartingCoreCharTip">Only supports the CN name of a single oper, default if not filled.</system:String>
<system:String x:Key="RoguelikeUseSupportUnit">Select "Starting Oper" from support unit list</system:String>
<system:String x:Key="RoguelikeUseSupportUnit">Select &quot;Starting Oper&quot; from support unit list</system:String>
<system:String x:Key="RoguelikeUseNonFriendSupport">Enable nonfirend support</system:String>
<system:String x:Key="DeploymentWithPause" xml:space="preserve">Deployment with Pause, Works for IS, Copilot and SSS,\nBeta function, Not recommended yet</system:String>
<system:String x:Key="AdbLiteEnabled">Use Adb Lite (Experimental)</system:String>
@@ -265,7 +265,7 @@
<system:String x:Key="CustomInfrastPlanShowInFightSettings">Show Base Plan</system:String>
<system:String x:Key="MainViewButtonFeature">Variable function button</system:String>
<system:String x:Key="CustomStageCode">Manual entry of level names</system:String>
<system:String x:Key="CustomStageCodeTip" xml:space="preserve">Support most main stage names + stage names from the original list (e.g. 4-10, AP-5, H10-1-Hard, etc.)&#x0a;At the end of the level, enter "Normal/Hard" to switch between Normal and Tough difficulty</system:String>
<system:String x:Key="CustomStageCodeTip" xml:space="preserve">Support most main stage names + stage names from the original list (e.g. 4-10, AP-5, H10-1-Hard, etc.)&#x0a;At the end of the level, enter &quot;Normal/Hard&quot; to switch between Normal and Tough difficulty</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>
@@ -276,6 +276,7 @@
<system:String x:Key="ConnectionPreset">Connection Preset</system:String>
<system:String x:Key="RetryOnDisconnected">Auto restart emulator when adb reconnection fails</system:String>
<system:String x:Key="RetryOnDisconnectedTip">Try restarting the emulator after 20 failed reconnect attempts, Must be checked when using a background timed task and setting the task to close the emulator when finished</system:String>
<system:String x:Key="AllowADBRestart">Attempt to restart ADB after connection failure</system:String>
<!-- Settings -->
<!-- Farming -->
@@ -391,7 +392,7 @@
<system:String x:Key="RecruitmentRecognitionTip">Tip: This recognition is independent from main tab (Farming); need open up in game recruit tag selection screen then begin ~</system:String>
<system:String x:Key="AutoSettingTime">Auto setting time</system:String>
<system:String x:Key="RecruitmentShowPotential">Show Potential</system:String>
<system:String x:Key="RecruitmentShowPotentialTips">Please use the "Operator" to get information</system:String>
<system:String x:Key="RecruitmentShowPotentialTips">Please use the &quot;Operator&quot; to get information</system:String>
<system:String x:Key="AutoSelectLevel3Tags">Auto select 3 ★ Tags</system:String>
<system:String x:Key="AutoSelectLevel4Tags">Auto select 4 ★ Tags</system:String>
<system:String x:Key="AutoSelectLevel5Tags">Auto select 5 ★ Tags</system:String>
@@ -420,7 +421,7 @@
<system:String x:Key="VideoRecognition">Video</system:String>
<system:String x:Key="StartToVideoRecognition">Start to identify</system:String>
<system:String x:Key="OpenVideoRecognitionResult">Open Directory</system:String>
<system:String x:Key="VideoRecognitionTips" xml:space="preserve">For video recognition, please open the "Copilot" page and drag the strategy video into it.
<system:String x:Key="VideoRecognitionTips" xml:space="preserve">For video recognition, please open the &quot;Copilot&quot; page and drag the strategy video into it.
The video resolution is required to be 16:9, and there are no interference factors such as black borders, emulator borders, and special-shaped screen corrections.</system:String>
<!-- Video Recognition -->
@@ -465,7 +466,7 @@ The video resolution is required to be 16:9, and there are no interference facto
<system:String x:Key="ThanksForLikeWebJson">Thanks for the likes!\nThe comment section is already open on the web page, please feel free to leave your comment!</system:String>
<system:String x:Key="AutoSquad">Auto squad</system:String>
<system:String x:Key="LoopTimes">LoopTimes</system:String>
<system:String x:Key="AutoSquadTip">The operator of "special focus" cannot be identified at this time</system:String>
<system:String x:Key="AutoSquadTip">The operator of &quot;special focus&quot; cannot be identified at this time</system:String>
<system:String x:Key="Start">Start</system:String>
@@ -474,11 +475,11 @@ The video resolution is required to be 16:9, and there are no interference facto
<!-- Logs -->
<system:String x:Key="CopilotTip">
Tips\n\n
1. Please use this function only when "Start" is visible in game.\n\n
2. You need turn off the "Auto squad" if using friend support unit, then start with your support unit selected.\n\n
3. For Paradox Simulation, you need to turn off "Auto squad" and select the skill before, then start in game "start" screen.\n\n
1. Please use this function only when &quot;Start&quot; is visible in game.\n\n
2. You need turn off the &quot;Auto squad&quot; if using friend support unit, then start with your support unit selected.\n\n
3. For Paradox Simulation, you need to turn off &quot;Auto squad&quot; and select the skill before, then start in game &quot;start&quot; screen.\n\n
4. For SSS, There are multiple built-in files under the resource/copilot folder.\n
Please start on the "Start Deployment" screen after manual formation (can be used with "Loop times")\n\n
Please start on the &quot;Start Deployment&quot; screen after manual formation (can be used with &quot;Loop times&quot;)\n\n
5. Video recognition is now supported, please drag the guide video to use. \n
The video resolution is required to be 16:9, and there are no distracting elements such as black borders, emulator borders, and special-shaped screen corrections.\n\n
</system:String>
@@ -584,6 +585,7 @@ The video resolution is required to be 16:9, and there are no interference facto
<system:String x:Key="RecruitTagsDetected" xml:space="preserve">Identify results: </system:String>
<system:String x:Key="ConnectFailed">Connection Failed</system:String>
<system:String x:Key="TryToStartEmulator">Trying to start the emulator</system:String>
<system:String x:Key="RestartADB">Trying to restart the ADB</system:String>
<system:String x:Key="CheckSettings">Please check your connection settings or try restarting the emulator and ADB, or restart your computer</system:String>
<!-- AsstProxy -->
@@ -620,7 +622,7 @@ The video resolution is required to be 16:9, and there are no interference facto
<!-- AutoRecruitSettings -->
<!-- EasterEggs -->
<system:String x:Key="BuyWineOnAprilFoolsDay">Dear doctor, ever heard of the new listings of "isopropyl alcohol" in Ms. Closure's store? let's check it out?</system:String>
<system:String x:Key="BuyWineOnAprilFoolsDay">Dear doctor, ever heard of the new listings of &quot;isopropyl alcohol&quot; in Ms. Closure's store? let's check it out?</system:String>
<system:String x:Key="Burping">Ugh... Ehem</system:String>
<system:String x:Key="DrunkAndStaggering">Ah, doctor. Why do you sway, so much in your movement today?</system:String>
<system:String x:Key="Hangover">I must not drink, drink so much next time...</system:String>

View File

@@ -90,7 +90,7 @@
<system:String x:Key="StartingRoles">最初の職業</system:String>
<system:String x:Key="StartingCoreChar">最初のオペレーター(一人だけ、中国名のみを入力可能)</system:String>
<system:String x:Key="StartingCoreCharTip">一人のオペレーターの中国名のみをサポートします。入力されていない場合はデフォルトになります。</system:String>
<system:String x:Key="RoguelikeUseSupportUnit">"最初のオペレーター"をサポートから選択</system:String>
<system:String x:Key="RoguelikeUseSupportUnit">&quot;最初のオペレーター&quot;をサポートから選択</system:String>
<system:String x:Key="RoguelikeUseNonFriendSupport">フレンド以外のサポートの使用を許可</system:String>
<system:String x:Key="DeploymentWithPause">統合戦略/保全駐在でポーズトリックを使用します(ベータ機能のため非推奨です)</system:String>
<system:String x:Key="AdbLiteEnabled">軽量Adbを使用(実験機能)</system:String>
@@ -259,7 +259,7 @@
<system:String x:Key="CustomInfrastPlanShowInFightSettings">基地計画を表示する</system:String>
<system:String x:Key="MainViewButtonFeature">スタート画面に表示する便利ボタン</system:String>
<system:String x:Key="CustomStageCode">ステージ名を入力する</system:String>
<system:String x:Key="CustomStageCodeTip" xml:space="preserve">(テスト機能)ステージ名と番号4-10、AP-5、H10-1-Hardなど&#x0a;の両方がサポートされています。レベルの最後に"Normal/Hard"を入力することで、標準から強襲/厄難に難易度を切り替えることができます。</system:String>
<system:String x:Key="CustomStageCodeTip" xml:space="preserve">(テスト機能)ステージ名と番号4-10、AP-5、H10-1-Hardなど&#x0a;の両方がサポートされています。レベルの最後に&quot;Normal/Hard&quot;を入力することで、標準から強襲/厄難に難易度を切り替えることができます。</system:String>
<system:String x:Key="AutoDetectConnection">接続自動認識</system:String>
<system:String x:Key="AutoDetectConnectionTip">このチェックボックスは、検出が完了するたびに自動的にチェックが外れますが、再検出が必要な場合は再度チェックを入れることができます</system:String>
@@ -270,6 +270,7 @@
<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="AllowADBRestart">接続失敗後にADBの再起動を試みる</system:String>
<!-- 設定 -->
<!-- スタート -->
@@ -574,6 +575,7 @@
<system:String x:Key="RecruitTagsDetected">認識結果:</system:String>
<system:String x:Key="ConnectFailed">接続失敗</system:String>
<system:String x:Key="TryToStartEmulator">エミュレータを起動しようとしています</system:String>
<system:String x:Key="RestartADB">ADBの再起動を試みています</system:String>
<system:String x:Key="CheckSettings">接続設定を確認するか、エミュレータとADBを再起動するか、コンピューターを再起動してください</system:String>
<!-- Recruitment Results: -->

View File

@@ -259,7 +259,7 @@
<system:String x:Key="CustomInfrastPlanShowInFightSettings">기반시설 계획 표시</system:String>
<system:String x:Key="MainViewButtonFeature">메인 화면 버튼의 기능</system:String>
<system:String x:Key="CustomStageCode">스테이지 코드 수동 입력</system:String>
<system:String x:Key="CustomStageCodeTip" xml:space="preserve">대부분의 메인 스테이지와 원래 목록(예: 4-10, AP-5, H10-1-Hard)에 있는 스테이지 이름을 지원합니다.&#x0a; 레벨 끝에서 "Normal / Hard"를 입력하여 일반 및 터프 난이도 간 전환</system:String>
<system:String x:Key="CustomStageCodeTip" xml:space="preserve">대부분의 메인 스테이지와 원래 목록(예: 4-10, AP-5, H10-1-Hard)에 있는 스테이지 이름을 지원합니다.&#x0a; 레벨 끝에서 &quot;Normal / Hard&quot;를 입력하여 일반 및 터프 난이도 간 전환</system:String>
<system:String x:Key="AutoDetectConnection">연결 자동 감지</system:String>
<system:String x:Key="AutoDetectConnectionTip">이 체크박스는 감지가 끝나면 자동으로 체크가 해제됩니다. 다시 감지하려면 다시 체크해주세요.</system:String>
@@ -270,6 +270,7 @@
<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="AllowADBRestart">연결 실패 후 ADB 재시작 시도</system:String>
<!-- 설정 -->
<!-- 자동화 -->
@@ -575,6 +576,7 @@
<system:String x:Key="RecruitTagsDetected">인식 결과:</system:String>
<system:String x:Key="ConnectFailed">연결 실패</system:String>
<system:String x:Key="TryToStartEmulator">에뮬레이터를 시작하는 중입니다</system:String>
<system:String x:Key="RestartADB">ADB 재시작을 시도 중입니다</system:String>
<system:String x:Key="CheckSettings">연결 설정을 확인하거나 에뮬레이터와 ADB를 다시 시작하거나 컴퓨터를 재시작해주세요.</system:String>
<!-- Current step: {0} {1} -->

View File

@@ -265,7 +265,7 @@
<system:String x:Key="CustomInfrastPlanShowInFightSettings">显示基建计划</system:String>
<system:String x:Key="MainViewButtonFeature">主界面可选择按钮功能</system:String>
<system:String x:Key="CustomStageCode">手动输入关卡名</system:String>
<system:String x:Key="CustomStageCodeTip" xml:space="preserve">支持大部分主线关卡名与原列表的关卡名如4-10、AP-5、H10-1-Hard&#x0a;可在关卡结尾输入"Normal/Hard"表示需要切换标准与磨难难度</system:String>
<system:String x:Key="CustomStageCodeTip" xml:space="preserve">支持大部分主线关卡名与原列表的关卡名如4-10、AP-5、H10-1-Hard&#x0a;可在关卡结尾输入&quot;Normal/Hard&quot;表示需要切换标准与磨难难度</system:String>
<system:String x:Key="AutoDetectConnection">自动检测连接</system:String>
<system:String x:Key="AutoDetectConnectionTip">每次检测完成后会自动取消勾选,若需要重新检测可再次勾选,若反复连接失败可勾选始终自动检测连接</system:String>
@@ -276,6 +276,7 @@
<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="AllowADBRestart">连接失败后尝试重启 ADB</system:String>
<!-- 设置 -->
<!-- 一键长草 -->
@@ -584,6 +585,7 @@
<system:String x:Key="RecruitTagsDetected">识别结果:</system:String>
<system:String x:Key="ConnectFailed">连接失败</system:String>
<system:String x:Key="TryToStartEmulator">正在尝试启动模拟器</system:String>
<system:String x:Key="RestartADB">正在尝试重启 ADB</system:String>
<system:String x:Key="CheckSettings">请检查连接设置或尝试重启模拟器与 ADB 或重启电脑</system:String>
<!-- AsstProxy -->

View File

@@ -259,7 +259,7 @@
<system:String x:Key="CustomInfrastPlanShowInFightSettings">顯示基建計劃</system:String>
<system:String x:Key="MainViewButtonFeature">主介面可選擇按鈕功能</system:String>
<system:String x:Key="CustomStageCode">手動輸入關卡代名</system:String>
<system:String x:Key="CustomStageCodeTip" xml:space="preserve">支持大部分主線關卡名與原列表的關卡名如4-10、AP-5、H10-1-Hard&#x0a;可在關卡結尾輸入"Normal/Hard"表示需要切換標準與磨難難度</system:String>
<system:String x:Key="CustomStageCodeTip" xml:space="preserve">支持大部分主線關卡名與原列表的關卡名如4-10、AP-5、H10-1-Hard&#x0a;可在關卡結尾輸入&quot;Normal/Hard&quot;表示需要切換標準與磨難難度</system:String>
<system:String x:Key="AutoDetectConnection">自動檢測連接</system:String>
<system:String x:Key="AutoDetectConnectionTip">每次檢測完成後會自動取消勾選,若需要重新檢測可再次勾選</system:String>
@@ -270,6 +270,7 @@
<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="AllowADBRestart">連接失敗後嘗試重啟 ADB</system:String>
<!-- 設定 -->
<!-- 一鍵長草 -->
@@ -577,6 +578,7 @@
<system:String x:Key="RecruitTagsDetected">辨識結果:</system:String>
<system:String x:Key="ConnectFailed">連接失敗</system:String>
<system:String x:Key="TryToStartEmulator">正在嘗試啟動模擬器</system:String>
<system:String x:Key="RestartADB">正在嘗試重啟 ADB</system:String>
<system:String x:Key="CheckSettings">請檢查連接設置或嘗試重啟模擬器與 ADB 或重啟電腦</system:String>
<!-- About -->

View File

@@ -730,6 +730,44 @@ namespace MaaWpfGui.ViewModels.UI
Instances.TaskQueueViewModel.Idle = idle;
}
/// <summary>
/// Restarts the ADB (Android Debug Bridge).
/// </summary>
public void RestartADB()
{
if (!AllowADBRestart)
{
return;
}
string adbPath = AdbPath;
if (string.IsNullOrEmpty(adbPath))
{
return;
}
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
RedirectStandardInput = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
UseShellExecute = false,
};
Process process = new Process
{
StartInfo = processStartInfo,
};
process.Start();
process.StandardInput.WriteLine($"{adbPath} kill-server");
process.StandardInput.WriteLine($"{adbPath} start-server");
process.StandardInput.WriteLine("exit");
process.WaitForExit();
}
/// <summary>
/// Selects the emulator to execute.
/// </summary>
@@ -2140,6 +2178,21 @@ namespace MaaWpfGui.ViewModels.UI
}
}
private bool _allowADBRestart = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.AllowADBRestart, bool.TrueString));
/// <summary>
/// Gets or sets a value indicating whether to retry task after adb disconnected.
/// </summary>
public bool AllowADBRestart
{
get => _allowADBRestart;
set
{
SetAndNotify(ref _allowADBRestart, value);
ConfigurationHelper.SetValue(ConfigurationKeys.AllowADBRestart, value.ToString());
}
}
private bool _deploymentWithPause = bool.Parse(ConfigurationHelper.GetValue(ConfigurationKeys.RoguelikeDeploymentWithPause, false.ToString()));
public bool DeploymentWithPause

View File

@@ -693,7 +693,6 @@ namespace MaaWpfGui.ViewModels.UI
if (!connected)
{
AddLog(errMsg, UiLogColor.Error);
AddLog(LocalizationHelper.GetString("ConnectFailed") + "\n" + LocalizationHelper.GetString("TryToStartEmulator"));
await Task.Run(() => Instances.SettingsViewModel.TryToStartEmulator(true));
@@ -704,13 +703,28 @@ namespace MaaWpfGui.ViewModels.UI
}
connected = await Task.Run(() => Instances.AsstProxy.AsstConnect(ref errMsg));
if (!connected)
}
if (!connected)
{
AddLog(LocalizationHelper.GetString("ConnectFailed") + "\n" + LocalizationHelper.GetString("RestartADB"));
await Task.Run(() => Instances.SettingsViewModel.RestartADB());
if (Stopping)
{
AddLog(errMsg, UiLogColor.Error);
Idle = true;
SetStopped();
return;
}
connected = await Task.Run(() => Instances.AsstProxy.AsstConnect(ref errMsg));
}
if (!connected)
{
AddLog(errMsg, UiLogColor.Error);
Idle = true;
SetStopped();
return;
}
// 一般是点了“停止”按钮了

View File

@@ -151,6 +151,10 @@
Content="{DynamicResource RetryOnDisconnected}"
IsChecked="{Binding RetryOnDisconnected}"
ToolTip="{DynamicResource RetryOnDisconnectedTip}" />
<CheckBox
Margin="20,10"
Content="{DynamicResource AllowADBRestart}"
IsChecked="{Binding AllowADBRestart}" />
<CheckBox
Margin="20,10"
Content="{DynamicResource AutoRestartOption}"