feat: shutdown when task queue empty
@ -213,7 +213,7 @@ class MCE_Manager(customtkinter.CTk):
|
|||||||
self.template_optionmenu.set(self.previous_selected)
|
self.template_optionmenu.set(self.previous_selected)
|
||||||
return
|
return
|
||||||
elif template_name in self.templates_list:
|
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)
|
self.template_optionmenu.set(self.previous_selected)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
@ -234,7 +234,7 @@ class MCE_Manager(customtkinter.CTk):
|
|||||||
|
|
||||||
def delete_template(self):
|
def delete_template(self):
|
||||||
msg = CTkMessagebox(title="Template Deletetion", message=f"Are you sure you want to delete Template {self.previous_selected}?",
|
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()
|
response = msg.get()
|
||||||
if response=="Yes":
|
if response=="Yes":
|
||||||
if len(self.templates) != 1:
|
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.configure(values=self.templates_list)
|
||||||
self.template_optionmenu.set(self.preferred_template)
|
self.template_optionmenu.set(self.preferred_template)
|
||||||
else:
|
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
|
return
|
||||||
|
|
||||||
# Function to add a frame with widgets
|
# Function to add a frame with widgets
|
||||||
@ -311,7 +311,7 @@ class MCE_Manager(customtkinter.CTk):
|
|||||||
mode_optionmenu = frame.winfo_children()[2]
|
mode_optionmenu = frame.winfo_children()[2]
|
||||||
stage_entry = frame.winfo_children()[3]
|
stage_entry = frame.winfo_children()[3]
|
||||||
if not self.check_entry(mode_optionmenu, stage_entry):
|
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
|
return
|
||||||
mode = frame.winfo_children()[2].get()
|
mode = frame.winfo_children()[2].get()
|
||||||
stage = frame.winfo_children()[3].get().strip()
|
stage = frame.winfo_children()[3].get().strip()
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
@ -14,6 +14,9 @@ from module.exception import *
|
|||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
from module.notify import handle_notify
|
from module.notify import handle_notify
|
||||||
|
|
||||||
|
from MCE.custom_widgets.ctkmessagebox import CTkMessagebox
|
||||||
|
import subprocess
|
||||||
|
import platform
|
||||||
|
|
||||||
class AzurLaneAutoScript:
|
class AzurLaneAutoScript:
|
||||||
stop_event: threading.Event = None
|
stop_event: threading.Event = None
|
||||||
@ -228,6 +231,26 @@ class AzurLaneAutoScript:
|
|||||||
if not self.wait_until(task.next_run):
|
if not self.wait_until(task.next_run):
|
||||||
del_cached_property(self, 'config')
|
del_cached_property(self, 'config')
|
||||||
continue
|
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:
|
else:
|
||||||
logger.warning(f'Invalid Optimization_WhenTaskQueueEmpty: {method}, fallback to stay_there')
|
logger.warning(f'Invalid Optimization_WhenTaskQueueEmpty: {method}, fallback to stay_there')
|
||||||
release_resources()
|
release_resources()
|
||||||
@ -308,6 +331,18 @@ class AzurLaneAutoScript:
|
|||||||
self.checker.check_now()
|
self.checker.check_now()
|
||||||
continue
|
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__':
|
if __name__ == '__main__':
|
||||||
alas = AzurLaneAutoScript()
|
alas = AzurLaneAutoScript()
|
||||||
|
|||||||
@ -128,7 +128,8 @@
|
|||||||
"option": [
|
"option": [
|
||||||
"stay_there",
|
"stay_there",
|
||||||
"goto_main",
|
"goto_main",
|
||||||
"close_game"
|
"close_game",
|
||||||
|
"shutdown"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,7 +71,7 @@ Optimization:
|
|||||||
CombatScreenshotInterval: 1.0
|
CombatScreenshotInterval: 1.0
|
||||||
WhenTaskQueueEmpty:
|
WhenTaskQueueEmpty:
|
||||||
value: goto_main
|
value: goto_main
|
||||||
option: [ stay_there, goto_main, close_game ]
|
option: [ stay_there, goto_main, close_game, shutdown ]
|
||||||
|
|
||||||
# ==================== Daily ====================
|
# ==================== Daily ====================
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,7 @@ class GeneratedConfig:
|
|||||||
# Group `Optimization`
|
# Group `Optimization`
|
||||||
Optimization_ScreenshotInterval = 0.3
|
Optimization_ScreenshotInterval = 0.3
|
||||||
Optimization_CombatScreenshotInterval = 1.0
|
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`
|
# Group `Cafe`
|
||||||
Cafe_Reward = True
|
Cafe_Reward = True
|
||||||
|
|||||||
@ -224,7 +224,8 @@
|
|||||||
"help": "Close AL when there are no pending tasks, can help reduce CPU",
|
"help": "Close AL when there are no pending tasks, can help reduce CPU",
|
||||||
"stay_there": "Stay There",
|
"stay_there": "Stay There",
|
||||||
"goto_main": "Goto Main Page",
|
"goto_main": "Goto Main Page",
|
||||||
"close_game": "Close Game"
|
"close_game": "Close Game",
|
||||||
|
"shutdown": "Shutdown"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Cafe": {
|
"Cafe": {
|
||||||
|
|||||||
@ -224,7 +224,8 @@
|
|||||||
"help": "无任务时关闭游戏,能在收菜期间降低 CPU 占用",
|
"help": "无任务时关闭游戏,能在收菜期间降低 CPU 占用",
|
||||||
"stay_there": "停在原处",
|
"stay_there": "停在原处",
|
||||||
"goto_main": "前往主界面",
|
"goto_main": "前往主界面",
|
||||||
"close_game": "关闭游戏"
|
"close_game": "关闭游戏",
|
||||||
|
"shutdown": "shutdown"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Cafe": {
|
"Cafe": {
|
||||||
|
|||||||