diff --git a/Module/DeviceInfo.py b/Module/DeviceInfo.py index 8b90693..73aad13 100644 --- a/Module/DeviceInfo.py +++ b/Module/DeviceInfo.py @@ -214,23 +214,23 @@ class Deviceinfo(object): def _removeDisconnected(self, current_list): try: - # 当前在线的 UDID 集合 - now_udids = {d.udid for d in current_list if hasattr(d, 'udid')} + # 当前在线的 deviceId 集合(即 UDID) + now_device_ids = {d.udid for d in current_list if hasattr(d, 'udid')} - # 上一次记录的 UDID 集合 - prev_udids = {d.udid for d in self.deviceArray if hasattr(d, 'udid')} + # 上一次记录的 deviceId 集合 + prev_device_ids = {model.deviceId for model in self.deviceModelList} except Exception as e: - LogManager.error(f"收集 UDID 失败:{e}", "") + LogManager.error(f"收集 deviceId 失败:{e}", "") return - removed_udids = prev_udids - now_udids - if not removed_udids: + removed_device_ids = prev_device_ids - now_device_ids + if not removed_device_ids: return with self._lock: # 清理 deviceModelList for model in list(self.deviceModelList): - if model.deviceId in removed_udids: + if model.deviceId in removed_device_ids: model.type = 2 try: self.manager.send(model.toDict()) @@ -241,7 +241,7 @@ class Deviceinfo(object): # 清理 pidList survivors = [] for item in self.pidList: - if item.get("id") in removed_udids: + if item.get("id") in removed_device_ids: p = item.get("target") try: self._terminate_proc(p) @@ -251,11 +251,14 @@ class Deviceinfo(object): survivors.append(item) self.pidList = survivors - # 清理 deviceArray - self.deviceArray = [d for d in self.deviceArray if d.udid not in removed_udids] + # 清理 deviceArray(也统一用 udid) + self.deviceArray = [d for d in self.deviceArray if getattr(d, 'udid', None) not in removed_device_ids] - for udid in removed_udids: - LogManager.info("设备已拔出,清理完成(下线通知 + 端口映射关闭 + 状态移除)", udid) + # >>> 新增:记录剩余设备数量 <<< + LogManager.info(f"设备拔出完成,当前剩余设备数:{len(self.deviceModelList)}", "") + + for device_id in removed_device_ids: + LogManager.info("设备已拔出,清理完成(下线通知 + 端口映射关闭 + 状态移除)", device_id) def _base_dir(self) -> Path: if getattr(sys, "frozen", False):