feat(core): 优化主窗口和管理器功能

- 在主窗口中重构初始化逻辑,增强UI组件的管理和信号连接,提升代码可读性。
- 添加资源验证和加载测试功能,确保关键资源文件的完整性和可用性。
- 更新下载管理器和离线模式管理器,优化线程管理和状态更新,提升用户体验。
- 增强日志记录,确保在关键操作中提供详细的调试信息,便于后续排查和用户反馈。
- 删除不再使用的进度窗口创建函数,改为由UIManager管理,提升代码整洁性。
This commit is contained in:
hyb-oyqq
2025-08-11 17:42:52 +08:00
parent dc433a2ac9
commit 68bbafc564
12 changed files with 842 additions and 551 deletions

View File

@@ -4,8 +4,8 @@ import datetime
from PySide6.QtWidgets import QApplication, QMessageBox
from main_window import MainWindow
from core.managers.privacy_manager import PrivacyManager
from utils.logger import setup_logger
from config.config import LOG_FILE, APP_NAME
from utils.logger import setup_logger, cleanup_old_logs
from config.config import LOG_FILE, APP_NAME, LOG_RETENTION_DAYS
from utils import load_config
if __name__ == "__main__":
@@ -17,6 +17,10 @@ if __name__ == "__main__":
config = load_config()
debug_mode = config.get("debug_mode", False)
# 在应用启动时清理过期的日志文件
cleanup_old_logs(LOG_RETENTION_DAYS)
logger.info(f"已执行日志清理,保留最近{LOG_RETENTION_DAYS}天的日志")
# 如果调试模式已启用,确保立即创建主日志文件
if debug_mode:
try:
@@ -26,14 +30,13 @@ if __name__ == "__main__":
os.makedirs(log_dir, exist_ok=True)
logger.info(f"已创建日志目录: {log_dir}")
# 创建新的日志文件(使用覆盖模式)
with open(LOG_FILE, 'w', encoding='utf-8') as f:
current_time = datetime.datetime.now()
formatted_date = current_time.strftime("%Y-%m-%d")
formatted_time = current_time.strftime("%H:%M:%S")
f.write(f"--- 新调试会话开始于 {os.path.basename(LOG_FILE)} ---\n")
f.write(f"--- 应用版本: {APP_NAME} ---\n")
f.write(f"--- 日期: {formatted_date} 时间: {formatted_time} ---\n\n")
# 记录调试会话信息
logger.info(f"--- 新调试会话开始于 {os.path.basename(LOG_FILE)} ---")
logger.info(f"--- 应用版本: {APP_NAME} ---")
current_time = datetime.datetime.now()
formatted_date = current_time.strftime("%Y-%m-%d")
formatted_time = current_time.strftime("%H:%M:%S")
logger.info(f"--- 日期: {formatted_date} 时间: {formatted_time} ---")
logger.info(f"调试模式已启用,日志文件路径: {os.path.abspath(LOG_FILE)}")
except Exception as e: