Skip to content

Commit

Permalink
fix: stuck at ensure adb is running (#79)
Browse files Browse the repository at this point in the history
* fix: add some logs on device manager

* fix: removed connect to devices

* fix: remove unecessary imports

* fix: format
  • Loading branch information
brunocordioli072 authored Mar 15, 2024
1 parent 061bd18 commit 60db829
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions packages/core/epic7_bot/core/DeviceManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ def __init__(self):

def setup_device(self):
self.ensure_adb_is_running()
self.connect_devices_to_adb()

client = Client(host="127.0.0.1", port=5037)
devices = client.devices()
if len(devices) == 0:
logging.error("No device found, are you sure your bluestacks is open?")
sys.exit()
logging.info(f"Found {len(devices)} devices")

device = devices[0]
logging.info(f"Connected to {device.serial}")

devicesWithEpic7 = []
for d in devices:
hasEpic7 = self.ensure_device_has_epic7_app(d)
Expand All @@ -29,8 +31,11 @@ def setup_device(self):
device = d
if all(device is None for device in devicesWithEpic7):
logging.error("No Epic Seven App found in devices.")
logging.info(f"Checked if device {device.serial} has Epic Seven App")


device.shell("wm size 1600x900")
logging.info(f"Set device {device.serial} size to 1600x900")
return device

def ensure_device_has_epic7_app(self, device):
Expand All @@ -48,28 +53,8 @@ def ensure_adb_is_running(self):
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
)
sp.wait()
if (sp.returncode != 0):
logging.error(f"Something went wrong: {str(sp.stderr.read().decode())}")

sp.terminate()

def connect_devices_to_adb(self):
bluestacks_config_path = "C:\\ProgramData\\BlueStacks_nxt\\bluestacks.conf"
with open(bluestacks_config_path, "r") as f:
config = f.readlines()

device_ports = set([])
config = [x.strip().split("=", 1) for x in config if "=" in x]
for c in config:
if "adb_port" in c[0]:
device_ports.add(c[1].replace('"', ""))
sp.wait(timeout=5)
if sp.returncode != 0:
logging.error(f"ensure_adb_is_running - Something went wrong: {str(sp.stderr.read().decode())}")

for port in device_ports:
subprocess.Popen(
["adb", "connect", f"127.0.0.1:{port}"],
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
).wait()
sp.terminate()

0 comments on commit 60db829

Please sign in to comment.