preset: hypr/ category prefix for hyprland actions

parent 33f3fe93
...@@ -128,36 +128,38 @@ func processSystemGrub(prof config.PresetProfile, opts opOptions, res *Result) { ...@@ -128,36 +128,38 @@ func processSystemGrub(prof config.PresetProfile, opts opOptions, res *Result) {
} }
func processHyprVars(manager *hyprland.HyprlandManager, prof config.PresetProfile, opts opOptions, res *Result) { func processHyprVars(manager *hyprland.HyprlandManager, prof config.PresetProfile, opts opOptions, res *Result) {
cat := "hypr/" + locale.T("var")
for _, v := range prof.Hyprland.Vars { for _, v := range prof.Hyprland.Vars {
if !v.Force { if !v.Force {
if existing := manager.GetVar(v.Name); existing != "" { if existing := manager.GetVar(v.Name); existing != "" {
res.Add(locale.T("var"), fmt.Sprintf(locale.T("Already exists: %s"), v.Name), config.OpStatus.Skipped) res.Add(cat, fmt.Sprintf(locale.T("Already exists: %s"), v.Name), config.OpStatus.Skipped)
continue continue
} }
} }
if opts.DryRun { if opts.DryRun {
res.Add(locale.T("var"), fmt.Sprintf("%s = %s", v.Name, v.Value), config.OpStatus.DryRun) res.Add(cat, fmt.Sprintf("%s = %s", v.Name, v.Value), config.OpStatus.DryRun)
continue continue
} }
if _, err := manager.SetVar(v.Name, v.Value); err != nil { if _, err := manager.SetVar(v.Name, v.Value); err != nil {
res.Add(locale.T("var"), fmt.Sprintf(locale.T("Error setting %s: %v"), v.Name, err), config.OpStatus.Error) res.Add(cat, fmt.Sprintf(locale.T("Error setting %s: %v"), v.Name, err), config.OpStatus.Error)
} else { } else {
res.Add(locale.T("var"), fmt.Sprintf("%s = %s", v.Name, v.Value), config.OpStatus.Done) res.Add(cat, fmt.Sprintf("%s = %s", v.Name, v.Value), config.OpStatus.Done)
} }
} }
} }
func processHyprModules(manager *hyprland.HyprlandManager, prof config.PresetProfile, opts opOptions, res *Result) { func processHyprModules(manager *hyprland.HyprlandManager, prof config.PresetProfile, opts opOptions, res *Result) {
cat := "hypr/" + locale.T("module")
for _, m := range prof.Hyprland.Modules { for _, m := range prof.Hyprland.Modules {
if m.Name == "" { if m.Name == "" {
res.Add(locale.T("module"), locale.T("Skipped module without name"), config.OpStatus.Skipped) res.Add(cat, locale.T("Skipped module without name"), config.OpStatus.Skipped)
continue continue
} }
if !slices.Contains(validActions, m.Action) { if !slices.Contains(validActions, m.Action) {
res.Add(locale.T("module"), fmt.Sprintf(locale.T("Module '%s': unsupported action"), m.Name), config.OpStatus.Skipped) res.Add(cat, fmt.Sprintf(locale.T("Module '%s': unsupported action"), m.Name), config.OpStatus.Skipped)
continue continue
} }
...@@ -165,13 +167,13 @@ func processHyprModules(manager *hyprland.HyprlandManager, prof config.PresetPro ...@@ -165,13 +167,13 @@ func processHyprModules(manager *hyprland.HyprlandManager, prof config.PresetPro
cmd := exec.Command("sh", "-c", m.IfExec) cmd := exec.Command("sh", "-c", m.IfExec)
output, err := cmd.Output() output, err := cmd.Output()
if err != nil || len(bytes.TrimSpace(output)) == 0 { if err != nil || len(bytes.TrimSpace(output)) == 0 {
res.Add(locale.T("module"), fmt.Sprintf(locale.T("Module '%s': condition not met"), m.Name), config.OpStatus.Skipped) res.Add(cat, fmt.Sprintf(locale.T("Module '%s': condition not met"), m.Name), config.OpStatus.Skipped)
continue continue
} }
} }
if m.IfBinary != "" && !commandExists(m.IfBinary) { if m.IfBinary != "" && !commandExists(m.IfBinary) {
res.Add(locale.T("module"), fmt.Sprintf(locale.T("Module '%s': binary '%s' not found"), m.Name, m.IfBinary), config.OpStatus.Skipped) res.Add(cat, fmt.Sprintf(locale.T("Module '%s': binary '%s' not found"), m.Name, m.IfBinary), config.OpStatus.Skipped)
continue continue
} }
...@@ -179,23 +181,23 @@ func processHyprModules(manager *hyprland.HyprlandManager, prof config.PresetPro ...@@ -179,23 +181,23 @@ func processHyprModules(manager *hyprland.HyprlandManager, prof config.PresetPro
modulefile := manager.GetModuleFile(m.Name, m.User) modulefile := manager.GetModuleFile(m.Name, m.User)
if _, err := os.Stat(modulefile); os.IsNotExist(err) { if _, err := os.Stat(modulefile); os.IsNotExist(err) {
if opts.DryRun { if opts.DryRun {
res.Add(locale.T("module"), fmt.Sprintf(locale.T("Created empty module: %s"), m.Name), config.OpStatus.DryRun) res.Add(cat, fmt.Sprintf(locale.T("Created empty module: %s"), m.Name), config.OpStatus.DryRun)
} else { } else {
_ = os.WriteFile(modulefile, []byte(""), 0o644) _ = os.WriteFile(modulefile, []byte(""), 0o644)
res.Add(locale.T("module"), fmt.Sprintf(locale.T("Created empty module: %s"), m.Name), config.OpStatus.Done) res.Add(cat, fmt.Sprintf(locale.T("Created empty module: %s"), m.Name), config.OpStatus.Done)
} }
} }
} }
if opts.DryRun { if opts.DryRun {
res.Add(locale.T("module"), fmt.Sprintf("%s: %s", m.Name, m.Action), config.OpStatus.DryRun) res.Add(cat, fmt.Sprintf("%s: %s", m.Name, m.Action), config.OpStatus.DryRun)
continue continue
} }
if _, err := manager.SetModule(m.Action, m.Name, m.User, m.NewOnly); err != nil { if _, err := manager.SetModule(m.Action, m.Name, m.User, m.NewOnly); err != nil {
res.Add(locale.T("module"), fmt.Sprintf(locale.T("Error (%s): %v"), m.Name, err), config.OpStatus.Error) res.Add(cat, fmt.Sprintf(locale.T("Error (%s): %v"), m.Name, err), config.OpStatus.Error)
} else { } else {
res.Add(locale.T("module"), fmt.Sprintf("%s: %s", m.Name, m.Action), config.OpStatus.Done) res.Add(cat, fmt.Sprintf("%s: %s", m.Name, m.Action), config.OpStatus.Done)
} }
} }
} }
...@@ -205,6 +207,8 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP ...@@ -205,6 +207,8 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP
return return
} }
cat := "hypr/" + locale.T("check")
if manager.Changed { if manager.Changed {
manager.Save() manager.Save()
} }
...@@ -213,13 +217,13 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP ...@@ -213,13 +217,13 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP
checkErrors, err := manager.Check("") checkErrors, err := manager.Check("")
if err != nil { if err != nil {
res.Add(locale.T("check"), fmt.Sprintf(locale.T("Check failed: %v"), err), config.OpStatus.Error) res.Add(cat, fmt.Sprintf(locale.T("Check failed: %v"), err), config.OpStatus.Error)
return return
} }
if len(checkErrors) == 0 { if len(checkErrors) == 0 {
os.Remove(logPath) // Удаляем лог от предыдущего запуска os.Remove(logPath) // Удаляем лог от предыдущего запуска
res.Add(locale.T("check"), locale.T("No errors found"), config.OpStatus.Done) res.Add(cat, locale.T("No errors found"), config.OpStatus.Done)
return return
} }
...@@ -250,11 +254,11 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP ...@@ -250,11 +254,11 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP
} }
if _, err := manager.SetModule("disable", name, isUser, false); err != nil { if _, err := manager.SetModule("disable", name, isUser, false); err != nil {
res.Add(locale.T("check"), fmt.Sprintf(locale.T("Failed to disable '%s': %v"), name, err), config.OpStatus.Error) res.Add(cat, fmt.Sprintf(locale.T("Failed to disable '%s': %v"), name, err), config.OpStatus.Error)
continue continue
} }
disabled[key] = true disabled[key] = true
res.Add(locale.T("check"), fmt.Sprintf(locale.T("Module '%s' disabled (errors)"), name), config.OpStatus.Error) res.Add(cat, fmt.Sprintf(locale.T("Module '%s' disabled (errors)"), name), config.OpStatus.Error)
} }
os.MkdirAll(filepath.Dir(logPath), 0o755) os.MkdirAll(filepath.Dir(logPath), 0o755)
...@@ -266,7 +270,7 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP ...@@ -266,7 +270,7 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP
// Включаем модуль уведомления об ошибках // Включаем модуль уведомления об ошибках
if _, err := manager.SetModule("enable", "ximperconf-errors", false, false); err != nil { if _, err := manager.SetModule("enable", "ximperconf-errors", false, false); err != nil {
res.Add(locale.T("check"), fmt.Sprintf(locale.T("Failed to enable notification module: %v"), err), config.OpStatus.Error) res.Add(cat, fmt.Sprintf(locale.T("Failed to enable notification module: %v"), err), config.OpStatus.Error)
} }
} }
...@@ -275,14 +279,16 @@ func processHyprLayoutSync(manager *hyprland.HyprlandManager, prof config.Preset ...@@ -275,14 +279,16 @@ func processHyprLayoutSync(manager *hyprland.HyprlandManager, prof config.Preset
return return
} }
cat := "hypr/" + locale.T("layout")
if opts.DryRun { if opts.DryRun {
res.Add(locale.T("layout"), locale.T("Sync Hyprland layouts"), config.OpStatus.DryRun) res.Add(cat, locale.T("Sync Hyprland layouts"), config.OpStatus.DryRun)
return return
} }
sysLayouts, err := hyprland.HyprlandGetKeyboardLayouts() sysLayouts, err := hyprland.HyprlandGetKeyboardLayouts()
if err != nil { if err != nil {
res.Add(locale.T("layout"), locale.T("Failed to get system layouts"), config.OpStatus.Error) res.Add(cat, locale.T("Failed to get system layouts"), config.OpStatus.Error)
return return
} }
...@@ -290,12 +296,12 @@ func processHyprLayoutSync(manager *hyprland.HyprlandManager, prof config.Preset ...@@ -290,12 +296,12 @@ func processHyprLayoutSync(manager *hyprland.HyprlandManager, prof config.Preset
if hyprLayouts == "" { if hyprLayouts == "" {
if _, err := manager.SetVar("kb_layout", sysLayouts); err != nil { if _, err := manager.SetVar("kb_layout", sysLayouts); err != nil {
res.Add(locale.T("layout"), locale.T("Failed to update kb_layout"), config.OpStatus.Error) res.Add(cat, locale.T("Failed to update kb_layout"), config.OpStatus.Error)
return return
} }
res.Add(locale.T("layout"), fmt.Sprintf(locale.T("Layout updated: %s"), sysLayouts), config.OpStatus.Done) res.Add(cat, fmt.Sprintf(locale.T("Layout updated: %s"), sysLayouts), config.OpStatus.Done)
} else { } else {
res.Add(locale.T("layout"), fmt.Sprintf(locale.T("Layout already set: %s"), hyprLayouts), config.OpStatus.Skipped) res.Add(cat, fmt.Sprintf(locale.T("Layout already set: %s"), hyprLayouts), config.OpStatus.Skipped)
} }
} }
......
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