DroidCast修复
Some checks failed
ci/woodpecker/push/check_format Pipeline failed

This commit is contained in:
zhbaor 2024-12-04 15:20:59 +08:00
parent 148ab6a8db
commit 15875a3fe0
2 changed files with 13 additions and 21 deletions

View file

@ -132,7 +132,7 @@ class ADB:
def check_server_status(self) -> str:
"""Use `adb devices` as `adb start-server`, result is actually useless"""
stdout = self.adb_command(["devices"])
stdout = self.adb_command(["devices"]).strip()
logger.info(stdout)
return stdout

View file

@ -32,7 +32,7 @@ class DroidCast:
def __init__(self):
self.session = requests.Session()
self.port = 0
self.process = None
self.socket = None
@cached_property
def adb(self) -> ADB:
@ -88,21 +88,15 @@ class DroidCast:
logger.info(f"保持DroidCast端口为{port}")
self.adb.adb.forward(f"tcp:{port}", f"tcp:{port}")
logger.info("ADB端口转发成功,启动DroidCast")
self.process = self.adb.process(
class_path,
[
"app_process",
"/",
"com.rayworks.droidcast.Main",
f"--port={port}",
],
)
cmd = f"{class_path} app_process / com.rayworks.droidcast.Main --port={port}"
self.socket = self.adb.adb_shell(cmd, True)
time.sleep(1) # TODO: 更好地等待DroidCast启动
return True
@retry_droidcast
def capture_display(self):
try:
if self.port == 0:
raise Exception("DroidCast未启动")
url = f"http://127.0.0.1:{self.port}/screenshot"
logger.debug(f"GET {url}")
r = self.session.get(url)
@ -110,5 +104,3 @@ class DroidCast:
if config.conf.droidcast.rotate:
img = cv2.rotate(img, cv2.ROTATE_180)
return img
except Exception as e:
raise e