fix(prompt): clear prompt file when all prompts are disabled

When disabling a prompt, check if any other prompts remain enabled.
If all prompts are disabled, clear the prompt file to ensure UI state
matches the actual configuration that Claude Code reads.
This commit is contained in:
Jason
2026-01-23 22:43:07 +08:00
parent a6ad896db0
commit adb868d0cf

View File

@@ -36,10 +36,22 @@ impl PromptService {
state.db.save_prompt(app.as_str(), &prompt)?;
// 如果是已启用的提示词,同步更新到对应的文件
if is_enabled {
// 启用提示词:写入内容到文件
let target_path = prompt_file_path(&app)?;
write_text_file(&target_path, &prompt.content)?;
} else {
// 禁用提示词:检查是否还有其他已启用的提示词
let prompts = state.db.get_prompts(app.as_str())?;
let any_enabled = prompts.values().any(|p| p.enabled);
if !any_enabled {
// 所有提示词都已禁用,清空文件
let target_path = prompt_file_path(&app)?;
if target_path.exists() {
write_text_file(&target_path, "")?;
}
}
}
Ok(())