mirror of
https://github.com/TheFunny/ArisuAutoSweeper
synced 2025-12-20 04:05:23 +00:00
test: exit emulator
This commit is contained in:
parent
836ea595ca
commit
67310938d2
@ -29,6 +29,7 @@ class AzurLaneAutoScript:
|
|||||||
# Failure count of tasks
|
# Failure count of tasks
|
||||||
# Key: str, task name, value: int, failure count
|
# Key: str, task name, value: int, failure count
|
||||||
self.failure_record = {}
|
self.failure_record = {}
|
||||||
|
self.operating_system = platform.system()
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def config(self):
|
def config(self):
|
||||||
@ -231,21 +232,19 @@ 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 == 'exit_aas':
|
||||||
|
self.exit_aas()
|
||||||
|
release_resources()
|
||||||
|
self.device.release_during_wait()
|
||||||
|
if not self.wait_until(task.next_run):
|
||||||
|
del_cached_property(self, 'config')
|
||||||
|
continue
|
||||||
|
elif method == 'exit_aas_emulator':
|
||||||
|
self.exit_emulator()
|
||||||
|
self.exit_aas()
|
||||||
|
exit(0)
|
||||||
elif method == 'shutdown':
|
elif method == 'shutdown':
|
||||||
os = platform.system()
|
self.shutdown()
|
||||||
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()
|
release_resources()
|
||||||
self.device.release_during_wait()
|
self.device.release_during_wait()
|
||||||
if not self.wait_until(task.next_run):
|
if not self.wait_until(task.next_run):
|
||||||
@ -331,17 +330,52 @@ class AzurLaneAutoScript:
|
|||||||
self.checker.check_now()
|
self.checker.check_now()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def shutdown(self, os):
|
def exit_emulator(self):
|
||||||
|
if self.operating_system != 'Windows':
|
||||||
|
logger.error("Exiting emulator is only supported on Windows")
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
from module.device.platform.platform_windows import PlatformWindows
|
||||||
|
PlatformWindows(self.config).emulator_stop()
|
||||||
|
except:
|
||||||
|
logger.error("Failed to stop emulator. It may be due to a lack of administrator privileges or incorrect input in Emulator Settings.")
|
||||||
|
|
||||||
|
def exit_aas(self):
|
||||||
|
if self.operating_system != 'Windows':
|
||||||
|
logger.error("Exiting AAS is only supported on Windows")
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
from module.device.platform.platform_windows import PlatformWindows
|
||||||
|
PlatformWindows(self.config).kill_process_by_regex("aas\.exe")
|
||||||
|
except:
|
||||||
|
logger.error("Failed to stop AAS. It may be due to a lack of administrator privileges.")
|
||||||
|
|
||||||
|
def shutdown(self):
|
||||||
|
if self.operating_system not in ["Windows", "Linux", "Darwin"]:
|
||||||
|
logger.info("Shutdown set during wait but operating system not supported")
|
||||||
|
else:
|
||||||
|
logger.info('Shutdown during wait')
|
||||||
|
try:
|
||||||
|
self.start_shutdown()
|
||||||
|
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.cancel_shutdown()
|
||||||
|
except:
|
||||||
|
logger.error("Failed to shutdown. It may be due to a lack of administrator privileges.")
|
||||||
|
|
||||||
|
def start_shutdown(self):
|
||||||
logger.info("Running Shutting down")
|
logger.info("Running Shutting down")
|
||||||
if os == "Windows":
|
if self.operating_system == "Windows":
|
||||||
subprocess.run(["shutdown", "-s", "-t", "60"])
|
subprocess.run(["shutdown", "-s", "-t", "60"])
|
||||||
elif os in ["Linux", "Darwin"]:
|
elif self.operating_system in ["Linux", "Darwin"]:
|
||||||
subprocess.run(["shutdown", "-h", "+1"])
|
subprocess.run(["shutdown", "-h", "+1"])
|
||||||
|
|
||||||
def abort_shutdown(self, os):
|
def cancel_shutdown(self):
|
||||||
if os == "Windows":
|
if self.operating_system == "Windows":
|
||||||
subprocess.run(["shutdown", "-a"])
|
subprocess.run(["shutdown", "-a"])
|
||||||
elif os in ["Linux", "Darwin"]:
|
elif self.operating_system in ["Linux", "Darwin"]:
|
||||||
subprocess.run(["shutdown", "-c"])
|
subprocess.run(["shutdown", "-c"])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@ -129,6 +129,8 @@
|
|||||||
"stay_there",
|
"stay_there",
|
||||||
"goto_main",
|
"goto_main",
|
||||||
"close_game",
|
"close_game",
|
||||||
|
"exit_aas",
|
||||||
|
"exit_aas_emulator",
|
||||||
"shutdown"
|
"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, shutdown ]
|
option: [ stay_there, goto_main, close_game, exit_aas, exit_aas_emulator, 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, shutdown
|
Optimization_WhenTaskQueueEmpty = 'goto_main' # stay_there, goto_main, close_game, exit_aas, exit_aas_emulator, shutdown
|
||||||
|
|
||||||
# Group `Cafe`
|
# Group `Cafe`
|
||||||
Cafe_Reward = True
|
Cafe_Reward = True
|
||||||
|
|||||||
@ -225,6 +225,8 @@
|
|||||||
"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",
|
||||||
|
"exit_aas": "Exit AAS",
|
||||||
|
"exit_aas_emulator": "Exit AAS & Emulator",
|
||||||
"shutdown": "Shutdown"
|
"shutdown": "Shutdown"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -225,6 +225,8 @@
|
|||||||
"stay_there": "停在原处",
|
"stay_there": "停在原处",
|
||||||
"goto_main": "前往主界面",
|
"goto_main": "前往主界面",
|
||||||
"close_game": "关闭游戏",
|
"close_game": "关闭游戏",
|
||||||
|
"exit_aas": "exit_aas",
|
||||||
|
"exit_aas_emulator": "exit_aas_emulator",
|
||||||
"shutdown": "shutdown"
|
"shutdown": "shutdown"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -153,6 +153,8 @@ class PlatformWindows(PlatformBase, EmulatorManager):
|
|||||||
elif instance == Emulator.NoxPlayerFamily:
|
elif instance == Emulator.NoxPlayerFamily:
|
||||||
# Nox.exe -clone:Nox_1 -quit
|
# Nox.exe -clone:Nox_1 -quit
|
||||||
self.execute(f'"{exe}" -clone:{instance.name} -quit')
|
self.execute(f'"{exe}" -clone:{instance.name} -quit')
|
||||||
|
elif instance == Emulator.BlueStacks5:
|
||||||
|
self.execute(f'taskkill /fi "WINDOWTITLE eq {instance.name}" /IM "HD-Player.exe" /F')
|
||||||
else:
|
else:
|
||||||
raise EmulatorUnknown(f'Cannot stop an unknown emulator instance: {instance}')
|
raise EmulatorUnknown(f'Cannot stop an unknown emulator instance: {instance}')
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user