diff --git a/MCE Manager.py b/MCE Manager.py index 6ccbf14..cbb71e0 100644 --- a/MCE Manager.py +++ b/MCE Manager.py @@ -213,7 +213,7 @@ class MCE_Manager(customtkinter.CTk): self.template_optionmenu.set(self.previous_selected) return elif template_name in self.templates_list: - CTkMessagebox(title="Error", message="Name is invalid.", icon="cancel") + CTkMessagebox(title="Error", message="Name is invalid.", icon="MCE\icons\cancel.png") self.template_optionmenu.set(self.previous_selected) return else: @@ -234,7 +234,7 @@ class MCE_Manager(customtkinter.CTk): def delete_template(self): msg = CTkMessagebox(title="Template Deletetion", message=f"Are you sure you want to delete Template {self.previous_selected}?", - icon="question", option_1="No", option_2="Yes") + icon="MCE\icons\question.png", option_1="No", option_2="Yes") response = msg.get() if response=="Yes": if len(self.templates) != 1: @@ -252,7 +252,7 @@ class MCE_Manager(customtkinter.CTk): self.template_optionmenu.configure(values=self.templates_list) self.template_optionmenu.set(self.preferred_template) else: - CTkMessagebox(title="Error", message="At least one template must exist!!!", icon="cancel") + CTkMessagebox(title="Error", message="At least one template must exist!!!", icon="MCE\icons\cancel.png") return # Function to add a frame with widgets @@ -311,7 +311,7 @@ class MCE_Manager(customtkinter.CTk): mode_optionmenu = frame.winfo_children()[2] stage_entry = frame.winfo_children()[3] if not self.check_entry(mode_optionmenu, stage_entry): - CTkMessagebox(title="Error", message="Configuration not saved. Some entries are incomplete or have incorect input.", icon="cancel") + CTkMessagebox(title="Error", message="Configuration not saved. Some entries are incomplete or have incorect input.", icon="MCE\icons\cancel.png") return mode = frame.winfo_children()[2].get() stage = frame.winfo_children()[3].get().strip() diff --git a/MCE/custom_widgets/icons/cancel.png b/MCE/icons/cancel.png similarity index 100% rename from MCE/custom_widgets/icons/cancel.png rename to MCE/icons/cancel.png diff --git a/MCE/custom_widgets/icons/check.png b/MCE/icons/check.png similarity index 100% rename from MCE/custom_widgets/icons/check.png rename to MCE/icons/check.png diff --git a/MCE/custom_widgets/icons/info.png b/MCE/icons/info.png similarity index 100% rename from MCE/custom_widgets/icons/info.png rename to MCE/icons/info.png diff --git a/MCE/custom_widgets/icons/question.png b/MCE/icons/question.png similarity index 100% rename from MCE/custom_widgets/icons/question.png rename to MCE/icons/question.png diff --git a/MCE/custom_widgets/icons/warning.png b/MCE/icons/warning.png similarity index 100% rename from MCE/custom_widgets/icons/warning.png rename to MCE/icons/warning.png diff --git a/module/alas.py b/module/alas.py index 56c0193..8e2167f 100644 --- a/module/alas.py +++ b/module/alas.py @@ -14,6 +14,9 @@ from module.exception import * from module.logger import logger from module.notify import handle_notify +from MCE.custom_widgets.ctkmessagebox import CTkMessagebox +import subprocess +import platform class AzurLaneAutoScript: stop_event: threading.Event = None @@ -228,6 +231,26 @@ class AzurLaneAutoScript: if not self.wait_until(task.next_run): del_cached_property(self, 'config') continue + elif method == 'shutdown': + os = platform.system() + if os not in ["Windows", "Linux", "Darwin"]: + logger.info("Shutdown set during wait but operating system not supported") + else: + logger.info('Shutdown during wait') + try: + self.shutdown(os) + msg = CTkMessagebox(title="AAS: Cancel Shutdown?", message="All tasks have been completed: shutting down. Do you want to cancel?", + icon="MCE\icons\question.png", option_1="Cancel") + response = msg.get() + if response=="Cancel": + self.abort_shutdown(os) + except: + logger.error("Failed to shutdown. It may be due to a lack of administrator privileges.") + release_resources() + self.device.release_during_wait() + if not self.wait_until(task.next_run): + del_cached_property(self, 'config') + continue else: logger.warning(f'Invalid Optimization_WhenTaskQueueEmpty: {method}, fallback to stay_there') release_resources() @@ -308,6 +331,18 @@ class AzurLaneAutoScript: self.checker.check_now() continue + def shutdown(self, os): + logger.info("Running Shutting down") + if os == "Windows": + subprocess.run(["shutdown", "-s", "-t", "60"]) + elif os in ["Linux", "Darwin"]: + subprocess.run(["shutdown", "-h", "+1"]) + + def abort_shutdown(self, os): + if os == "Windows": + subprocess.run(["shutdown", "-a"]) + elif os in ["Linux", "Darwin"]: + subprocess.run(["shutdown", "-c"]) if __name__ == '__main__': alas = AzurLaneAutoScript() diff --git a/module/config/argument/args.json b/module/config/argument/args.json index 496b71d..91f4ee9 100644 --- a/module/config/argument/args.json +++ b/module/config/argument/args.json @@ -128,7 +128,8 @@ "option": [ "stay_there", "goto_main", - "close_game" + "close_game", + "shutdown" ] } } diff --git a/module/config/argument/argument.yaml b/module/config/argument/argument.yaml index 14da2ff..9a3464a 100644 --- a/module/config/argument/argument.yaml +++ b/module/config/argument/argument.yaml @@ -71,7 +71,7 @@ Optimization: CombatScreenshotInterval: 1.0 WhenTaskQueueEmpty: value: goto_main - option: [ stay_there, goto_main, close_game ] + option: [ stay_there, goto_main, close_game, shutdown ] # ==================== Daily ==================== diff --git a/module/config/config_generated.py b/module/config/config_generated.py index 870a56c..ca9c668 100644 --- a/module/config/config_generated.py +++ b/module/config/config_generated.py @@ -37,7 +37,7 @@ class GeneratedConfig: # Group `Optimization` Optimization_ScreenshotInterval = 0.3 Optimization_CombatScreenshotInterval = 1.0 - Optimization_WhenTaskQueueEmpty = 'goto_main' # stay_there, goto_main, close_game + Optimization_WhenTaskQueueEmpty = 'goto_main' # stay_there, goto_main, close_game, shutdown # Group `Cafe` Cafe_Reward = True diff --git a/module/config/i18n/en-US.json b/module/config/i18n/en-US.json index b055d06..b8bb086 100644 --- a/module/config/i18n/en-US.json +++ b/module/config/i18n/en-US.json @@ -224,7 +224,8 @@ "help": "Close AL when there are no pending tasks, can help reduce CPU", "stay_there": "Stay There", "goto_main": "Goto Main Page", - "close_game": "Close Game" + "close_game": "Close Game", + "shutdown": "Shutdown" } }, "Cafe": { diff --git a/module/config/i18n/zh-CN.json b/module/config/i18n/zh-CN.json index 6ad9f51..81e3d75 100644 --- a/module/config/i18n/zh-CN.json +++ b/module/config/i18n/zh-CN.json @@ -224,7 +224,8 @@ "help": "无任务时关闭游戏,能在收菜期间降低 CPU 占用", "stay_there": "停在原处", "goto_main": "前往主界面", - "close_game": "关闭游戏" + "close_game": "关闭游戏", + "shutdown": "shutdown" } }, "Cafe": {