Skip to content

Commit

Permalink
Update emulator.py (#195)
Browse files Browse the repository at this point in the history
* Update emulator.py

* Ignore pylint with error

---------

Co-authored-by: peter <[email protected]>
  • Loading branch information
Leviaria and Pbatch authored Jul 1, 2024
1 parent 95b079c commit 3fcd566
Showing 1 changed file with 21 additions and 7 deletions.
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

0 comments on commit 3fcd566

Please sign in to comment.