mirror of
https://gitcode.com/JianFeeeee/homeagent-sdk.git
synced 2026-10-15 12:15:11 +00:00
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:
@ -19,6 +19,7 @@ type Plugin struct {
|
||||
sdk *sdk.PluginSDK
|
||||
client *http.Client
|
||||
defaultLoc string
|
||||
dataDir string
|
||||
}
|
||||
|
||||
func NewPluginFactory(name string, config map[string]interface{}) (sdk.Plugin, error) {
|
||||
@ -48,7 +49,11 @@ func (p *Plugin) Start(s *sdk.PluginSDK) error {
|
||||
if dataHome == "" {
|
||||
dataHome = "/tmp"
|
||||
}
|
||||
os.MkdirAll(filepath.Join(dataHome, ".homeagent", "weather"), 0755)
|
||||
p.dataDir = filepath.Join(dataHome, ".homeagent", "weather")
|
||||
os.MkdirAll(p.dataDir, 0755)
|
||||
|
||||
// 卸载(删除)时清理天气缓存目录;重载不触发
|
||||
s.RegisterOnRemoveHandler(p.cleanupData)
|
||||
|
||||
tp := p.name + "_"
|
||||
s.RegisterTool(tp+"current", sdk.ToolDef{
|
||||
@ -423,3 +428,10 @@ func (p *Plugin) handleSetLocation(args map[string]interface{}) (interface{}, er
|
||||
p.defaultLoc = loc
|
||||
return map[string]interface{}{"content": fmt.Sprintf("Default location set to: %s", loc)}, nil
|
||||
}
|
||||
|
||||
// cleanupData 卸载时清理天气缓存目录
|
||||
func (p *Plugin) cleanupData() {
|
||||
if p.dataDir != "" {
|
||||
os.RemoveAll(p.dataDir)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user