This commit is contained in:
parent
148ab6a8db
commit
15875a3fe0
2 changed files with 13 additions and 21 deletions
|
@ -132,7 +132,7 @@ class ADB:
|
||||||
|
|
||||||
def check_server_status(self) -> str:
|
def check_server_status(self) -> str:
|
||||||
"""Use `adb devices` as `adb start-server`, result is actually useless"""
|
"""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)
|
logger.info(stdout)
|
||||||
return stdout
|
return stdout
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ class DroidCast:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
self.port = 0
|
self.port = 0
|
||||||
self.process = None
|
self.socket = None
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def adb(self) -> ADB:
|
def adb(self) -> ADB:
|
||||||
|
@ -88,27 +88,19 @@ class DroidCast:
|
||||||
logger.info(f"保持DroidCast端口为{port}")
|
logger.info(f"保持DroidCast端口为{port}")
|
||||||
self.adb.adb.forward(f"tcp:{port}", f"tcp:{port}")
|
self.adb.adb.forward(f"tcp:{port}", f"tcp:{port}")
|
||||||
logger.info("ADB端口转发成功,启动DroidCast")
|
logger.info("ADB端口转发成功,启动DroidCast")
|
||||||
self.process = self.adb.process(
|
cmd = f"{class_path} app_process / com.rayworks.droidcast.Main --port={port}"
|
||||||
class_path,
|
self.socket = self.adb.adb_shell(cmd, True)
|
||||||
[
|
|
||||||
"app_process",
|
|
||||||
"/",
|
|
||||||
"com.rayworks.droidcast.Main",
|
|
||||||
f"--port={port}",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
time.sleep(1) # TODO: 更好地等待DroidCast启动
|
time.sleep(1) # TODO: 更好地等待DroidCast启动
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@retry_droidcast
|
@retry_droidcast
|
||||||
def capture_display(self):
|
def capture_display(self):
|
||||||
try:
|
if self.port == 0:
|
||||||
url = f"http://127.0.0.1:{self.port}/screenshot"
|
raise Exception("DroidCast未启动")
|
||||||
logger.debug(f"GET {url}")
|
url = f"http://127.0.0.1:{self.port}/screenshot"
|
||||||
r = self.session.get(url)
|
logger.debug(f"GET {url}")
|
||||||
img = bytes2img(r.content)
|
r = self.session.get(url)
|
||||||
if config.conf.droidcast.rotate:
|
img = bytes2img(r.content)
|
||||||
img = cv2.rotate(img, cv2.ROTATE_180)
|
if config.conf.droidcast.rotate:
|
||||||
return img
|
img = cv2.rotate(img, cv2.ROTATE_180)
|
||||||
except Exception as e:
|
return img
|
||||||
raise e
|
|
||||||
|
|
Loading…
Reference in a new issue