mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
refactor: 重构CheckAfterCompleted,添加睡眠
This commit is contained in:
@@ -66,6 +66,11 @@ public class PostActionSetting : PropertyChangedBase
|
||||
/// 关机
|
||||
/// </summary>
|
||||
Shutdown = 64,
|
||||
|
||||
/// <summary>
|
||||
/// 睡眠
|
||||
/// </summary>
|
||||
Sleep = 128,
|
||||
}
|
||||
|
||||
private PostActions _postActions;
|
||||
@@ -218,8 +223,9 @@ public class PostActionSetting : PropertyChangedBase
|
||||
if (value)
|
||||
{
|
||||
Shutdown = false;
|
||||
Sleep = false;
|
||||
}
|
||||
else if (!Shutdown)
|
||||
else if (!Shutdown && !Sleep)
|
||||
{
|
||||
IfNoOtherMaa = false;
|
||||
}
|
||||
@@ -242,11 +248,11 @@ public class PostActionSetting : PropertyChangedBase
|
||||
|
||||
if (value)
|
||||
{
|
||||
ExitArknights = false;
|
||||
BackToAndroidHome = false;
|
||||
ExitEmulator = true;
|
||||
Hibernate = false;
|
||||
Sleep = false;
|
||||
}
|
||||
else if (!Hibernate)
|
||||
else if (!Hibernate && !Sleep)
|
||||
{
|
||||
IfNoOtherMaa = false;
|
||||
}
|
||||
@@ -255,6 +261,32 @@ public class PostActionSetting : PropertyChangedBase
|
||||
}
|
||||
}
|
||||
|
||||
private bool _sleep;
|
||||
|
||||
public bool Sleep
|
||||
{
|
||||
get => _sleep;
|
||||
set
|
||||
{
|
||||
if (!SetAndNotify(ref _sleep, value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (value)
|
||||
{
|
||||
Hibernate = false;
|
||||
Shutdown = false;
|
||||
}
|
||||
else if (!Hibernate && !Shutdown)
|
||||
{
|
||||
IfNoOtherMaa = false;
|
||||
}
|
||||
|
||||
UpdatePostAction(PostActions.Sleep, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static PostActionSetting Current { get; } = new();
|
||||
|
||||
private string _actionTitle = LocalizationHelper.GetString("PostActions");
|
||||
@@ -332,6 +364,11 @@ public class PostActionSetting : PropertyChangedBase
|
||||
actions.Add(prefix + LocalizationHelper.GetString("Shutdown"));
|
||||
}
|
||||
|
||||
if (Sleep)
|
||||
{
|
||||
actions.Add(LocalizationHelper.GetString("Sleep"));
|
||||
}
|
||||
|
||||
ActionDescription = actions.Count == 0
|
||||
? LocalizationHelper.GetString("DoNothing")
|
||||
: string.Join(" -> ", actions);
|
||||
@@ -370,6 +407,7 @@ public class PostActionSetting : PropertyChangedBase
|
||||
IfNoOtherMaa = _postActions.HasFlag(PostActions.IfNoOtherMaa);
|
||||
Hibernate = _postActions.HasFlag(PostActions.Hibernate);
|
||||
Shutdown = _postActions.HasFlag(PostActions.Shutdown);
|
||||
Sleep = _postActions.HasFlag(PostActions.Sleep);
|
||||
Once = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -435,6 +435,7 @@ Only supports Official(CN) and Bilibili server. Login account is not supported.<
|
||||
<system:String x:Key="ExitSelf">Exit MAA</system:String>
|
||||
<system:String x:Key="ExitEmulator">Exit Emulator</system:String>
|
||||
<system:String x:Key="Hibernate">Hibernate</system:String>
|
||||
<system:String x:Key="Sleep">Sleep</system:String>
|
||||
<system:String x:Key="Shutdown">Shutdown</system:String>
|
||||
<system:String x:Key="Once">Only once*</system:String>
|
||||
<system:String x:Key="PostActionOnceTip">If active, changes will NOT be saved until next run.</system:String>
|
||||
@@ -509,6 +510,7 @@ Only supports Official(CN) and Bilibili server. Login account is not supported.<
|
||||
<system:String x:Key="AboutToShutdown">All tasks have been completed: shutting down. Do you want to cancel?</system:String>
|
||||
<system:String x:Key="ShutdownPrompt">Tip</system:String>
|
||||
<system:String x:Key="HibernatePrompt">Task(s) completed, about to hibernate</system:String>
|
||||
<system:String x:Key="SleepPrompt">Completed, about to sleep</system:String>
|
||||
<system:String x:Key="UnknownActionAfterCompleted">Unknown ending action</system:String>
|
||||
<system:String x:Key="AnnihilationTaskTip">The stage selected is an annihilation task. After the task is completed, the remaining alternative stages will be attempted. Some battle settings will not take effect.</system:String>
|
||||
<system:String x:Key="AnnihilationTaskFailed">Annihilation task failed, will try to use alternate stage, some combat settings will not be effective.</system:String>
|
||||
|
||||
@@ -435,6 +435,7 @@
|
||||
<system:String x:Key="ExitSelf">MAAを終了する</system:String>
|
||||
<system:String x:Key="ExitEmulator">エミュレータを終了する</system:String>
|
||||
<system:String x:Key="Hibernate">休止状態にする</system:String>
|
||||
<system:String x:Key="Sleep">スリープ</system:String>
|
||||
<system:String x:Key="Shutdown">シャットダウン</system:String>
|
||||
<system:String x:Key="Once">1回のみ*</system:String>
|
||||
<system:String x:Key="PostActionOnceTip" xml:space="preserve">1回のみ実行するには、まず1回のみチェックしてください
|
||||
@@ -511,6 +512,7 @@
|
||||
<system:String x:Key="AboutToShutdown">完了しました。シャットダウンしようとしています。キャンセルしますか?</system:String>
|
||||
<system:String x:Key="ShutdownPrompt">ヒント</system:String>
|
||||
<system:String x:Key="HibernatePrompt">完了しました。休止状態にしようとしています</system:String>
|
||||
<system:String x:Key="SleepPrompt">完了しました、スリープ状態に入ります</system:String>
|
||||
<system:String x:Key="UnknownActionAfterCompleted">未知の終了動作</system:String>
|
||||
<system:String x:Key="AnnihilationTaskTip">ステージ選択が殲滅任務になっています。任務終了後、残りの代替ステージが試されます。一部の戦闘設定は有効になりません。</system:String>
|
||||
<system:String x:Key="AnnihilationTaskFailed">殲滅戦に失敗、代替ステージを使用しますが、一部の戦闘設定が有効ではありません</system:String>
|
||||
|
||||
@@ -436,6 +436,7 @@ OF-1을 해금하지 않았다면 선택하지 말아 주세요.</system:String>
|
||||
<system:String x:Key="ExitSelf">MAA를 종료</system:String>
|
||||
<system:String x:Key="ExitEmulator">에뮬레이터를 종료</system:String>
|
||||
<system:String x:Key="Hibernate">절전 모드</system:String>
|
||||
<system:String x:Key="Sleep">절전</system:String>
|
||||
<system:String x:Key="Shutdown">시스템 종료</system:String>
|
||||
<system:String x:Key="Once">한 번만*</system:String>
|
||||
<system:String x:Key="PostActionOnceTip" xml:space="preserve">한 번만 실행하려면 먼저 Only once를 체크하세요.
|
||||
@@ -512,6 +513,7 @@ Only once가 체크되면 실행 후 Only once가 체크되기 전 상태로 작
|
||||
<system:String x:Key="AboutToShutdown">작업을 완료했습니다. 시스템이 곧 종료됩니다. 취소하시겠습니까?</system:String>
|
||||
<system:String x:Key="ShutdownPrompt">알림</system:String>
|
||||
<system:String x:Key="HibernatePrompt">작업을 완료했습니다. 곧 절전 모드에 진입합니다</system:String>
|
||||
<system:String x:Key="SleepPrompt">완료되었습니다, 절전 모드로 전환합니다</system:String>
|
||||
<system:String x:Key="UnknownActionAfterCompleted">알 수 없는 종료 동작</system:String>
|
||||
<system:String x:Key="AnnihilationTaskTip">선택한 스테이지는 섬멸 임무입니다. 임무 완료 후 남은 대체 스테이지가 시도됩니다. 일부 전투 설정은 적용되지 않습니다.</system:String>
|
||||
<system:String x:Key="AnnihilationTaskFailed">섬멸 작전에 실패하여 대체 스테이지를 진행합니다. 일부 전투 설정이 무시될 수 있습니다</system:String>
|
||||
|
||||
@@ -435,6 +435,7 @@
|
||||
<system:String x:Key="ExitSelf">退出 MAA</system:String>
|
||||
<system:String x:Key="ExitEmulator">退出 模拟器</system:String>
|
||||
<system:String x:Key="Hibernate">休眠</system:String>
|
||||
<system:String x:Key="Sleep">睡眠</system:String>
|
||||
<system:String x:Key="Shutdown">关机</system:String>
|
||||
<system:String x:Key="Once">仅一次*</system:String>
|
||||
<system:String x:Key="PostActionOnceTip" xml:space="preserve">如想只执行一次,请先勾选仅一次
|
||||
@@ -511,6 +512,7 @@
|
||||
<system:String x:Key="AboutToShutdown">已刷完,即将关机,是否取消?</system:String>
|
||||
<system:String x:Key="ShutdownPrompt">提示</system:String>
|
||||
<system:String x:Key="HibernatePrompt">已刷完,即将休眠</system:String>
|
||||
<system:String x:Key="SleepPrompt">已刷完,即将睡眠</system:String>
|
||||
<system:String x:Key="UnknownActionAfterCompleted">未知的结束动作</system:String>
|
||||
<system:String x:Key="AnnihilationTaskTip">关卡选择为剿灭任务,任务结束后将尝试使用剩余备选关卡,部分战斗设置将不生效。</system:String>
|
||||
<system:String x:Key="AnnihilationTaskFailed">剿灭任务失败,将尝试使用剩余备选关卡,部分战斗设置将不生效。</system:String>
|
||||
|
||||
@@ -435,6 +435,7 @@
|
||||
<system:String x:Key="ExitSelf">退出 MAA</system:String>
|
||||
<system:String x:Key="ExitEmulator">退出 模擬器</system:String>
|
||||
<system:String x:Key="Hibernate">休眠</system:String>
|
||||
<system:String x:Key="Sleep">睡眠</system:String>
|
||||
<system:String x:Key="Shutdown">關機</system:String>
|
||||
<system:String x:Key="Once">僅一次*</system:String>
|
||||
<system:String x:Key="PostActionOnceTip" xml:space="preserve">如想只執行一次,請先勾選僅一次
|
||||
@@ -511,6 +512,7 @@
|
||||
<system:String x:Key="AboutToShutdown">已刷完,即將關機,是否取消?</system:String>
|
||||
<system:String x:Key="ShutdownPrompt">提示</system:String>
|
||||
<system:String x:Key="HibernatePrompt">已刷完,即將休眠</system:String>
|
||||
<system:String x:Key="SleepPrompt">已刷完,即將睡眠</system:String>
|
||||
<system:String x:Key="UnknownActionAfterCompleted">未知的結束動作</system:String>
|
||||
<system:String x:Key="AnnihilationTaskTip">關卡選擇為剿滅任務,任務結束後將嘗試使用剩餘備選關卡,部分戰鬥設置將不生效。</system:String>
|
||||
<system:String x:Key="AnnihilationTaskFailed">剿滅任務失敗,將嘗試使用剩餘備選關卡,部分戰鬥設定將不生效。</system:String>
|
||||
|
||||
@@ -119,10 +119,10 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
if (actions.BackToAndroidHome)
|
||||
{
|
||||
Instances.AsstProxy.AsstBackToHome();
|
||||
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
else if (actions.ExitArknights)
|
||||
|
||||
if (actions.ExitArknights)
|
||||
{
|
||||
var mode = Instances.SettingsViewModel.ClientType;
|
||||
if (!Instances.AsstProxy.AsstStartCloseDown(mode))
|
||||
@@ -136,11 +136,10 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
if (actions.ExitEmulator)
|
||||
{
|
||||
DoKillEmulator();
|
||||
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
|
||||
if (actions.ExitSelf && !(actions.Hibernate || actions.Shutdown))
|
||||
if (actions.ExitSelf && !(actions.Hibernate || actions.Shutdown || actions.Sleep))
|
||||
{
|
||||
Bootstrapper.Shutdown();
|
||||
}
|
||||
@@ -153,12 +152,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
}
|
||||
else
|
||||
{
|
||||
DoHibernate();
|
||||
}
|
||||
|
||||
if (actions.ExitSelf)
|
||||
{
|
||||
Bootstrapper.Shutdown();
|
||||
await DoHibernate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,16 +164,35 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
}
|
||||
else
|
||||
{
|
||||
DoShutDown();
|
||||
await DoShutDown();
|
||||
}
|
||||
}
|
||||
|
||||
if (actions.Sleep)
|
||||
{
|
||||
if (actions.IfNoOtherMaa && HasOtherMaa())
|
||||
{
|
||||
Bootstrapper.Shutdown();
|
||||
}
|
||||
else
|
||||
{
|
||||
await DoSleep();
|
||||
}
|
||||
}
|
||||
|
||||
if (actions.ExitSelf)
|
||||
{
|
||||
Bootstrapper.Shutdown();
|
||||
}
|
||||
|
||||
actions.LoadPostActions();
|
||||
return;
|
||||
|
||||
bool HasOtherMaa()
|
||||
{
|
||||
return Process.GetProcessesByName("MAA").Length > 1;
|
||||
var processesCount = Process.GetProcessesByName("MAA").Length;
|
||||
_logger.Information($"MAA processes count: {processesCount}");
|
||||
return processesCount > 1;
|
||||
}
|
||||
|
||||
void DoKillEmulator()
|
||||
@@ -190,45 +203,42 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
}
|
||||
}
|
||||
|
||||
void DoHibernate()
|
||||
async Task DoHibernate()
|
||||
{
|
||||
actions.LoadPostActions();
|
||||
|
||||
// 休眠提示
|
||||
AddLog(LocalizationHelper.GetString("HibernatePrompt"), UiLogColor.Error);
|
||||
|
||||
/*
|
||||
// 休眠不能加时间参数,https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/1133
|
||||
Process.Start("shutdown.exe", "-h");
|
||||
*/
|
||||
await Task.Delay(10000);
|
||||
PowerManagement.Hibernate();
|
||||
}
|
||||
|
||||
async void DoShutDown()
|
||||
async Task DoShutDown()
|
||||
{
|
||||
/*
|
||||
Process.Start("shutdown.exe", "-s -t 60");
|
||||
Process.Start("shutdown.exe", "-s -t 70");
|
||||
|
||||
// 关机询问
|
||||
var shutdownResult = MessageBoxHelper.Show(LocalizationHelper.GetString("AboutToShutdown"), LocalizationHelper.GetString("ShutdownPrompt"), MessageBoxButton.OK, MessageBoxImage.Question, ok: LocalizationHelper.GetString("Cancel"));
|
||||
if (shutdownResult == MessageBoxResult.OK)
|
||||
{
|
||||
Process.Start("shutdown.exe", "-a");
|
||||
}
|
||||
*/
|
||||
if (await TimerCanceledAsync(
|
||||
LocalizationHelper.GetString("Shutdown"),
|
||||
LocalizationHelper.GetString("AboutToShutdown"),
|
||||
LocalizationHelper.GetString("Cancel"),
|
||||
60))
|
||||
{
|
||||
Process.Start("shutdown.exe", "-a");
|
||||
return;
|
||||
}
|
||||
|
||||
Bootstrapper.Release();
|
||||
PowerManagement.Shutdown();
|
||||
Bootstrapper.Shutdown();
|
||||
}
|
||||
|
||||
async Task DoSleep()
|
||||
{
|
||||
actions.LoadPostActions();
|
||||
|
||||
// 休眠提示
|
||||
AddLog(LocalizationHelper.GetString("SleepPrompt"), UiLogColor.Error);
|
||||
await Task.Delay(10000);
|
||||
PowerManagement.Sleep();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<StackPanel>
|
||||
<StackPanel Visibility="{c:Binding !TaskSettingVisibilities.EnableAdvancedSettings}">
|
||||
<CheckBox
|
||||
Margin="0,10"
|
||||
Margin="0,8"
|
||||
HorizontalAlignment="Left"
|
||||
IsChecked="{Binding PostActionSetting.Once}"
|
||||
ToolTip="{DynamicResource PostActionOnceTip}"
|
||||
@@ -30,7 +30,7 @@
|
||||
</CheckBox>
|
||||
<hc:Divider />
|
||||
<CheckBox
|
||||
Margin="0,10"
|
||||
Margin="0,8"
|
||||
s:View.ActionTarget="{Binding PostActionSetting}"
|
||||
IsChecked="{Binding PostActionSetting.BackToAndroidHome}"
|
||||
IsEnabled="{c:Binding !PostActionSetting.ExitEmulator}"
|
||||
@@ -38,7 +38,7 @@
|
||||
<controls:TextBlock Text="{DynamicResource BackToAndroidHome}" TextWrapping="Wrap" />
|
||||
</CheckBox>
|
||||
<CheckBox
|
||||
Margin="0,10"
|
||||
Margin="0,8"
|
||||
s:View.ActionTarget="{Binding PostActionSetting}"
|
||||
IsChecked="{Binding PostActionSetting.ExitArknights}"
|
||||
IsEnabled="{c:Binding !PostActionSetting.ExitEmulator}"
|
||||
@@ -46,7 +46,7 @@
|
||||
<controls:TextBlock Text="{DynamicResource ExitArknights}" TextWrapping="Wrap" />
|
||||
</CheckBox>
|
||||
<CheckBox
|
||||
Margin="0,10"
|
||||
Margin="0,8"
|
||||
s:View.ActionTarget="{Binding PostActionSetting}"
|
||||
IsChecked="{Binding PostActionSetting.ExitEmulator}"
|
||||
IsEnabled="{c:Binding !PostActionSetting.IfNoOtherMaa}"
|
||||
@@ -54,7 +54,7 @@
|
||||
<controls:TextBlock Text="{DynamicResource ExitEmulator}" TextWrapping="Wrap" />
|
||||
</CheckBox>
|
||||
<CheckBox
|
||||
Margin="0,10"
|
||||
Margin="0,8"
|
||||
s:View.ActionTarget="{Binding PostActionSetting}"
|
||||
IsChecked="{Binding PostActionSetting.ExitSelf}"
|
||||
IsEnabled="{c:Binding !PostActionSetting.IfNoOtherMaa}"
|
||||
@@ -63,26 +63,33 @@
|
||||
</CheckBox>
|
||||
<hc:Divider />
|
||||
<CheckBox
|
||||
Margin="0,10"
|
||||
Margin="0,8"
|
||||
IsChecked="{Binding PostActionSetting.IfNoOtherMaa}"
|
||||
IsEnabled="{c:Binding 'PostActionSetting.Hibernate || PostActionSetting.Shutdown'}">
|
||||
<controls:TextBlock Text="{DynamicResource IfNoOtherMaa}" TextWrapping="Wrap" />
|
||||
</CheckBox>
|
||||
|
||||
<CheckBox
|
||||
Margin="0,10"
|
||||
Margin="0,8"
|
||||
s:View.ActionTarget="{Binding PostActionSetting}"
|
||||
IsChecked="{Binding PostActionSetting.Hibernate}"
|
||||
MouseRightButtonUp="{s:Action PostActionsAndOnce}">
|
||||
<controls:TextBlock Text="{DynamicResource Hibernate}" TextWrapping="Wrap" />
|
||||
</CheckBox>
|
||||
<CheckBox
|
||||
Margin="0,10"
|
||||
Margin="0,8"
|
||||
s:View.ActionTarget="{Binding PostActionSetting}"
|
||||
IsChecked="{Binding PostActionSetting.Shutdown}"
|
||||
MouseRightButtonUp="{s:Action PostActionsAndOnce}">
|
||||
<controls:TextBlock Text="{DynamicResource Shutdown}" TextWrapping="Wrap" />
|
||||
</CheckBox>
|
||||
<CheckBox
|
||||
Margin="0,8"
|
||||
s:View.ActionTarget="{Binding PostActionSetting}"
|
||||
IsChecked="{Binding PostActionSetting.Sleep}"
|
||||
MouseRightButtonUp="{s:Action PostActionsAndOnce}">
|
||||
<controls:TextBlock Text="{DynamicResource Sleep}" TextWrapping="Wrap" />
|
||||
</CheckBox>
|
||||
|
||||
<Button
|
||||
Height="30"
|
||||
|
||||
Reference in New Issue
Block a user