1
0
mirror of https://github.com/TheFunny/ArisuAutoSweeper synced 2026-06-09 20:04:52 +00:00

feat: shutdown when task queue empty

This commit is contained in:
RedDeadDepresso
2024-01-04 22:04:30 +00:00
committed by YoursFunny
parent 73568fe48c
commit f932b2ac10
12 changed files with 47 additions and 9 deletions
+35
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()
+2 -1
View File
@@ -128,7 +128,8 @@
"option": [
"stay_there",
"goto_main",
"close_game"
"close_game",
"shutdown"
]
}
}
+1 -1
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 ====================
+1 -1
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
+2 -1
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": {
+2 -1
View File
@@ -224,7 +224,8 @@
"help": "无任务时关闭游戏,能在收菜期间降低 CPU 占用",
"stay_there": "停在原处",
"goto_main": "前往主界面",
"close_game": "关闭游戏"
"close_game": "关闭游戏",
"shutdown": "shutdown"
}
},
"Cafe": {