使用MuMuManger阻塞重启mumu
This commit is contained in:
parent
6da80a42ff
commit
6222d7ac2a
2 changed files with 57 additions and 0 deletions
|
@ -5,6 +5,7 @@ from enum import Enum
|
|||
from mower import __system__
|
||||
from mower.utils import config
|
||||
from mower.utils.csleep import MowerExit, csleep
|
||||
from mower.utils.device.method.mumumanager import MuMuManager
|
||||
from mower.utils.log import logger
|
||||
|
||||
|
||||
|
@ -126,6 +127,14 @@ def exec_cmd(cmd, folder_path, wait_time):
|
|||
raise
|
||||
except subprocess.TimeoutExpired:
|
||||
wait_time -= 1
|
||||
elif config.conf.emulator.name == Emulator_Type.MuMu12.value:
|
||||
start_time = datetime.now()
|
||||
while (datetime.now() - start_time).total_seconds() < wait_time:
|
||||
if MuMuManager().check_android_process():
|
||||
csleep(5) # adb不一定能完全连
|
||||
return True
|
||||
csleep(1)
|
||||
|
||||
else:
|
||||
start_time = datetime.now()
|
||||
while (datetime.now() - start_time).total_seconds() < wait_time:
|
||||
|
|
48
mower/utils/device/method/mumumanager.py
Normal file
48
mower/utils/device/method/mumumanager.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
import json
|
||||
|
||||
from mower.utils import config
|
||||
from mower.utils.log import logger
|
||||
|
||||
from .utils import subprocess_run
|
||||
|
||||
|
||||
class MuMuManager:
|
||||
manager_path = config.conf.emulator.emulator_folder + "\\MuMuManager.exe"
|
||||
index = config.conf.emulator.index
|
||||
|
||||
def get_emulator_info(self):
|
||||
command = [self.manager_path, "info", "-v", str(self.index)]
|
||||
output = subprocess_run(command)
|
||||
|
||||
try:
|
||||
data = json.loads(output)
|
||||
return data
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"JSON 解析失败: {e}")
|
||||
return {}
|
||||
|
||||
def get_field_value(self, field_name):
|
||||
"""
|
||||
从模拟器信息中提取指定字段的值
|
||||
Args:
|
||||
field_name (str): 字段名称
|
||||
|
||||
Returns:
|
||||
str, int, bool, or None: 字段: 字段值或错误消息
|
||||
"""
|
||||
# 获取模拟器信息
|
||||
data = self.get_emulator_info()
|
||||
if not data:
|
||||
logger.error("未能获取数据")
|
||||
return
|
||||
|
||||
# 提取指定字段的值
|
||||
value = data.get(field_name, None)
|
||||
if value is None:
|
||||
logger.error(f"字段 '{field_name}' 不存在")
|
||||
return
|
||||
|
||||
return value
|
||||
|
||||
def check_android_process(self) -> bool:
|
||||
return self.get_field_value("is_android_started")
|
Loading…
Add table
Add a link
Reference in a new issue