diff --git a/README.md b/README.md index 402bd0e..43dfbb3 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,15 @@ - 🔧 优化:路径配置统一化 - 使用 `path_config.py` 统一管理所有文件路径 - 简化路径配置逻辑,提高代码可维护性 +- 🔧 优化:行为日志系统 + - 修复行为日志路径问题,统一使用 `path_config.get_actions_log_path()` + - 修复 GUI 和 Web GUI 中的日志读取路径 + - 实现完整的行为日志查看器组件 - 📝 更新:完善文档和流程图 - 更新流程图以反映30分钟超时检查 - 修正阶段诊断步骤编号 - 完善预约回退子流程图 + - 更新代码结构说明,反映模块化重构 ### V3.3.2 (2025-12-25) @@ -294,35 +299,46 @@ pytest tests/unit/test_example.py::test_some_behavior -q ``` ┌─────────────────────────────────────────┐ -│ GUI / Web GUI / CLI │ -│ (用户界面层) │ +│ GUI / Web GUI / CLI (用户界面层) │ +│ gui_app.py / web_gui.py / run_cli.py │ └──────────────┬──────────────────────────┘ │ ┌──────────────▼──────────────────────────┐ -│ douyin_fudai.py │ -│ (核心调度器 - 主流程控制) │ +│ douyin/core/douyin_fudai.py │ +│ fudai_analyse (Mixin 组合模式) │ +│ (核心调度器 - 主流程控制) │ └──────────────┬──────────────────────────┘ │ ┌──────────┼──────────┐ │ │ │ ┌───▼───┐ ┌───▼───┐ ┌───▼───┐ │阶段诊断│ │福袋核心│ │弹窗处理│ -│stage │ │core │ │popups │ +│stage/ │ │fudai/ │ │handlers│ └───────┘ └───────┘ └───────┘ │ │ │ └──────────┼──────────┘ │ ┌──────────────▼──────────────────────────┐ -│ Underlying_Operations.py │ -│ (底层操作封装 - ADB/OCR) │ +│ operations/ (底层操作模块) │ +│ device / screenshot / ocr │ └──────────────┬──────────────────────────┘ │ ┌──────────────▼──────────────────────────┐ -│ ADB / PaddleOCR │ -│ (系统底层接口) │ +│ path_config.py (路径配置) │ +│ 统一管理所有文件路径 │ +└──────────────┬──────────────────────────┘ + │ +┌──────────────▼──────────────────────────┐ +│ ADB / PaddleOCR (系统底层接口) │ └─────────────────────────────────────────┘ ``` +**设计特点**: +- **模块化设计**:功能按模块划分,便于维护和扩展 +- **Mixin 模式**:核心类使用 Mixin 组合,功能解耦 +- **路径统一管理**:所有路径通过 `path_config.py` 统一配置 +- **日志系统**:统一日志和行为日志分离,便于调试和分析 + --- ## 💻 环境要求与安装 @@ -852,77 +868,160 @@ python run_cli.py \ ## 📁 代码结构 -### 核心模块 +### 项目架构 -#### `douyin_fudai.py` +项目采用模块化设计,主要代码位于 `douyin/` 目录下,按功能划分为多个子模块: + +``` +douyin_guaji-main/ +├── douyin/ # 核心业务逻辑模块 +│ ├── core/ # 核心调度和主流程 +│ │ ├── douyin_fudai.py # 主类 fudai_analyse(Mixin 组合) +│ │ ├── douyin_main_flow.py # 主流程控制器 +│ │ ├── douyin_flow_control.py # 流程控制 +│ │ └── fudai_modules/ # 功能模块(Mixin) +│ │ ├── fudai_navigation.py # 导航功能 +│ │ ├── fudai_stage_detection.py # 阶段检测 +│ │ ├── fudai_popup_handler.py # 弹窗处理 +│ │ ├── fudai_lottery_result.py # 抽奖结果 +│ │ ├── fudai_room_utils.py # 直播间工具 +│ │ └── fudai_main_logic.py # 主逻辑 +│ ├── detection/ # 检测模块 +│ │ ├── douyin_detection.py # 综合检测逻辑 +│ │ └── douyin_pixel.py # 像素检测 +│ ├── stage/ # 阶段诊断模块 +│ │ ├── douyin_stage.py # 阶段诊断核心 +│ │ └── douyin_stage_handler.py # 阶段处理 +│ ├── fudai/ # 福袋相关模块 +│ │ ├── douyin_fudai_core.py # 福袋核心逻辑 +│ │ ├── douyin_fudai_detail.py # 福袋详情 +│ │ ├── douyin_fudai_finder.py # 福袋查找 +│ │ └── core/ # 福袋核心子模块 +│ ├── handlers/ # 处理器模块 +│ │ ├── douyin_popup_handler.py # 弹窗处理 +│ │ ├── douyin_screenshot_handler.py # 截图处理 +│ │ └── douyin_swipe_handler.py # 滑动处理 +│ ├── reservation/ # 预约模块 +│ │ ├── douyin_reservation_logic.py # 预约逻辑 +│ │ └── douyin_reservation_handler.py # 预约处理 +│ ├── logging/ # 日志模块 +│ │ ├── douyin_logging.py # 日志系统 +│ │ ├── douyin_logging_wrapper.py # 日志包装器 +│ │ └── douyin_logger.py # 日志器 +│ ├── other/ # 其他功能模块 +│ │ ├── douyin_yanghao.py # 养号功能 +│ │ ├── douyin_robot.py # 人机验证 +│ │ └── douyin_popups.py # 弹窗检测 +│ └── utils/ # 工具模块 +│ ├── douyin_config.py # 配置工具 +│ └── douyin_helpers.py # 辅助函数 +├── gui/ # GUI 界面模块 +│ ├── gui_app.py # 桌面 GUI +│ ├── web_gui.py # Web GUI 服务 +│ └── components/ # GUI 组件 +├── operations/ # 底层操作模块 +│ ├── device_operations.py # 设备操作 +│ ├── screenshot_operations.py # 截图操作 +│ └── ocr_operations.py # OCR 操作 +├── fudai_detail_modules/ # 福袋详情页模块 +├── path_config.py # 路径配置统一管理 +├── Underlying_Operations.py # 底层操作封装(兼容旧代码) +└── run_cli.py # 命令行入口 +``` + +### 核心模块说明 + +#### `douyin/core/douyin_fudai.py` - **职责**:核心调度器,主流程控制 -- **主要类**:`fudai_analyse` +- **主要类**:`fudai_analyse`(使用 Mixin 模式组合功能) +- **设计模式**:Mixin 组合模式,将功能拆分到 `fudai_modules/` 下的各个模块 - **主要方法**: - `fudai_choujiang()`:主循环入口 - `run_once_basic()`:单次循环执行 - `load_config()`:加载配置 - `_diagnose_stage_from_current_screen()`:阶段诊断入口 - - `_check_in_live_room_by_icon()`:直播间检测 -#### `douyin_stage.py` -- **职责**:阶段诊断模块 -- **主要函数**:`diagnose_stage_from_current_screen()` -- **检测阶段**: +#### `douyin/stage/` - 阶段诊断模块 +- **`douyin_stage.py`**:阶段诊断核心逻辑 + - `diagnose_stage_from_current_screen()`:综合诊断函数 + - 支持的阶段类型: - `IN_LIVE_ROOM`:直播间 - `RECOMMEND_PAGE`:推荐页 - `FOLLOW_LIST`:关注列表 - - `LIVE_LIST`:直播列表 - - `FUDai_DETAIL`:福袋详情页 - - `FUDai_RESULT`:抽奖结果页 + - `LIVE_LIST`:直播列表 + - `FUDai_DETAIL`:福袋详情页 + - `FUDai_RESULT`:抽奖结果页 - `FANSCLUB_JOIN`:粉丝团加入页 - - `LIVE_CLOSED`:直播已结束 + - `LIVE_CLOSED`:直播已结束 +- **`douyin_stage_handler.py`**:阶段处理逻辑,包括直播间检测等 -#### `douyin_pixel.py` -- **职责**:像素检测模块 -- **主要功能**: +#### `douyin/detection/` - 检测模块 +- **`douyin_pixel.py`**:像素检测模块 - 检测弹窗背景颜色 - 检测按钮区域颜色 - 并行采集像素特征 +- **`douyin_detection.py`**:综合检测逻辑,整合像素、模板、OCR 检测 -#### `douyin_fudai_core.py` -- **职责**:福袋核心业务逻辑 -- **主要函数**: +#### `douyin/fudai/` - 福袋模块 +- **`douyin_fudai_core.py`**:福袋核心业务逻辑 - `get_fudai_contain()`:获取福袋信息 - `check_contain()`:检查福袋内容 - `attend_choujiang()`:参与抽奖 - - `check_lucky_draw_result()`:检查开奖结果 - - `get_reward()`:领取奖品 +- **`douyin_fudai_detail.py`**:福袋详情页处理 +- **`douyin_fudai_finder.py`**:福袋图标查找 +- **`core/`**:福袋核心子模块 + - `fudai_filter.py`:福袋筛选逻辑 + - `fudai_result_checker.py`:开奖结果检查 + - `fudai_attend.py`:参与抽奖逻辑 -#### `douyin_popups.py` -- **职责**:弹窗检测与处理 -- **主要函数**: +#### `douyin/handlers/` - 处理器模块 +- **`douyin_popup_handler.py`**:弹窗检测与处理 - `check_coupon_popup()`:检测优惠券弹窗 - `check_shopping_redpacket_popup()`:检测购物红包弹窗 +- **`douyin_screenshot_handler.py`**:截图处理和管理 +- **`douyin_swipe_handler.py`**:滑动操作处理 -#### `douyin_robot.py` -- **职责**:人机验证处理 -- **主要函数**: - - `check_have_robot_analyse()`:检测人机验证 - - `deal_robot_analyse()`:处理人机验证 - - `deal_swipe_robot_analyse()`:处理滑块验证 - -#### `douyin_yanghao.py` -- **职责**:推荐页养号逻辑 -- **主要功能**: - - 点赞操作 - - 收藏操作 - - 评论操作 - - 关键词触发 - -#### `douyin_reservation.py` -- **职责**:高价值福袋预约管理 -- **主要功能**: +#### `douyin/reservation/` - 预约模块 +- **`douyin_reservation_logic.py`**:高价值福袋预约管理 - 预约记录管理 - 高价值直播间记录 - 状态持久化 +- **`douyin_reservation_handler.py`**:预约处理逻辑 + +#### `douyin/logging/` - 日志模块 +- **`douyin_logging.py`**:统一日志系统 +- **`douyin_logging_wrapper.py`**:日志包装器,支持行为日志(actions.log) +- **`douyin_logger.py`**:日志器实现 + +#### `douyin/other/` - 其他功能模块 +- **`douyin_yanghao.py`**:推荐页养号逻辑 + - 点赞、收藏、评论操作 + - 关键词触发 +- **`douyin_robot.py`**:人机验证处理 + - `check_have_robot_analyse()`:检测人机验证 + - `deal_robot_analyse()`:处理人机验证 +- **`douyin_popups.py`**:弹窗检测(兼容旧代码) + +#### `path_config.py` - 路径配置模块 +- **职责**:统一管理所有文件路径 +- **主要函数**: + - `get_project_root()`:项目根目录 + - `get_assets_dir()`:模板图片目录 + - `get_pic_dir()`:截图目录 + - `get_screenshot_path()`:截图文件路径 + - `get_logs_dir()`:日志目录 + - `get_actions_log_path()`:行为日志路径 + - `get_state_dir()`:状态文件目录 + - `get_reservations_path()`:预约状态文件路径 +- **优势**:统一路径管理,便于维护和迁移 + +#### `operations/` - 底层操作模块 +- **`device_operations.py`**:设备连接和操作 +- **`screenshot_operations.py`**:截图获取和处理 +- **`ocr_operations.py`**:OCR 识别操作 #### `Underlying_Operations.py` -- **职责**:底层操作封装 +- **职责**:底层操作封装(兼容旧代码) - **主要类**:`underlying_operations` - **主要方法**: - `get_screenshot()`:获取截图 @@ -1000,7 +1099,8 @@ python run_cli.py \ #### `logs/` - **内容**: - - `unified.log`:统一日志文件 + - `unified.log`:统一日志文件(所有日志) + - `actions.log`:行为日志文件(关键操作记录,用于性能分析和调试) #### `state/` - **内容**: @@ -1283,9 +1383,10 @@ python run_cli.py \ ### Q9: 如何查看运行日志? **A**: -1. GUI/Web GUI 界面实时显示日志 -2. 查看 `logs/unified.log` 文件 -3. 命令行运行时直接在终端查看 +1. **统一日志**:查看 `logs/unified.log` 文件,包含所有运行日志 +2. **行为日志**:查看 `logs/actions.log` 文件,包含关键操作记录(用于性能分析) +3. **GUI/Web GUI**:界面实时显示日志,支持筛选和搜索 +4. **命令行**:运行时直接在终端查看 ### Q10: 脚本卡住了怎么办? diff --git a/check_md_files.py b/check_md_files.py deleted file mode 100644 index 2f6453f..0000000 --- a/check_md_files.py +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -"""检查所有Markdown文件的编码和完整性""" - -import os -import sys -from pathlib import Path - - -def check_md_file(file_path): - """检查单个MD文件""" - issues = [] - try: - # 尝试以UTF-8读取 - with open(file_path, "r", encoding="utf-8") as f: - content = f.read() - - # 检查文件大小 - file_size = os.path.getsize(file_path) - if file_size == 0: - issues.append("文件为空") - - # 检查是否有BOM - if content.startswith("\ufeff"): - issues.append("包含UTF-8 BOM标记") - - # 检查是否有异常字符 - try: - content.encode("utf-8") - except UnicodeEncodeError as e: - issues.append(f"编码错误: {e}") - - # 检查基本格式 - if not content.strip(): - issues.append("文件内容为空(只有空白字符)") - - return issues - - except UnicodeDecodeError as e: - return [f"无法以UTF-8解码: {e}"] - except Exception as e: - return [f"读取文件时出错: {e}"] - - -def main(): - """主函数""" - project_root = Path(__file__).parent - md_files = list(project_root.rglob("*.md")) - - print(f"找到 {len(md_files)} 个Markdown文件\n") - - all_ok = True - for md_file in sorted(md_files): - relative_path = md_file.relative_to(project_root) - issues = check_md_file(md_file) - - if issues: - print(f"[ERROR] {relative_path}") - for issue in issues: - print(f" - {issue}") - all_ok = False - else: - file_size = os.path.getsize(md_file) - print(f"[OK] {relative_path} ({file_size} bytes)") - - print("\n" + "=" * 60) - if all_ok: - print("[SUCCESS] All Markdown files are valid!") - else: - print("[WARNING] Found some issues, please check above") - - return 0 if all_ok else 1 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/douyin/core/state/reservations.json b/douyin/core/state/reservations.json index 272b8d2..3092cdb 100644 --- a/douyin/core/state/reservations.json +++ b/douyin/core/state/reservations.json @@ -1,5 +1,5 @@ { - "updated_ts": 1766906222.6343777, + "updated_ts": 1766906682.4194293, "reason": "startup_clear", "room_pos": 0, "current_room_title": "", diff --git a/douyin/logging/douyin_logging_wrapper.py b/douyin/logging/douyin_logging_wrapper.py index d1868e7..d99f2c7 100644 --- a/douyin/logging/douyin_logging_wrapper.py +++ b/douyin/logging/douyin_logging_wrapper.py @@ -346,10 +346,17 @@ class LoggingWrapper: action_log_line = " ".join(action_parts) # 写入 actions.log 文件 - actions_log_path = os.path.join( - os.path.dirname(__file__), "logs", "actions.log" - ) - log_dir = os.path.dirname(actions_log_path) + # 使用统一的路径配置 + try: + import path_config + actions_log_path = path_config.get_actions_log_path() + log_dir = path_config.get_logs_dir() + except Exception: + # 回退到旧路径(向后兼容) + actions_log_path = os.path.join( + os.path.dirname(__file__), "logs", "actions.log" + ) + log_dir = os.path.dirname(actions_log_path) if log_dir: os.makedirs(log_dir, exist_ok=True) diff --git a/fix_cursor_md_issue.py b/fix_cursor_md_issue.py deleted file mode 100644 index 1085f8b..0000000 --- a/fix_cursor_md_issue.py +++ /dev/null @@ -1,201 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -"""修复 Cursor IDE 无法打开 Markdown 文件的问题""" - -import os -import json -import sys -from pathlib import Path - -def check_file_permissions(file_path): - """检查文件权限""" - issues = [] - try: - if not os.path.exists(file_path): - issues.append("文件不存在") - return issues - - if not os.access(file_path, os.R_OK): - issues.append("文件无读取权限") - - # 检查文件是否被锁定 - try: - with open(file_path, 'r', encoding='utf-8') as f: - f.read(1) - except PermissionError: - issues.append("文件被锁定或无权限") - except Exception as e: - issues.append(f"无法读取文件: {e}") - - except Exception as e: - issues.append(f"检查权限时出错: {e}") - - return issues - -def create_test_md_file(): - """创建一个测试 Markdown 文件""" - test_file = Path("TEST_MARKDOWN.md") - content = """# Test Markdown File - -This is a test file to verify Cursor can open Markdown files. - -## Test Section - -- Item 1 -- Item 2 -- Item 3 - -**Bold text** and *italic text* - -```python -print("Hello, World!") -``` - -""" - try: - with open(test_file, 'w', encoding='utf-8', newline='\n') as f: - f.write(content) - print(f"[OK] 已创建测试文件: {test_file}") - return test_file - except Exception as e: - print(f"[ERROR] 创建测试文件失败: {e}") - return None - -def fix_md_file_encoding(file_path): - """修复单个 MD 文件的编码""" - try: - # 读取文件 - encodings = ['utf-8', 'utf-8-sig', 'gbk', 'gb2312'] - content = None - - for encoding in encodings: - try: - with open(file_path, 'r', encoding=encoding) as f: - content = f.read() - break - except (UnicodeDecodeError, UnicodeError): - continue - - if content is None: - return False, "无法读取文件" - - # 移除BOM - if content.startswith('\ufeff'): - content = content[1:] - - # 确保以UTF-8保存(无BOM,使用LF换行) - with open(file_path, 'w', encoding='utf-8', newline='\n') as f: - f.write(content) - - return True, "已修复" - - except Exception as e: - return False, str(e) - -def main(): - """主函数""" - print("=" * 60) - print("Cursor IDE Markdown 文件修复工具") - print("=" * 60) - print() - - # 检查主要MD文件 - main_files = [ - "MODULARIZATION_SUMMARY.md", - "README.md", - "douyin/README.md", - "douyin/fudai/core/MODULARIZATION_PLAN.md", - ] - - print("检查主要 Markdown 文件...") - print() - - all_ok = True - for file_path_str in main_files: - file_path = Path(file_path_str) - if not file_path.exists(): - print(f"[WARN] {file_path_str} - 文件不存在") - continue - - # 检查权限 - perm_issues = check_file_permissions(file_path) - if perm_issues: - print(f"[ERROR] {file_path_str}") - for issue in perm_issues: - print(f" - {issue}") - all_ok = False - continue - - # 修复编码 - success, message = fix_md_file_encoding(file_path) - if success: - file_size = os.path.getsize(file_path) - print(f"[OK] {file_path_str} ({file_size} bytes) - {message}") - else: - print(f"[ERROR] {file_path_str} - {message}") - all_ok = False - - print() - print("=" * 60) - - # 创建测试文件 - print("创建测试文件...") - test_file = create_test_md_file() - - print() - print("=" * 60) - print("修复建议:") - print("=" * 60) - print() - print("1. 重启 Cursor IDE") - print(" - 完全关闭 Cursor") - print(" - 重新打开 Cursor 和项目") - print() - print("2. 清除 Cursor 缓存") - print(" - 关闭 Cursor") - print(" - 删除以下目录(如果存在):") - print(" - %APPDATA%\\Cursor\\Cache") - print(" - %APPDATA%\\Cursor\\CachedData") - print(" - 重新打开 Cursor") - print() - print("3. 检查 Cursor 设置") - print(" - 打开设置 (Ctrl+,)") - print(" - 搜索 'markdown'") - print(" - 确保 Markdown 预览功能已启用") - print() - print("4. 重新安装 Markdown 扩展") - print(" - 打开扩展面板 (Ctrl+Shift+X)") - print(" - 搜索 'Markdown'") - print(" - 禁用并重新启用相关扩展") - print() - print("5. 使用命令面板") - print(" - 按 Ctrl+Shift+P") - print(" - 输入 'Reload Window'") - print(" - 选择 'Developer: Reload Window'") - print() - print("6. 手动打开文件") - print(" - 在文件资源管理器中找到文件") - print(" - 右键点击 .md 文件") - print(" - 选择 '打开方式' -> 'Cursor'") - print() - - if test_file: - print(f"7. 测试文件") - print(f" - 尝试打开: {test_file}") - print(f" - 如果这个文件能打开,说明是特定文件的问题") - print(f" - 如果这个文件也不能打开,说明是 Cursor 的配置问题") - print() - - print("=" * 60) - - if all_ok: - print("[SUCCESS] 所有文件检查通过") - print("如果仍然无法打开,请按照上述建议操作") - else: - print("[WARNING] 发现一些问题,请查看上面的详细信息") - - return 0 if all_ok else 1 - -if __name__ == "__main__": - sys.exit(main()) - diff --git a/gui/components/actions_log_viewer.py b/gui/components/actions_log_viewer.py index 4982c3e..5e1595d 100644 --- a/gui/components/actions_log_viewer.py +++ b/gui/components/actions_log_viewer.py @@ -5,10 +5,11 @@ from __future__ import annotations -from typing import Any, Callable, Tuple +from typing import Any, Callable, Tuple, Optional import tkinter as tk from tkinter import ttk from tkinter.scrolledtext import ScrolledText +import os try: from ttkbootstrap.scrolled import ScrolledText as TBSrolledText @@ -18,12 +19,14 @@ except ImportError: def create_actions_log_viewer( - parent: Any + parent: Any, + filter_var: Optional[tk.StringVar] = None ): """创建行为日志查看器组件。 参数: parent: 父容器 + filter_var: 可选的筛选关键字变量(StringVar),如果提供则用于筛选日志 返回: (actions_log_text, refresh_actions_log_func) @@ -37,9 +40,78 @@ def create_actions_log_viewer( pass def refresh_actions_log() -> None: - """刷新行为日志。""" - # TODO: 从原文件迁移函数实现 - pass + """刷新行为日志:读取 logs/actions.log 的尾部若干行,在 GUI 中展示关键行为日志(支持简单关键字筛选)。""" + # 使用统一的路径配置 + try: + import path_config + path = path_config.get_actions_log_path() + except Exception: + # 回退到旧路径(向后兼容) + path = os.path.join(os.path.dirname(__file__), "..", "logs", "actions.log") + path = os.path.abspath(path) + + try: + if os.path.exists(path): + # 仿照 web_gui 的实现:只读最后一小段,避免文件巨大 + size = os.path.getsize(path) + if size == 0: + actions_log_text.delete("1.0", "end") + actions_log_text.insert("1.0", "行为日志文件为空") + return + + read_bytes = min(size, 65536) + with open(path, "rb") as f: + if read_bytes < size: + f.seek(-read_bytes, os.SEEK_END) + data = f.read() + # 尝试多种编码方式 + try: + # 先尝试 utf-8-sig(带BOM) + text = data.decode("utf-8-sig", errors="replace") + except Exception: + try: + # 再尝试 utf-8 + text = data.decode("utf-8", errors="replace") + except Exception: + # 最后尝试 gbk(Windows常见编码) + text = data.decode("gbk", errors="replace") + lines = text.splitlines() + # 只取最近 300 行 + tail = lines[-300:] + + # 关键字筛选:若提供了筛选变量且填写了筛选词,只保留包含该关键字的行 + if filter_var is not None: + kw = filter_var.get().strip() + if kw: + tail = [ln for ln in tail if kw in ln] + + # 保存当前滚动位置,避免刷新时自动置顶 + try: + scroll_position = actions_log_text.yview()[0] # 获取当前滚动位置(顶部可见位置的比例) + except Exception: + scroll_position = 0.0 + + actions_log_text.delete("1.0", "end") + if tail: + actions_log_text.insert("1.0", "\n".join(tail)) + else: + actions_log_text.insert("1.0", "暂无匹配的行为日志") + + # 恢复之前的滚动位置,避免自动置顶 + try: + actions_log_text.yview_moveto(scroll_position) + except Exception: + pass + else: + actions_log_text.delete("1.0", "end") + actions_log_text.insert( + "1.0", "暂无行为日志(logs/actions.log 不存在)" + ) + except Exception as e: + actions_log_text.delete("1.0", "end") + actions_log_text.insert( + "1.0", f"读取行为日志失败: {str(e)}" + ) return actions_log_text, refresh_actions_log diff --git a/gui/gui_app.py b/gui/gui_app.py index f8b31e3..4cd2f3b 100644 --- a/gui/gui_app.py +++ b/gui/gui_app.py @@ -3167,7 +3167,13 @@ def main(): def refresh_actions_log(): """读取 logs/actions.log 的尾部若干行,在 GUI 中展示关键行为日志(支持简单关键字筛选)。""" - path = os.path.join(os.path.dirname(__file__), "logs", "actions.log") + # 使用统一的路径配置 + try: + from path_config import get_actions_log_path + path = get_actions_log_path() + except Exception: + # 回退到旧路径(向后兼容) + path = os.path.join(os.path.dirname(__file__), "logs", "actions.log") try: if os.path.exists(path): # 仿照 web_gui 的实现:只读最后一小段,避免文件巨大 diff --git a/gui/web_gui.py b/gui/web_gui.py index cbebe49..cf07971 100644 --- a/gui/web_gui.py +++ b/gui/web_gui.py @@ -1549,7 +1549,13 @@ class Handler(BaseHTTPRequestHandler): n = int((qs.get("lines") or [200])[0]) except Exception: n = 200 - path = os.path.join(BASE_DIR, "logs", "actions.log") + # 使用统一的路径配置 + try: + import path_config + path = path_config.get_actions_log_path() + except Exception: + # 回退到旧路径(向后兼容) + path = os.path.join(BASE_DIR, "logs", "actions.log") out_lines: list[str] = [] try: if os.path.exists(path): diff --git a/path_config.py b/path_config.py index bd1ecc4..32b95c2 100644 --- a/path_config.py +++ b/path_config.py @@ -28,6 +28,11 @@ def get_log_file_path() -> str: return os.path.join(PROJECT_ROOT, "logs", "unified.log") +def get_actions_log_path() -> str: + """返回行为日志文件 (actions.log) 的路径""" + return os.path.join(PROJECT_ROOT, "logs", "actions.log") + + def get_pic_dir() -> str: """返回 pic 目录的路径(OCR截图、临时截图等)""" return os.path.join(PROJECT_ROOT, "pic")