Skip to content

Commit

Permalink
DroidCast修复
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoZuohong committed Jul 10, 2024
1 parent 7f7ff30 commit 745212d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
9 changes: 1 addition & 8 deletions arknights_mower/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from copy import deepcopy
from datetime import datetime, timedelta

import requests
from evalidate import Expr

from arknights_mower import __version__
Expand Down Expand Up @@ -50,13 +49,7 @@ def main():
config.fix_mumu12_adb_disconnect = conf["fix_mumu12_adb_disconnect"]
config.grandet_back_to_index = conf["run_order_grandet_mode"]["back_to_index"]
config.ADB_CONTROL_CLIENT = conf["touch_method"]
if hasattr(config, "droidcast"):
config.droidcast.update(conf["droidcast"])
else:
config.droidcast = conf["droidcast"]
config.droidcast["session"] = requests.Session()
config.droidcast["port"] = 0
config.droidcast["process"] = None
config.droidcast.update(conf["droidcast"])
config.ADB_BINARY = [conf["maa_adb_path"]]

if config.wh is None:
Expand Down
4 changes: 3 additions & 1 deletion arknights_mower/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import shutil
import sys

import requests

try:
from collections.abc import Mapping
except ImportError:
Expand Down Expand Up @@ -157,6 +159,6 @@ def init_adb_buildin() -> Path:
init_config()

conf = {}
droidcast = {"enable": False}
droidcast = {"enable": False, "session": requests.Session(), "port": 0, "process": None}
TAP_TO_LAUNCH = {"enable": False, "x": 0, "y": 0}
stop_mower = None
22 changes: 19 additions & 3 deletions arknights_mower/utils/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,32 @@ def start_droidcast(self) -> bool:
logger.error(f"无法获取CLASSPATH:{out}")
return False
port = config.droidcast["port"]
if port == 0 or is_port_in_use(port):
if port != 0:
self.client.cmd(f"forward --remove tcp:{port}")
if port != 0 and is_port_in_use(port):
try:
occupied_by_adb_forward = False
forward_list = self.client.cmd("forward --list", True).strip().split()
for host, pc_port, android_port in forward_list:
# 127.0.0.1:5555 tcp:60579 tcp:60579
if pc_port != android_port:
# 不是咱转发的,别乱动
continue
if pc_port == f"tcp:{port}":
occupied_by_adb_forward = True
break
if not occupied_by_adb_forward:
port = 0
except Exception:
pass
if port == 0:
port = get_new_port()
config.droidcast["port"] = port
logger.info(f"更新DroidCast端口为{port}")
else:
logger.info(f"保持DroidCast端口为{port}")
self.client.cmd(f"forward tcp:{port} tcp:{port}")
logger.info("ADB端口转发成功,启动DroidCast")
if config.droidcast["process"] is not None:
config.droidcast["process"].terminate()
process = self.client.process(
class_path,
[
Expand Down

0 comments on commit 745212d

Please sign in to comment.