- Go 主进程 cmd/zerorigin(托盘常驻 + 触发器/规则/动作引擎) - Wails v3 设置进程 cmd/settings(独立 module) - 监督进程 cmd/watchdog(-supervise 异常重启) - 构建脚本 build.bat / NSIS 安装包 deploy/、便携版 portable/ - 架构与 MVP 计划文档 docs/、阶段 0-4 验收记录 deploy/acceptance-0-4.md
43 lines
920 B
Go
43 lines
920 B
Go
package action
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func init() {
|
|
Register("delay", func() Action { return &delayAction{} })
|
|
}
|
|
|
|
// delayAction 延迟指定毫秒数(响应 context 取消)。
|
|
type delayAction struct{}
|
|
|
|
func (a *delayAction) ID() string { return "delay" }
|
|
func (a *delayAction) Name() string { return "延迟" }
|
|
|
|
func (a *delayAction) Schema() ActionSchema {
|
|
return ActionSchema{Params: []ParamSpec{
|
|
{Name: "ms", Type: "int", Required: true},
|
|
}}
|
|
}
|
|
|
|
func (a *delayAction) Validate(params map[string]any) error {
|
|
if ms := GetInt(params, "ms"); ms < 0 {
|
|
return fmt.Errorf("delay: ms must be >= 0")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (a *delayAction) Execute(ctx context.Context, params map[string]any) error {
|
|
ms := GetInt(params, "ms")
|
|
timer := time.NewTimer(time.Duration(ms) * time.Millisecond)
|
|
defer timer.Stop()
|
|
select {
|
|
case <-ctx.Done():
|
|
return ctx.Err()
|
|
case <-timer.C:
|
|
return nil
|
|
}
|
|
}
|