2525from mluascript .maa .lifecycle .runtime import MaaContext
2626from mluascript .maa .types import MaaPaths
2727from mluascript .shared .config import GlobalConfig , config , load_config
28+ from mluascript .shared .logging import logger
2829
2930from .models import (
3031 ConnectAdbRequest ,
@@ -76,6 +77,7 @@ def find_adb(self) -> DeviceActionResult:
7677 self ._adb_page = 0
7778 return DeviceActionResult (ok = True , message = f"已搜索到 { len (self ._adb_raw )} 个 ADB 设备" , overview = self .get_overview ())
7879 except Exception as exc :
80+ logger .error (f"Device operation failed: { exc } " , exc_info = True )
7981 return DeviceActionResult (ok = False , message = f"搜索 ADB 设备失败: { exc } " , severity = "error" , overview = self .get_overview ())
8082
8183 def find_desktop (self ) -> DeviceActionResult :
@@ -84,6 +86,7 @@ def find_desktop(self) -> DeviceActionResult:
8486 self ._desktop_page = 0
8587 return DeviceActionResult (ok = True , message = f"已搜索到 { len (self ._desktop_raw )} 个{ current_desktop_label ()} " , overview = self .get_overview ())
8688 except Exception as exc :
89+ logger .error (f"Device operation failed: { exc } " , exc_info = True )
8790 return DeviceActionResult (ok = False , message = f"搜索本地窗口失败: { exc } " , severity = "error" , overview = self .get_overview ())
8891
8992 def change_adb_page (self , delta : int ) -> DeviceOverview :
@@ -107,6 +110,7 @@ def connect_adb(self, request: ConnectAdbRequest) -> DeviceActionResult:
107110 self ._maa_facade .attach_session (session )
108111 return DeviceActionResult (ok = True , message = f"已连接 ADB 设备: { address } " , overview = self .get_overview ())
109112 except Exception as exc :
113+ logger .error (f"Device operation failed: { exc } " , exc_info = True )
110114 return DeviceActionResult (ok = False , message = f"连接 ADB 失败: { exc } " , severity = "error" , overview = self .get_overview ())
111115
112116 def connect_device (self , action_id : str ) -> DeviceActionResult :
@@ -125,6 +129,7 @@ def disconnect_device(self) -> DeviceActionResult:
125129 self ._maa_facade .clear_session ()
126130 return DeviceActionResult (ok = True , message = "已断开当前设备连接" , overview = self .get_overview ())
127131 except Exception as exc :
132+ logger .error (f"Device operation failed: { exc } " , exc_info = True )
128133 return DeviceActionResult (ok = False , message = f"断开设备连接失败: { exc } " , severity = "error" , overview = self .get_overview ())
129134
130135 def _capture_current_screenshot_result (self ) -> DeviceActionResult :
@@ -168,6 +173,8 @@ def _capture_current_screenshot_result(self) -> DeviceActionResult:
168173 )
169174
170175 except Exception as exc :
176+
177+ logger .error (f"Device operation failed: { exc } " , exc_info = True )
171178 return DeviceActionResult (
172179 ok = False ,
173180 message = f"截图处理时发生异常: { exc } " ,
@@ -193,6 +200,7 @@ def screencap_current_and_save(self) -> DeviceActionResult:
193200 result .saved_path = screenshot_path .as_posix ()
194201 return result
195202 except Exception as exc :
203+ logger .error (f"Device operation failed: { exc } " , exc_info = True )
196204 return DeviceActionResult (
197205 ok = False ,
198206 message = f"截图保存时发生异常: { exc } " ,
@@ -224,6 +232,7 @@ def _connect_adb_item(self, action_id: str) -> DeviceActionResult:
224232 self ._maa_facade .attach_session (session )
225233 return DeviceActionResult (ok = True , message = f"已连接 ADB 设备: { params .address } " , overview = self .get_overview ())
226234 except Exception as exc :
235+ logger .error (f"Device operation failed: { exc } " , exc_info = True )
227236 return DeviceActionResult (ok = False , message = f"连接 ADB 设备失败: { exc } " , severity = "error" , overview = self .get_overview ())
228237
229238 def _connect_desktop_item (self , action_id : str ) -> DeviceActionResult :
@@ -246,6 +255,7 @@ def _connect_desktop_item(self, action_id: str) -> DeviceActionResult:
246255 window_name = str (window .get ("window_name" ) or handle or backend )
247256 return DeviceActionResult (ok = True , message = f"已连接{ current_desktop_label ()} : { window_name } " , overview = self .get_overview ())
248257 except Exception as exc :
258+ logger .error (f"Device operation failed: { exc } " , exc_info = True )
249259 return DeviceActionResult (ok = False , message = f"连接本地窗口失败: { exc } " , severity = "error" , overview = self .get_overview ())
250260
251261 def _connect_emulator_item (self , action_id : str ) -> DeviceActionResult :
@@ -271,6 +281,7 @@ def _connect_emulator_item(self, action_id: str) -> DeviceActionResult:
271281 self ._maa_facade .attach_session (session )
272282 return DeviceActionResult (ok = True , message = f"已连接模拟器设备: { device .name } " , overview = self .get_overview ())
273283 except Exception as exc :
284+ logger .error (f"Device operation failed: { exc } " , exc_info = True )
274285 return DeviceActionResult (ok = False , message = f"连接模拟器设备失败: { exc } " , severity = "error" , overview = self .get_overview ())
275286
276287 def _build_connection_state (self ) -> DeviceConnectionState :
@@ -401,6 +412,7 @@ def _connect_browser_item(self, action_id: str) -> DeviceActionResult:
401412 self ._maa_facade .attach_session (session )
402413 return DeviceActionResult (ok = True , message = f"已连接浏览器设备: { device .name } " , overview = self .get_overview ())
403414 except Exception as exc :
415+ logger .error (f"Device operation failed: { exc } " , exc_info = True )
404416 return DeviceActionResult (ok = False , message = f"连接浏览器设备失败: { exc } " , severity = "error" , overview = self .get_overview ())
405417
406418 def _get_device_config (self ) -> MaaDeviceConfig :
0 commit comments