preset: hypr/ category prefix for hyprland actions

parent 33f3fe93
......@@ -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) {
cat := "hypr/" + locale.T("var")
for _, v := range prof.Hyprland.Vars {
if !v.Force {
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
}
}
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
}
}
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 {
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) {
cat := "hypr/" + locale.T("module")
for _, m := range prof.Hyprland.Modules {
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
}
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
}
......@@ -165,13 +167,13 @@ func processHyprModules(manager *hyprland.HyprlandManager, prof config.PresetPro
cmd := exec.Command("sh", "-c", m.IfExec)
output, err := cmd.Output()
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
}
}
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
}
......@@ -179,23 +181,23 @@ func processHyprModules(manager *hyprland.HyprlandManager, prof config.PresetPro
modulefile := manager.GetModuleFile(m.Name, m.User)
if _, err := os.Stat(modulefile); os.IsNotExist(err) {
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 {
_ = 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 {
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
}
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 {
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
return
}
cat := "hypr/" + locale.T("check")
if manager.Changed {
manager.Save()
}
......@@ -213,13 +217,13 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP
checkErrors, err := manager.Check("")
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
}
if len(checkErrors) == 0 {
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
}
......@@ -250,11 +254,11 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP
}
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
}
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)
......@@ -266,7 +270,7 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP
// Включаем модуль уведомления об ошибках
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
return
}
cat := "hypr/" + locale.T("layout")
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
}
sysLayouts, err := hyprland.HyprlandGetKeyboardLayouts()
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
}
......@@ -290,12 +296,12 @@ func processHyprLayoutSync(manager *hyprland.HyprlandManager, prof config.Preset
if hyprLayouts == "" {
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
}
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 {
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