package trigger // ParamSchema 描述触发器参数(供设置界面渲染表单)。 type ParamSchema struct { Name string Label string // 中文标签(设置界面显示) Type string // "string" | "int" | "select" Required bool Default any Options []string // Type=="select" 时的可选值 Labels []string // 与 Options 一一对应的中文显示名(nil 表示直接显示值) Help string // 帮助文本 } // IDs 返回全部触发器类型(固定顺序,供设置界面下拉)。 func IDs() []string { return []string{"mouse_corner", "mouse_edge_wheel", "hotkey"} } // DisplayName 返回触发器的中文显示名;未知类型原样返回。 func DisplayName(id string) string { switch id { case "mouse_corner": return "鼠标进入屏幕角落" case "mouse_edge_wheel": return "屏幕边缘滚轮" case "hotkey": return "全局快捷键" } return id } // Schema 返回触发器的参数契约;未知类型返回 nil。 func Schema(id string) []ParamSchema { switch id { case "mouse_corner": return []ParamSchema{ {Name: "corner", Label: "屏幕角落", Type: "select", Required: true, Default: "bottom_left", Options: []string{"top_left", "top_right", "bottom_left", "bottom_right"}, Labels: []string{"左上角", "右上角", "左下角", "右下角"}}, {Name: "screen", Label: "显示器", Type: "select", Required: false, Default: "all", Options: []string{"all", "primary"}, Labels: []string{"所有显示器", "仅主显示器"}, Help: "光标进入指定显示器的角落时触发"}, {Name: "threshold_px", Label: "触发阈值(像素)", Type: "int", Required: false, Default: 32, Help: "光标进入角落该像素范围内才算命中(默认 32)"}, } case "mouse_edge_wheel": return []ParamSchema{ {Name: "edge", Label: "屏幕边缘", Type: "select", Required: false, Default: "top", Options: []string{"top", "bottom", "left", "right"}, Labels: []string{"上边缘", "下边缘", "左边缘", "右边缘"}}, {Name: "threshold_px", Label: "触发阈值(像素)", Type: "int", Required: false, Default: 32, Help: "光标位于边缘该像素范围内才响应滚轮(默认 32)"}, {Name: "direction", Label: "滚轮方向过滤", Type: "select", Required: false, Default: "", Options: []string{"", "up", "down"}, Labels: []string{"任意方向", "向上", "向下"}, Help: "任意方向:上下都触发;向上/向下:仅该方向触发(作为事件匹配条件)"}, } case "hotkey": return []ParamSchema{ {Name: "hotkey", Label: "快捷键", Type: "string", Required: true, Default: "ctrl+alt+d", Help: "格式:修饰键(ctrl/alt/shift/win)+单个字母或数字,例如 ctrl+alt+d"}, } } return nil } // DefaultParams 返回参数默认值(设置界面新建规则/切换类型时使用)。 func DefaultParams(id string) map[string]any { params := map[string]any{} for _, p := range Schema(id) { if p.Default != nil { params[p.Name] = p.Default } } return params }