20250904-初步功能已完成

This commit is contained in:
2025-09-05 16:33:03 +08:00
parent 4e705b51f1
commit 8050d8c14c
5 changed files with 77 additions and 136 deletions

View File

@@ -294,109 +294,6 @@ class AiUtils(object):
print(f"btn:{btn}")
return cls.findNumber(btn.label)
# 获取聊天页面的聊天信息
# @classmethod
# def extract_messages_from_xml(cls, xml: str):
# """
# 仅返回当前屏幕中“可见的”聊天内容(含时间分隔)
# """
# from lxml import etree
# root = etree.fromstring(xml.encode("utf-8"))
# items = []
#
# # 判断是否是聊天页面
# is_chat_page = False
# if root.xpath('//XCUIElementTypeStaticText[contains(@traits, "Header")]'):
# is_chat_page = True
# elif root.xpath('//XCUIElementTypeCell//XCUIElementTypeOther[@name or @label]'):
# is_chat_page = True
#
# if not is_chat_page:
# raise Exception("请先进入聊天页面")
#
# # 屏幕宽度
# app = root.xpath('/XCUIElementTypeApplication')
#
# screen_w = cls.parse_float(app[0], 'width', 414.0) if app else 414.0
#
# # 找 Table 的可见范围
# table = root.xpath('//XCUIElementTypeTable')
# if table:
# table = table[0]
# table_top = cls.parse_float(table, 'y', 0.0)
# table_h = cls.parse_float(table, 'height', 0.0)
# table_bottom = table_top + table_h
# else:
# table_top, table_bottom = 0.0, cls.parse_float(app[0], 'height', 736.0) if app else 736.0
#
# def in_view(el) -> bool:
# """元素在聊天区内并且可见"""
# if el.get('visible') != 'true':
# return False
# y = cls.parse_float(el, 'y', -1e9)
# h = cls.parse_float(el, 'height', 0.0)
# by = y + h
# return not (by <= table_top or y >= table_bottom)
#
# # 时间分隔
# for t in root.xpath('//XCUIElementTypeStaticText[contains(@traits, "Header")]'):
# if not in_view(t):
# continue
# txt = (t.get('label') or t.get('name') or t.get('value') or '').strip()
# if txt:
# items.append({'type': 'time', 'text': txt, 'y': cls.parse_float(t, 'y')})
#
# # 消息气泡
# EXCLUDES = {'Heart', 'Lol', 'ThumbsUp', '分享发布内容', '视频贴纸标签页', '双击发送表情'}
#
# msg_nodes = table.xpath(
# './/XCUIElementTypeCell[@visible="true"]'
# '//XCUIElementTypeOther[@visible="true" and (@name or @label) and not(ancestor::XCUIElementTypeCollectionView)]'
# ) if table is not None else []
#
# for o in msg_nodes:
# text = (o.get('label') or o.get('name') or '').strip()
# if not text or text in EXCLUDES:
# continue
# if not in_view(o):
# continue
#
# # 找所在 Cell
# cell = o.getparent()
# while cell is not None and cell.get('type') != 'XCUIElementTypeCell':
# cell = cell.getparent()
#
# x = cls.parse_float(o, 'x')
# y = cls.parse_float(o, 'y')
# w = cls.parse_float(o, 'width')
# right_edge = x + w
#
# direction = None
# # 头像位置判定
# if cell is not None:
# avatar_btns = cell.xpath(
# './/XCUIElementTypeButton[@visible="true" and (@name="图片头像" or @label="图片头像")]')
# if avatar_btns:
# ax = cls.parse_float(avatar_btns[0], 'x')
# direction = 'in' if ax < (screen_w / 2) else 'out'
# # 右对齐兜底
# if direction is None:
# direction = 'out' if right_edge > (screen_w - 20) else 'in'
#
# items.append({'type': 'msg', 'dir': direction, 'text': text, 'y': y})
#
# # 排序 & 清理
# items.sort(key=lambda i: i['y'])
# for it in items:
# it.pop('y', None)
# return items
#
# @classmethod
# def parse_float(cls, el, attr, default=0.0):
# try:
# return float(el.get(attr, default))
# except Exception:
# return default
@classmethod
def extract_messages_from_xml(cls, xml: str):
@@ -407,15 +304,6 @@ class AiUtils(object):
root = etree.fromstring(xml.encode("utf-8"))
items = []
# 判断是否是聊天页面
is_chat_page = False
if root.xpath('//XCUIElementTypeStaticText[contains(@traits, "Header")]'):
is_chat_page = True
elif root.xpath('//XCUIElementTypeCell//XCUIElementTypeOther[@name or @label]'):
is_chat_page = True
if not is_chat_page:
raise Exception("请先进入聊天页面")
# 屏幕宽度
app = root.xpath('/XCUIElementTypeApplication')
@@ -571,5 +459,3 @@ class AiUtils(object):
return t
return ""
# AiUtils.getCurrentScreenSource()