Files
zerorigin-toolbox/internal/action/launch.go
T
zerorigin 0b8b9b0775 迁移到 mygo 单进程架构并接入签名自更新
- 单进程:托盘常驻 + 原生设置窗口(internal/settings),移除 Wails 前端与 IPC
- 触发器(鼠标角落 / 边缘滚轮 / 热键)+ 规则引擎 + 动作注册表
- 调节提示条:截屏 + glass.Blur 三层毛玻璃、背景跟随屏幕变化、悬停光感与拖动
- 音量 Core Audio COM、亮度 DDC/CI(gamma 兜底)、多显示器求平均
- 配置热重载 + 版本迁移 v1→v5、便携模式、崩溃取证三件套
- updater/native 插件 + 托盘「检查更新…」,watchdog 识别更新重启
- 自建 Gitea 发布:scripts/publish-gitea.ps1(updates.url 指向 latest Release)
2026-11-16 10:31:44 +08:00

68 lines
2.0 KiB
Go

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", Label: "程序路径", Type: "string", Required: true,
Help: `Windows 绝对路径,例如 C:\Windows\notepad.exe`},
{Name: "args", Label: "启动参数", Type: "string", Required: false, Default: "",
Help: "传给程序的命令行参数(可选)"},
}}
}
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
}