1
0
mirror of https://github.com/TheFunny/ArisuAutoSweeper synced 2025-12-16 15:35:12 +00:00

feat: shutdown when task queue empty

This commit is contained in:
RedDeadDepresso 2024-01-04 22:04:30 +00:00
parent f484756e3f
commit 836ea595ca
12 changed files with 47 additions and 9 deletions

View File

@ -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()

View File

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -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()

View File

@ -128,7 +128,8 @@
"option": [
"stay_there",
"goto_main",
"close_game"
"close_game",
"shutdown"
]
}
}

View File

@ -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 ====================

View File

@ -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

View File

@ -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": {

View File

@ -224,7 +224,8 @@
"help": "无任务时关闭游戏,能在收菜期间降低 CPU 占用",
"stay_there": "停在原处",
"goto_main": "前往主界面",
"close_game": "关闭游戏"
"close_game": "关闭游戏",
"shutdown": "shutdown"
}
},
"Cafe": {