Skip to content

Commit

Permalink
fix: do not watch layout for legacy T1B1 emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
grdddj authored and mroz22 committed Jan 20, 2025
1 parent 6b8a027 commit 795cb6e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

# TODO: consider creating a class from this module to avoid these globals
VERSION_RUNNING: str | None = None
MODEL_RUNNING: binaries.Model | None = None
EMULATOR: CoreEmulator | LegacyEmulator | None = None

ROOT_DIR = Path(__file__).resolve().parent.parent
Expand Down Expand Up @@ -225,6 +226,7 @@ def start(
) -> None:
global VERSION_RUNNING
global EMULATOR
global MODEL_RUNNING

binaries.check_model(model)

Expand Down Expand Up @@ -275,9 +277,11 @@ def version_model() -> str:

try:
EMULATOR.start()
VERSION_RUNNING = model
except Exception:
# When emulators fails to start, setting it to empty state not to cause issues later
EMULATOR = None
VERSION_RUNNING = None
raise

log(f"Emulator spawned. PID: {EMULATOR.process.pid}. CMD: {EMULATOR.process.args}") # type: ignore
Expand Down Expand Up @@ -317,6 +321,7 @@ def stop() -> None:
log("Stopping")
global VERSION_RUNNING
global EMULATOR
global MODEL_RUNNING

if EMULATOR is None:
log("WARNING: Attempting to stop emulator, but it is not running", "red")
Expand All @@ -327,6 +332,7 @@ def stop() -> None:
log(f"Emulator killed. PID: {emu_pid}.")
EMULATOR = None
VERSION_RUNNING = None
MODEL_RUNNING = None


def get_current_screen() -> str:
Expand Down Expand Up @@ -362,12 +368,16 @@ def connect_to_client(
time.sleep(SLEEP)

# Needs to be done because some older emulators require this explicitly
client.debug.watch_layout(True)
# Done for all the newer models, does not work with the legacy model
watch_layout = MODEL_RUNNING and MODEL_RUNNING != "T1B1"

try:
if watch_layout:
client.debug.watch_layout(True)
yield client
finally:
client.debug.watch_layout(False)
if watch_layout:
client.debug.watch_layout(False)
client.close()


Expand Down

0 comments on commit 795cb6e

Please sign in to comment.