解决打招呼消息的bug

This commit is contained in:
zw
2025-09-08 19:16:05 +08:00
parent a6d5330c73
commit 7a8380af9c
4 changed files with 48 additions and 71 deletions

View File

@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
import os
import signal
import sys
import time
import json
import wda
import threading
import subprocess
@@ -30,7 +28,6 @@ class Deviceinfo(object):
self._lock = threading.Lock()
self._pending_udids = set()
try:
self.iproxy_path = self._iproxy_path()
self.iproxy_dir = self.iproxy_path.parent
@@ -96,7 +93,6 @@ class Deviceinfo(object):
continue
now_udids = {d.udid for d in lists if d.conn_type == ConnectionType.USB}
# 1. 处理“已插入但未信任”的设备,一旦信任就补连接
for udid in list(self._pending_udids):
if udid not in now_udids:
@@ -281,7 +277,6 @@ class Deviceinfo(object):
if not self._spawn_iproxy:
LogManager.error("iproxy 启动器未就绪,无法建立端口映射(初始化时未找到 iproxy", udid)
return None
try:
p = self._spawn_iproxy(udid, self.screenProxy, 9100)
LogManager.info(f"启动 iproxy 成功,本地 {self.screenProxy} -> 设备 9100", udid)

View File

@@ -16,15 +16,17 @@ from Entity.ResultData import ResultData
from Utils.ControlUtils import ControlUtils
from Utils.ThreadManager import ThreadManager
from script.ScriptManager import ScriptManager
from Entity.Variables import anchorList, addModelToAnchorList, prologueList, removeModelFromAnchorList
from Entity.Variables import anchorList, prologueList, addModelToAnchorList, removeModelFromAnchorList
import Entity.Variables as ev
app = Flask(__name__)
CORS(app)
app.config['JSON_AS_ASCII'] = False # Flask jsonify 不转义中文/emoji
app.config['JSONIFY_MIMETYPE'] = "application/json; charset=utf-8"
listData = []
dataQueue = Queue()
def start_socket_listener():
port = int(os.getenv('FLASK_COMM_PORT', 0))
LogManager.info(f"Received port from environment: {port}")
@@ -230,43 +232,40 @@ def stopScript():
code, msg = ThreadManager.stop(udid)
return ResultData(code=code, data="", msg=msg).toJson()
# 传递主播数据(关注主播打招呼)
# 关注打招呼
@app.route('/passAnchorData', methods=['POST'])
def passAnchorData():
data: Dict[str, Any] = request.get_json()
# 设备列表
try:
data: Dict[str, Any] = request.get_json()
# 设备列表
idList = data.get("deviceList", [])
# 主播列表
acList = data.get("anchorList", [])
# 是否需要回复
needReply = data.get("needReply", True)
# 获取打招呼数据
ev.prologueList = data.get("prologueList", [])
print("接收的数据", data)
idList = data.get("deviceList", [])
# 主播列表
acList = data.get("anchorList", [])
# 是否需要回复
needReply = data.get("needReply", True)
# 获取打招呼数据
ev.prologueList = data.get("prologueList", [])
# 添加主播数据
addModelToAnchorList(acList)
# 启动线程,执行脚本
for udid in idList:
manager = ScriptManager()
event = threading.Event()
# 启动脚本
thread = threading.Thread(target=manager.safe_greetNewFollowers, args=(udid, needReply, event))
thread.start()
# 添加到线程管理
ThreadManager.add(udid, thread, event)
return ResultData(data="").toJson()
# 添加主播数据
addModelToAnchorList(acList)
# 启动线程,执行脚本
for udid in idList:
manager = ScriptManager()
event = threading.Event()
# 启动脚本
thread = threading.Thread(target=manager.safe_greetNewFollowers, args=(udid, needReply, event))
thread.start()
# 添加到线程管理
ThreadManager.add(udid, thread, event)
return ResultData(data="").toJson()
except Exception as e:
LogManager.error(e)
# 获取私信数据
@app.route("/getPrologueList", methods=['GET'])
def getPrologueList():
print(ev.prologueList)
return ResultData(data=ev.prologueList).toJson()
import Entity.Variables as Variables
return ResultData(data=Variables.prologueList).toJson()
# 添加临时数据
@app.route("/addTempAnchorData", methods=['POST'])