chore: 初始化仓库(零源工具箱 0.1.0 基线)
- 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
This commit is contained in:
commit
0a1c1e82ea
188 files changed
+19926
No files matched your search
@@ -0,0 +1,65 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
pwin "zerorigin/internal/platform/windows"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Register("launch_application", func() Action { return &launchAction{} })
|
||||
}
|
||||
|
||||
// launchAction 启动指定程序。
|
||||
// 安全约束(架构文档 §9.2):路径必须为绝对路径且文件存在;
|
||||
// 不使用 shell 拼接;结果与错误均记录,不记录敏感参数。
|
||||
type launchAction struct{}
|
||||
|
||||
func (a *launchAction) ID() string { return "launch_application" }
|
||||
func (a *launchAction) Name() string { return "启动程序" }
|
||||
|
||||
func (a *launchAction) Schema() ActionSchema {
|
||||
return ActionSchema{Params: []ParamSpec{
|
||||
{Name: "path", Type: "string", Required: true},
|
||||
{Name: "args", Type: "string", Required: false, Default: ""},
|
||||
}}
|
||||
}
|
||||
|
||||
func (a *launchAction) Validate(params map[string]any) error {
|
||||
path := GetString(params, "path")
|
||||
if path == "" {
|
||||
return fmt.Errorf("launch_application: missing param \"path\"")
|
||||
}
|
||||
if !filepathIsAbs(path) {
|
||||
return fmt.Errorf("launch_application: path must be absolute: %q", path)
|
||||
}
|
||||
fi, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("launch_application: %q: %v", path, err)
|
||||
}
|
||||
if fi.IsDir() {
|
||||
return fmt.Errorf("launch_application: %q is a directory, want executable", path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *launchAction) Execute(ctx context.Context, params map[string]any) error {
|
||||
path := GetString(params, "path")
|
||||
args := GetString(params, "args")
|
||||
return pwin.OpenPathWithArgs(path, args)
|
||||
}
|
||||
|
||||
// filepathIsAbs 判断路径是否绝对路径(避免引入 filepath 包仅为此一处)。
|
||||
func filepathIsAbs(p string) bool {
|
||||
if len(p) >= 2 {
|
||||
if p[1] == ':' && (p[0] >= 'A' && p[0] <= 'Z' || p[0] >= 'a' && p[0] <= 'z') {
|
||||
return true // C:\... / c:\...
|
||||
}
|
||||
if p[0] == '\\' && p[1] == '\\' {
|
||||
return true // \\server\share
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user