fix: re-init MaaTouch when orientation changes

This commit is contained in:
2026-07-05 23:08:36 +08:00
parent 6d2b536050
commit 7415c7e217
3 changed files with 50 additions and 2 deletions
+10
View File
@@ -164,6 +164,16 @@ class Device(Screenshot, Control, AppControl):
if self.config.Emulator_ScreenshotMethod == 'nemu_ipc':
self.nemu_ipc_release()
def get_orientation(self):
"""
Callbacks when orientation changed.
"""
o = super().get_orientation()
self.on_orientation_change_maatouch()
return o
def stuck_record_add(self, button):
self.detect_record.add(str(button))
+31 -2
View File
@@ -102,9 +102,10 @@ class MaaTouch(Connection):
"""
max_x: int
max_y: int
_maatouch_stream = socket.socket
_maatouch_stream: socket.socket = None
_maatouch_stream_storage = None
_maatouch_init_thread = None
_maatouch_orientation: int = None
@cached_property
@retry
@@ -137,12 +138,40 @@ class MaaTouch(Connection):
self._maatouch_init_thread = thread
thread.start()
def on_orientation_change_maatouch(self):
"""
MaaTouch caches devices orientation at its startup
A restart is required when orientation changed
"""
if self._maatouch_orientation is None:
return
if self.orientation == self._maatouch_orientation:
return
logger.info(f'Orientation changed {self._maatouch_orientation} => {self.orientation}, re-init MaaTouch')
del_cached_property(self, '_maatouch_builder')
self.early_maatouch_init()
def maatouch_init(self):
logger.hr('MaaTouch init')
max_x, max_y = 1280, 720
max_contacts = 2
max_pressure = 50
# Try to close existing stream
if self._maatouch_stream is not None:
try:
self._maatouch_stream.close()
except Exception as e:
logger.error(e)
del self._maatouch_stream
if self._maatouch_stream_storage is not None:
del self._maatouch_stream_storage
# MaaTouch caches devices orientation at its startup
super(MaaTouch, self).get_orientation()
self._maatouch_orientation = self.orientation
# CLASSPATH=/data/local/tmp/maatouch app_process / com.shxyke.MaaTouch.App
stream = self.adb_shell(
['CLASSPATH=/data/local/tmp/maatouch', 'app_process', '/', 'com.shxyke.MaaTouch.App'],
@@ -303,4 +332,4 @@ class MaaTouch(Connection):
if __name__ == '__main__':
self = MaaTouch('src')
self.maatouch_uninstall()
self.maatouch_uninstall()
+9
View File
@@ -409,6 +409,15 @@ class Minitouch(Connection):
max_x, max_y = 1280, 720
max_contacts = 2
max_pressure = 50
# Try to close existing stream
if self._minitouch_client is not None:
try:
self._minitouch_client.close()
except Exception as e:
logger.error(e)
del self._minitouch_client
self.get_orientation()
self._minitouch_port = self.adb_forward("localabstract:minitouch")