preset: add action for hyprland/module

parent 0fc2d276
...@@ -43,6 +43,7 @@ type hyprVar struct { ...@@ -43,6 +43,7 @@ type hyprVar struct {
type hyprModule struct { type hyprModule struct {
Module string `yaml:"module"` Module string `yaml:"module"`
Action string `yaml:"action"`
User bool `yaml:"user,omitempty"` User bool `yaml:"user,omitempty"`
NewOnly bool `yaml:"new-only,omitempty"` NewOnly bool `yaml:"new-only,omitempty"`
IfExec string `yaml:"if-exec,omitempty"` IfExec string `yaml:"if-exec,omitempty"`
......
...@@ -2,6 +2,7 @@ package preset ...@@ -2,6 +2,7 @@ package preset
import ( import (
"bytes" "bytes"
"slices"
"ximperconf/config" "ximperconf/config"
"ximperconf/hyprland" "ximperconf/hyprland"
"ximperconf/system" "ximperconf/system"
...@@ -17,6 +18,10 @@ import ( ...@@ -17,6 +18,10 @@ import (
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
) )
var (
validActions = []string{"enable", "disable", "remove"}
)
func processCopies(prof config.PresetProfile, opts opOptions, res *config.PresetResult) { func processCopies(prof config.PresetProfile, opts opOptions, res *config.PresetResult) {
for _, c := range prof.Copy { for _, c := range prof.Copy {
src := expandPath(c.Src, "") src := expandPath(c.Src, "")
...@@ -135,6 +140,13 @@ func processHyprModules(prof config.PresetProfile, opts opOptions, res *config.P ...@@ -135,6 +140,13 @@ func processHyprModules(prof config.PresetProfile, opts opOptions, res *config.P
continue continue
} }
if !slices.Contains(validActions, m.Action) {
res.HyprModules = append(res.HyprModules,
fmt.Sprintf("Модуль '%s' пропущен: неподдерживаемый action",
m.Module))
continue
}
// if-exec // if-exec
if m.IfExec != "" { if m.IfExec != "" {
cmd := exec.Command("sh", "-c", m.IfExec) cmd := exec.Command("sh", "-c", m.IfExec)
...@@ -161,7 +173,7 @@ func processHyprModules(prof config.PresetProfile, opts opOptions, res *config.P ...@@ -161,7 +173,7 @@ func processHyprModules(prof config.PresetProfile, opts opOptions, res *config.P
continue continue
} }
if m.Init && m.User { if m.Init && m.User && m.Action == "enable" {
modulefile := hyprland.HyprlandGetModuleFile(m.Module, m.User) modulefile := hyprland.HyprlandGetModuleFile(m.Module, m.User)
if _, err := os.Stat(modulefile); os.IsNotExist(err) { if _, err := os.Stat(modulefile); os.IsNotExist(err) {
...@@ -178,22 +190,38 @@ func processHyprModules(prof config.PresetProfile, opts opOptions, res *config.P ...@@ -178,22 +190,38 @@ func processHyprModules(prof config.PresetProfile, opts opOptions, res *config.P
// dry-run // dry-run
if opts.DryRun { if opts.DryRun {
res.HyprModules = append(res.HyprModules, var dryrunmessage string
fmt.Sprintf("[Dry-run] Подключён модуль: %s", m.Module)) switch m.Action {
case "enable":
dryrunmessage = fmt.Sprintf("[Dry-run] Подключён модуль: %s", m.Module)
case "disable":
dryrunmessage = fmt.Sprintf("[Dry-run] Отключён модуль: %s", m.Module)
case "remove":
dryrunmessage = fmt.Sprintf("[Dry-run] Удалён модуль: %s", m.Module)
}
res.HyprModules = append(res.HyprModules, dryrunmessage)
continue continue
} }
if _, err := hyprland.HyprlandSetModule( if _, err := hyprland.HyprlandSetModule(
"enable", m.Action,
m.Module, m.Module,
m.User, m.User,
m.NewOnly, m.NewOnly,
); err != nil { ); err != nil {
res.HyprModules = append(res.HyprModules, res.HyprModules = append(res.HyprModules,
fmt.Sprintf("Ошибка подключения модуля %s: %v", m.Module, err)) fmt.Sprintf("Ошибка (%s): %v", m.Module, err))
} else { } else {
res.HyprModules = append(res.HyprModules, var message string
fmt.Sprintf("Подключён модуль: %s", m.Module)) switch m.Action {
case "enable":
message = fmt.Sprintf("Подключён модуль: %s", m.Module)
case "disable":
message = fmt.Sprintf("Отключён модуль: %s", m.Module)
case "remove":
message = fmt.Sprintf("Удалён модуль: %s", m.Module)
}
res.HyprModules = append(res.HyprModules, message)
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment