From 57d7bb5742630b63335d72997aa120983cfabcce Mon Sep 17 00:00:00 2001 From: MistEO Date: Sat, 25 Jun 2022 02:15:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=95=B4=E7=90=86=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=AE=8C=E6=88=90=E5=90=8E=E7=9A=84=E5=8A=A8=E4=BD=9C?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=B8=BA=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAsstGui/Helper/AsstProxy.cs | 4 +- src/MeoAsstGui/Helper/CombData.cs | 8 +- .../ViewModels/TaskQueueViewModel.cs | 75 ++++++++++++------- src/MeoAsstGui/Views/TaskQueueView.xaml | 4 +- 4 files changed, 56 insertions(+), 35 deletions(-) diff --git a/src/MeoAsstGui/Helper/AsstProxy.cs b/src/MeoAsstGui/Helper/AsstProxy.cs index c1946816bb..dacd66cb9a 100644 --- a/src/MeoAsstGui/Helper/AsstProxy.cs +++ b/src/MeoAsstGui/Helper/AsstProxy.cs @@ -313,7 +313,7 @@ namespace MeoAsstGui toast.Show(); } //mainModel.CheckAndShutdown(); - mainModel.CheckAfterComplete(); + mainModel.CheckAfterCompleted(); } _latestTaskId.Clear(); break; @@ -997,4 +997,4 @@ namespace MeoAsstGui SubTaskCompleted, // 原子任务完成 SubTaskExtraInfo // 原子任务额外信息 }; -} +} \ No newline at end of file diff --git a/src/MeoAsstGui/Helper/CombData.cs b/src/MeoAsstGui/Helper/CombData.cs index 21fe67b831..e660116330 100644 --- a/src/MeoAsstGui/Helper/CombData.cs +++ b/src/MeoAsstGui/Helper/CombData.cs @@ -11,9 +11,13 @@ namespace MeoAsstGui { - public class CombData + public class GenericCombData { public string Display { get; set; } - public string Value { get; set; } + public ValueType Value { get; set; } + } + + public class CombData : GenericCombData + { } } diff --git a/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs b/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs index c1cee1b6d5..7ed887f024 100644 --- a/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs +++ b/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs @@ -33,13 +33,16 @@ namespace MeoAsstGui public ObservableCollection TaskItemViewModels { get; set; } public ObservableCollection LogItemViewModels { get; set; } - private string _afterCompleteType = ""; - public List AfterCompleteList { get; set; } + private ActionType _actionAfterComplated = ActionType.DoNothing; + public List> ActionAfterCompletedList { get; set; } - public string AfterCompleteType + public ActionType ActionAfterCompleted { - get { return _afterCompleteType; } - set { _afterCompleteType = value; } + get { return _actionAfterComplated; } + set + { + SetAndNotify(ref _actionAfterComplated, value); + } } public TaskQueueViewModel(IContainer container, IWindowManager windowManager) @@ -103,15 +106,15 @@ namespace MeoAsstGui public void InitializeItems() { string[] task_list = new string[] { "开始唤醒", "刷理智", "自动公招", "基建换班", "访问好友", "收取信用及购物", "领取日常奖励", "无限刷肉鸽" }; - AfterCompleteList = new List + ActionAfterCompletedList = new List> { - new CombData{ Display="无动作",Value="" }, - new CombData{ Display="退出MAA",Value="exit" }, - new CombData { Display = "关闭模拟器", Value = "killemulator" }, - new CombData { Display = "退出并关闭模拟器", Value = "exitwithkillemulator" }, - new CombData{ Display="关机",Value="shutdown" }, - //new CombData { Display = "待机", Value = "suspend" }, - new CombData { Display = "休眠", Value = "hibernate" } + new GenericCombData{ Display="无动作",Value=ActionType.DoNothing }, + new GenericCombData{ Display="退出 MAA",Value=ActionType.ExitSelf }, + new GenericCombData{ Display="关闭模拟器",Value=ActionType.ExitEmulator }, + new GenericCombData{ Display="退出并关闭模拟器",Value=ActionType.ExitEmulatorAndSelf }, + //new GenericCombData{ Display="待机",Value=ActionTypeAfterCompleted.Suspend }, + new GenericCombData{ Display="休眠",Value=ActionType.Hibernate }, + new GenericCombData{ Display="关机",Value=ActionType.Shutdown }, }; var temp_order_list = new List(new DragItemViewModel[task_list.Length]); int order_offset = 0; @@ -602,11 +605,34 @@ namespace MeoAsstGui return true; } - public void CheckAfterComplete() + public enum ActionType { - switch (AfterCompleteType) + DoNothing, + ExitSelf, + ExitEmulator, + ExitEmulatorAndSelf, + Suspend, + Hibernate, + Shutdown + } + + public void CheckAfterCompleted() + { + switch (ActionAfterCompleted) { - case "killemulator": + case ActionType.DoNothing: + break; + + case ActionType.ExitSelf: + if (!new ToastNotification().CheckToastSystem()) + { + Environment.Exit(0); //不使用系统通知的情况下exit会关闭通知窗口 + } + else ToastNotificationManagerCompat.History.Clear(); //exit似乎不会走bootstapper,单独清一下通知 + Environment.Exit(0); + break; + + case ActionType.ExitEmulator: if (!killemulator()) Execute.OnUIThread(() => { @@ -618,7 +644,7 @@ namespace MeoAsstGui }); break; - case "exitwithkillemulator": + case ActionType.ExitEmulatorAndSelf: if (!killemulator()) { Execute.OnUIThread(() => @@ -639,16 +665,7 @@ namespace MeoAsstGui Environment.Exit(0); break; - case "exit": - if (!new ToastNotification().CheckToastSystem()) - { - Environment.Exit(0); //不使用系统通知的情况下exit会关闭通知窗口 - } - else ToastNotificationManagerCompat.History.Clear(); //exit似乎不会走bootstapper,单独清一下通知 - Environment.Exit(0); - break; - - case "shutdown": + case ActionType.Shutdown: System.Diagnostics.Process.Start("shutdown.exe", "-s -t 60"); var result = _windowManager.ShowMessageBox("已刷完,即将关机,是否取消?", "提示", MessageBoxButton.OK, MessageBoxImage.Question); if (result == MessageBoxResult.OK) @@ -657,13 +674,13 @@ namespace MeoAsstGui } break; - case "suspend": + case ActionType.Suspend: System.Diagnostics.Process.Start("powercfg", "-h off"); System.Diagnostics.Process.Start("rundll32.exe", "powrprof.dll,SetSuspendState 0,1,0"); System.Diagnostics.Process.Start("powercfg", "-h on"); break; - case "hibernate": + case ActionType.Hibernate: System.Diagnostics.Process.Start("shutdown.exe", "-h"); break; diff --git a/src/MeoAsstGui/Views/TaskQueueView.xaml b/src/MeoAsstGui/Views/TaskQueueView.xaml index da692244ce..1d6d1c0aff 100644 --- a/src/MeoAsstGui/Views/TaskQueueView.xaml +++ b/src/MeoAsstGui/Views/TaskQueueView.xaml @@ -54,10 +54,10 @@ - + SelectedValue="{Binding ActionAfterCompleted}" Margin="63,0,10,0" />