feat(v1.5.1): 配置守护系统和变更通知队列机制 #80
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
概述
本 PR 实现了 v1.5.1 版本的配置守护系统,包括配置变更监听、快照管理、变更历史和通知队列机制。
🎯 核心功能
配置守护系统(Config Guard)
动机:
核心特性:
技术实现:
后端(Rust)
数据模块 (
src-tauri/src/data/)changelogs.rs:配置变更日志管理(ChangeLogStore,支持分页、过期标记)snapshots.rs:配置快照管理(SnapshotStore,保存工具配置文件快照)配置监听 (
src-tauri/src/services/config/watcher.rs)compute_diff()递归比较 JSON 对象matches_pattern()支持通配符(如model_providers.*.base_url)is_sensitive_change()判断是否包含敏感字段filter_blacklisted()过滤自动修改字段Tauri 命令 (
src-tauri/src/commands/config_commands.rs)block_external_change:阻止外部变更,恢复快照到原生配置文件allow_external_change:允许外部变更,更新快照为当前文件内容get_watch_config/update_watch_config:监听配置管理update_sensitive_fields/update_blacklist:字段配置管理get_change_logs_page/clear_change_logs:变更历史管理启动流程 (
src-tauri/src/setup/initialization.rs)initialize_snapshots():启动时初始化所有工具的配置快照mark_expired_change_logs():标记未处理的变更日志为已过期start_watcher():启动文件监听服务前端(TypeScript + React)
Hook (
src/hooks/useConfigWatch.ts)useRef存储待处理变更,避免闭包陷阱queueLength给 UI 显示对话框组件
ConfigChangeDialog.tsx:显示变更详情,提供 Block/Allow 操作ChangeLogDialog.tsx:分页查看变更历史(10 条/页)FieldManagementDialog.tsx:管理敏感字段和黑名单配置设置页面 (
src/pages/SettingsPage/components/ConfigGuardTab.tsx)全局集成 (
src/App.tsx)useConfigWatchhook,自动弹出配置变更对话框📊 变更统计
主要文件
后端新增:
src-tauri/src/data/changelogs.rs(155 行)src-tauri/src/data/snapshots.rs(132 行)src-tauri/src/commands/config_commands.rs(+316 行命令函数)后端重构:
src-tauri/src/services/config/watcher.rs(~650 行,增强差异分析)src-tauri/src/models/config.rs(+140 行,ConfigWatchConfig 类型)src-tauri/src/setup/initialization.rs(+34 行,初始化逻辑)前端新增:
src/hooks/useConfigWatch.ts(109 行)src/components/dialogs/ConfigChangeDialog.tsx(253 行)src/components/dialogs/ChangeLogDialog.tsx(273 行)src/components/dialogs/FieldManagementDialog.tsx(319 行)src/lib/tauri-commands/config-watch.ts(103 行)src/types/config-watch.ts(126 行)src/pages/SettingsPage/components/ConfigGuardTab.tsx(255 行)src/pages/AboutPage/index.tsx(99 行)删除文件:
src-tauri/src/commands/watcher_commands.rs(125 行,功能整合到 config_commands.rs)src/pages/SettingsPage/components/AboutTab.tsx(89 行,移到独立页面)src/pages/SettingsPage/components/ConfigManagementTab.tsx(340 行,废弃旧实现)✅ 测试情况
后端测试
前端测试
手动验证
🔑 核心实现
1. 配置变更队列机制
2. 差异分析引擎
3. 快照管理
已缓解
配置文件操作
队列机制
isShowingRef和queueRef配合,避免闭包陷阱文件监听性能
📦 依赖变更
无新增依赖
🔗 相关 Commit
bffc26d- feat(config-watch): 实现配置守护系统和变更通知队列机制31d3a8f- fix(settings): 添加更新管理 Tab 并修复 TypeScript 类型错误📝 检查清单
npm run check且全部通过CLAUDE.md项目记忆审核建议:
测试建议: