Add: [ALAS] Add interval on dump_hierarchy()

This commit is contained in:
LmeSzinc 2024-07-15 22:09:21 +08:00
parent 83c9fb9b06
commit 00f3bf7495
2 changed files with 26 additions and 0 deletions

View File

@ -1,9 +1,11 @@
from lxml import etree
from module.base.timer import Timer
from module.device.method.adb import Adb
from module.device.method.uiautomator_2 import Uiautomator2
from module.device.method.utils import HierarchyButton
from module.device.method.wsa import WSA
from module.exception import ScriptError
from module.logger import logger
@ -12,6 +14,7 @@ class AppControl(Adb, WSA, Uiautomator2):
# Use ADB for all
# See https://github.com/openatx/uiautomator2/issues/565
_app_u2_family = []
_hierarchy_interval = Timer(0.1)
def app_is_running(self) -> bool:
method = self.config.Emulator_ControlMethod
@ -44,11 +47,28 @@ class AppControl(Adb, WSA, Uiautomator2):
else:
self.app_stop_adb()
def hierarchy_timer_set(self, interval=None):
if interval is None:
interval = 0.1
elif isinstance(interval, (int, float)):
# No limitation for manual set in code
pass
else:
logger.warning(f'Unknown hierarchy interval: {interval}')
raise ScriptError(f'Unknown hierarchy interval: {interval}')
if interval != self._hierarchy_interval.limit:
logger.info(f'Hierarchy interval set to {interval}s')
self._hierarchy_interval.limit = interval
def dump_hierarchy(self) -> etree._Element:
"""
Returns:
etree._Element: Select elements with `self.hierarchy.xpath('//*[@text="Hermit"]')` for example.
"""
self._hierarchy_interval.wait()
self._hierarchy_interval.reset()
# method = self.config.Emulator_ControlMethod
# if method in AppControl._app_u2_family:
# self.hierarchy = self.dump_hierarchy_uiautomator2()

View File

@ -1,6 +1,8 @@
import collections
import itertools
from lxml import etree
# Patch pkg_resources before importing adbutils and uiautomator2
from module.device.pkg_resources import get_distribution
@ -157,6 +159,10 @@ class Device(Screenshot, Control, AppControl):
return self.image
def dump_hierarchy(self) -> etree._Element:
self.stuck_record_check()
return super().dump_hierarchy()
def release_during_wait(self):
# Scrcpy server is still sending video stream,
# stop it during wait