Fix: [ALAS] Re-init MaaTouch when orientation changed

This commit is contained in:
LmeSzinc 2024-04-21 23:36:23 +08:00
parent 670541f515
commit 3757510ecd
3 changed files with 49 additions and 1 deletions

View File

@ -183,6 +183,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))

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
def _maatouch_builder(self):
@ -136,12 +137,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'],

View File

@ -408,6 +408,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")