Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update emulator.py #195

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions clashroyalebuildabot/emulator/emulator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: disable=consider-using-with

import atexit
from contextlib import contextmanager
import os
Expand Down Expand Up @@ -173,13 +175,18 @@ def _run_command(self, command):
command = [ADB_PATH, "-s", self.serial, *command]
logger.debug(" ".join(command))
try:
start_time = time.time()
result = subprocess.run(
command,
cwd=EMULATOR_DIR,
capture_output=True,
check=True,
text=True,
)
end_time = time.time()
logger.debug(
f"Command executed in {end_time - start_time} seconds"
)
except subprocess.CalledProcessError as e:
logger.error(f"Error executing command: {e}")
logger.error(f"Output: {e.stdout}")
Expand Down Expand Up @@ -220,13 +227,19 @@ def _start_scrcpy(self):
"raw_video_stream=true",
f"max_size={self.width}",
]
with subprocess.Popen(
command,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
cwd=EMULATOR_DIR,
) as proc:
self.scrcpy_proc = proc
logger.debug("Starting scrcpy process")
try:
self.scrcpy_proc = subprocess.Popen(
command,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
cwd=EMULATOR_DIR,
)
logger.debug("scrcpy process started")
except Exception as e:
logger.error(f"Failed to start scrcpy process: {e}")
self.quit()
raise

def _forward_port(self):
self._run_command(
Expand Down Expand Up @@ -266,6 +279,7 @@ def _update_screenshot(self):
continue

self.frame = frames[-1]
time.sleep(0.001)

def _get_width_and_height(self):
window_size = self._run_command(["shell", "wm", "size"])
Expand Down