Todo: 集成多平台 解决PDD打包后js文件位置检索问题

Todo: 集成多平台 解决打包日志规划问题
Todo: 集成多平台 解决后端连接心跳与重连管理问题
This commit is contained in:
2025-09-20 16:13:23 +08:00
parent 7cfc0c22b7
commit 8ad02b4416
6 changed files with 447 additions and 64 deletions

View File

@@ -8,6 +8,7 @@
@Date 2025/7/17 16:44
"""
import os
import sys
import threading
from concurrent.futures import ThreadPoolExecutor
import base64
@@ -1959,7 +1960,8 @@ class ChatPdd:
@staticmethod
def check_js_files():
"""检查JS文件是否存在"""
current_dir = "static/js"
# 使用资源路径解析函数
current_dir = ChatPdd._get_resource_path("static/js")
required_files = ["dencode_message.js", "encode_message.js"]
for file in required_files:
@@ -1968,15 +1970,65 @@ class ChatPdd:
raise FileNotFoundError(f"找不到必需的JS文件: {file_path}")
return True
@staticmethod
def _get_resource_path(relative_path):
"""获取资源文件的绝对路径兼容PyInstaller打包环境"""
try:
print(f"[DEBUG] 正在解析资源路径: {relative_path}")
# PyInstaller环境下的基础路径
if hasattr(sys, '_MEIPASS'):
# PyInstaller 临时目录
base_path = sys._MEIPASS
print(f"[DEBUG] 检测到PyInstaller环境_MEIPASS: {base_path}")
elif hasattr(sys, 'frozen') and sys.frozen:
# 其他打包环境
base_path = os.path.dirname(sys.executable)
print(f"[DEBUG] 检测到其他打包环境executable目录: {base_path}")
else:
# 开发环境
base_path = os.path.dirname(os.path.abspath(__file__))
# 向上两级目录到项目根目录
base_path = os.path.dirname(os.path.dirname(base_path))
print(f"[DEBUG] 开发环境,计算的项目根目录: {base_path}")
resource_path = os.path.join(base_path, relative_path)
print(f"[DEBUG] 拼接后的完整资源路径: {resource_path}")
# 检查路径是否存在
if os.path.exists(resource_path):
print(f"[DEBUG] ✅ 资源路径存在: {resource_path}")
else:
print(f"[DEBUG] ❌ 资源路径不存在: {resource_path}")
# 尝试列出基础路径的内容
print(f"[DEBUG] 基础路径 {base_path} 的内容:")
try:
for item in os.listdir(base_path):
item_path = os.path.join(base_path, item)
if os.path.isdir(item_path):
print(f"[DEBUG] 📁 {item}/")
else:
print(f"[DEBUG] 📄 {item}")
except Exception as e:
print(f"[DEBUG] 无法列出目录内容: {e}")
return resource_path
except Exception as e:
print(f"[ERROR] 获取资源路径失败: {e}")
import traceback
print(f"[ERROR] 堆栈跟踪: {traceback.format_exc()}")
# 降级处理:返回相对路径
return relative_path
def __init__(self, cookie, chat_list_stat, csname=None, text=None, log_callback=None):
# 检查JS文件
self.check_js_files()
# 获取JS文件路径
current_dir = "static/js"
dencode_js_path = os.path.join(current_dir, "dencode_message.js")
encode_js_path = os.path.join(current_dir, "encode_message.js")
# 获取JS文件路径 - 使用资源路径解析
js_dir = self._get_resource_path("static/js")
dencode_js_path = os.path.join(js_dir, "dencode_message.js")
encode_js_path = os.path.join(js_dir, "encode_message.js")
# 读取JS文件
try: