reference_core_modules.md
2.59 KB
name: core/ 业务核心模块结构
description: image_generator.py 5082 行拆解后的业务核心目录布局(task #20 完成)
type: reference
originSessionId: 21abab40-0d6c-449a-ae72-9ca03205f077
背景:image_generator.py 原本 5082 行混了 12 个类(数据库/历史/Worker/词库/UI), QML 迁移期顺手拆出业务核心,UI 类留待 task #19 删除。
目录布局(截至 2026-05-10):
core/
├── __init__.py
├── paths.py get_app_data_path + save_png_with_validation +
_migrate_data_from_app_bundle
├── database.py DatabaseManager + hash_password
(加了 authenticate_with_hash 走"记住密码"路径,跳过 hash)
├── history.py HistoryItem + HistoryListModel + HistoryManager
HistoryListModel.roleNames 已扩展给 QML:display/decoration/toolTip/timestamp
├── generation.py MODEL_BY_MODE / MODEL_PRO / FLASH_ONLY_ASPECT_RATIOS + ImageGenerationWorker
└── jewelry.py DEFAULT_JEWELRY_LIBRARY (8 类) + JewelryLibraryManager + PromptAssembler
core/runtime.py (新加,2026-05-09 抽出,2026-05-10 加日志兜底)
enable_crash_diagnostics(含 macOS DiagnosticReports 提示写入 crash_log.txt)
init_logging(用 TieredFsyncHandler 替代 RotatingFileHandler)
TieredFsyncHandler — WARNING+ 同步 fsync / INFO buffered
start_periodic_fsync — 1s 周期 daemon 线程兜底(INFO 最坏丢 1s)
log_system_info / cleanup_clipboard_tempfiles
flush_logs(升级为对所有 handlers 走 fsync)
get_crash_log_path
image_generator.py.txt(2026-05-10 重命名):
- git mv .py → .py.txt 保留全部历史;Python 不加载,PyInstaller 不扫
- 内容是老 QWidget UI 类(LoginDialog / ImageGeneratorWindow / DraggableThumbnail / DragDropScrollArea / StyleDesignerTab + main())和顶部已搬走的工具函数副本
- 用户要求暂不删,留作扒老逻辑参考;task #19 真正"删掉"动作要等用户确认 QML 版稳定后
外部消费:
- task_queue.py / temp_clean.py:
from core.generation import ImageGenerationWorker - bridges/*:
from core.history import HistoryManager / HistoryListModel,from core.database import DatabaseManager,from core.jewelry import PromptAssembler等 - image_generator.py 顶部
from core.* import *是 re-export,让 LoginDialog / ImageGeneratorWindow 内部代码无感知(仍按原名字调用,任务 #19 一起删)