优化拔出设备逻辑
This commit is contained in:
@@ -214,23 +214,23 @@ class Deviceinfo(object):
|
|||||||
|
|
||||||
def _removeDisconnected(self, current_list):
|
def _removeDisconnected(self, current_list):
|
||||||
try:
|
try:
|
||||||
# 当前在线的 UDID 集合
|
# 当前在线的 deviceId 集合(即 UDID)
|
||||||
now_udids = {d.udid for d in current_list if hasattr(d, 'udid')}
|
now_device_ids = {d.udid for d in current_list if hasattr(d, 'udid')}
|
||||||
|
|
||||||
# 上一次记录的 UDID 集合
|
# 上一次记录的 deviceId 集合
|
||||||
prev_udids = {d.udid for d in self.deviceArray if hasattr(d, 'udid')}
|
prev_device_ids = {model.deviceId for model in self.deviceModelList}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LogManager.error(f"收集 UDID 失败:{e}", "")
|
LogManager.error(f"收集 deviceId 失败:{e}", "")
|
||||||
return
|
return
|
||||||
|
|
||||||
removed_udids = prev_udids - now_udids
|
removed_device_ids = prev_device_ids - now_device_ids
|
||||||
if not removed_udids:
|
if not removed_device_ids:
|
||||||
return
|
return
|
||||||
|
|
||||||
with self._lock:
|
with self._lock:
|
||||||
# 清理 deviceModelList
|
# 清理 deviceModelList
|
||||||
for model in list(self.deviceModelList):
|
for model in list(self.deviceModelList):
|
||||||
if model.deviceId in removed_udids:
|
if model.deviceId in removed_device_ids:
|
||||||
model.type = 2
|
model.type = 2
|
||||||
try:
|
try:
|
||||||
self.manager.send(model.toDict())
|
self.manager.send(model.toDict())
|
||||||
@@ -241,7 +241,7 @@ class Deviceinfo(object):
|
|||||||
# 清理 pidList
|
# 清理 pidList
|
||||||
survivors = []
|
survivors = []
|
||||||
for item in self.pidList:
|
for item in self.pidList:
|
||||||
if item.get("id") in removed_udids:
|
if item.get("id") in removed_device_ids:
|
||||||
p = item.get("target")
|
p = item.get("target")
|
||||||
try:
|
try:
|
||||||
self._terminate_proc(p)
|
self._terminate_proc(p)
|
||||||
@@ -251,11 +251,14 @@ class Deviceinfo(object):
|
|||||||
survivors.append(item)
|
survivors.append(item)
|
||||||
self.pidList = survivors
|
self.pidList = survivors
|
||||||
|
|
||||||
# 清理 deviceArray
|
# 清理 deviceArray(也统一用 udid)
|
||||||
self.deviceArray = [d for d in self.deviceArray if d.udid not in removed_udids]
|
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:
|
def _base_dir(self) -> Path:
|
||||||
if getattr(sys, "frozen", False):
|
if getattr(sys, "frozen", False):
|
||||||
|
|||||||
Reference in New Issue
Block a user