feat(sdk): add RegisterStopHandler/RunStopHandlers and wire stop cleanup into registry lifecycle

- SDK PluginSDK gains RegisterStopHandler(fn func()) + RunStopHandlers()
  (LIFO, idempotent, cleared after running); synced to third_party copy
- Registry keeps per-plugin SDK refs (sdkRefs); StopAll/ReloadOne/
  DisablePlugin run handlers before calling Stop()
- timer built-in plugin demonstrates handler-based shutdown cleanup
- z_bridge (linux/windows templates) runs handlers before plugin.Stop()
This commit is contained in:
root
2026-08-02 10:23:40 +08:00
parent 94312d714a
commit 1013aa0aa9
6 changed files with 66 additions and 9 deletions

View File

@ -42,6 +42,8 @@ func (p *Plugin) Name() string { return p.name }
func (p *Plugin) Start(s *sdk.PluginSDK) error {
s.SetAutoRestart(true)
p.maxDur = 24 * time.Hour
// 停止清理(取消倒计时)交由 stop handler内核在调用 Stop() 之前执行。
s.RegisterStopHandler(func() { close(p.stopCh) })
s.Settings().RegisterDef(sdk.ConfigDef{
Key: "max_duration", Type: "string", DisplayName: "最大定时时长",
Description: "允许设置的最大定时时长,例如 24h, 7d, 1h默认 24h",
@ -118,7 +120,6 @@ func (p *Plugin) Start(s *sdk.PluginSDK) error {
}
func (p *Plugin) Stop() error {
close(p.stopCh)
p.wg.Wait()
return nil
}

View File

@ -258,9 +258,11 @@ code { font-family:monospace; font-size:12px; color:var(--pre-color) }
.msg { max-width:95% }
}
@media(max-width:768px) {
nav { padding:0 8px; gap:2px }
nav h1 { font-size:13px; margin-right:8px }
nav a { padding:8px 6px; font-size:11px }
nav { padding:0 6px; gap:2px; overflow-x:auto; scrollbar-width:none; -ms-overflow-style:none; flex-wrap:nowrap }
nav::-webkit-scrollbar { display:none }
nav h1 { font-size:0; margin-right:6px; color:var(--accent) }
nav a { padding:10px 8px; font-size:12px; white-space:nowrap; flex-shrink:0 }
nav > div { flex-shrink:0 }
.container { padding:12px }
.card { padding:12px }
.grid-2,.grid-3,.grid-4 { grid-template-columns:1fr }