example: 演示插件 onRemove 清理补齐(memo/rss/weather)

- memo: 卸载时删除 memos.json 数据文件
- rss: 卸载时清理 .homeagent/rss 订阅数据目录
- weather: 卸载时清理 .homeagent/weather 缓存目录
- 与 calendar(events.json)一致:仅删除触发、重载不触发;
  files(filesDir 为用户配置的访问根目录)、bili/qq(用户下载资产)、
  ocr(临时目录函数内自清理)按语义不加入删除回调
This commit is contained in:
root
2026-08-02 13:37:59 +08:00
parent fb07081929
commit aee63a4f98
3 changed files with 33 additions and 1 deletions

View File

@ -46,6 +46,9 @@ func (p *Plugin) Start(s *sdk.PluginSDK) error {
p.filePath = filepath.Join(fmt.Sprint(dataDirVal), "memos.json")
p.load()
// 卸载(删除)时清理备忘数据文件;重载不触发
s.RegisterOnRemoveHandler(p.cleanupData)
s.RegisterTool(p.tp+"create", sdk.ToolDef{
Name: p.tp + "create",
Description: "创建一条备忘条目。备忘内容应包含具体事项的完整描述。",
@ -272,3 +275,10 @@ func errorResult(msg string) map[string]interface{} {
func NewPluginFactory(name string, config map[string]interface{}) (sdk.Plugin, error) {
return &Plugin{name: name}, nil
}
// cleanupData 卸载时清理备忘数据文件
func (p *Plugin) cleanupData() {
if p.filePath != "" {
os.Remove(p.filePath)
}
}