2024-12-22 15:02:42 +08:00
|
|
|
import sys
|
2025-08-07 00:31:24 +08:00
|
|
|
import os
|
|
|
|
|
import datetime
|
2025-07-31 14:38:12 +08:00
|
|
|
from PySide6.QtWidgets import QApplication, QMessageBox
|
2025-07-16 16:18:39 +08:00
|
|
|
from main_window import MainWindow
|
2025-07-31 10:59:42 +08:00
|
|
|
from core.privacy_manager import PrivacyManager
|
2025-07-31 14:38:12 +08:00
|
|
|
from utils.logger import setup_logger
|
2025-08-07 00:31:24 +08:00
|
|
|
from data.config import LOG_FILE, APP_NAME
|
|
|
|
|
from utils import load_config
|
2024-12-22 15:02:42 +08:00
|
|
|
|
2025-02-05 21:08:56 +08:00
|
|
|
if __name__ == "__main__":
|
2025-08-07 00:31:24 +08:00
|
|
|
# 设置主日志
|
2025-07-31 14:38:12 +08:00
|
|
|
logger = setup_logger("main")
|
|
|
|
|
logger.info("应用启动")
|
|
|
|
|
|
2025-08-07 00:31:24 +08:00
|
|
|
# 检查配置中是否启用了调试模式
|
|
|
|
|
config = load_config()
|
|
|
|
|
debug_mode = config.get("debug_mode", False)
|
|
|
|
|
|
|
|
|
|
# 如果调试模式已启用,确保立即创建主日志文件
|
|
|
|
|
if debug_mode:
|
|
|
|
|
try:
|
|
|
|
|
# 确保log目录存在
|
|
|
|
|
log_dir = os.path.dirname(LOG_FILE)
|
|
|
|
|
if not os.path.exists(log_dir):
|
|
|
|
|
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.abspath(LOG_FILE)}")
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"创建日志文件失败: {e}")
|
|
|
|
|
|
2025-07-16 16:18:39 +08:00
|
|
|
app = QApplication(sys.argv)
|
2025-07-31 10:59:42 +08:00
|
|
|
|
2025-07-31 14:38:12 +08:00
|
|
|
try:
|
|
|
|
|
privacy_manager = PrivacyManager()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"初始化隐私协议管理器失败: {e}")
|
|
|
|
|
QMessageBox.critical(
|
|
|
|
|
None,
|
|
|
|
|
"隐私协议加载错误",
|
|
|
|
|
f"无法加载隐私协议管理器,程序将退出。\n\n错误信息:{e}"
|
|
|
|
|
)
|
|
|
|
|
sys.exit(1)
|
2025-07-31 10:59:42 +08:00
|
|
|
|
|
|
|
|
if not privacy_manager.show_privacy_dialog():
|
2025-07-31 14:38:12 +08:00
|
|
|
logger.info("用户未同意隐私协议,程序退出")
|
2025-08-04 12:46:59 +08:00
|
|
|
sys.exit(0)
|
2025-07-31 10:59:42 +08:00
|
|
|
|
2025-07-31 14:38:12 +08:00
|
|
|
logger.info("隐私协议已同意,启动主程序")
|
2025-07-15 16:30:50 +08:00
|
|
|
window = MainWindow()
|
2024-12-22 15:02:42 +08:00
|
|
|
window.show()
|
2025-07-15 16:30:50 +08:00
|
|
|
sys.exit(app.exec())
|