preset/hyprland profile: use HyprlandManager

parent a959dad7
...@@ -106,10 +106,10 @@ func handleReleaseReplace(src, dest, sysVer string, opts opOptions) string { ...@@ -106,10 +106,10 @@ func handleReleaseReplace(src, dest, sysVer string, opts opOptions) string {
return fmt.Sprintf("Обновлён: %s (%s → %s)", dest, fileVer, sysVer) return fmt.Sprintf("Обновлён: %s (%s → %s)", dest, fileVer, sysVer)
} }
func processHyprVars(prof config.PresetProfile, opts opOptions, res *config.PresetResult) { func processHyprVars(manager *hyprland.HyprlandManager, prof config.PresetProfile, opts opOptions, res *config.PresetResult) {
for _, v := range prof.Hyprland.Vars { for _, v := range prof.Hyprland.Vars {
if !v.Force { if !v.Force {
if _, err := hyprland.HyprlandVarGet(v.Var); err == nil { if V := manager.GetVar(v.Var); V != "" {
res.HyprVars = append(res.HyprVars, res.HyprVars = append(res.HyprVars,
fmt.Sprintf("Уже существует: '%s' — пропущено", v.Var)) fmt.Sprintf("Уже существует: '%s' — пропущено", v.Var))
continue continue
...@@ -122,7 +122,7 @@ func processHyprVars(prof config.PresetProfile, opts opOptions, res *config.Pres ...@@ -122,7 +122,7 @@ func processHyprVars(prof config.PresetProfile, opts opOptions, res *config.Pres
continue continue
} }
if _, err := hyprland.HyprlandVarSet(v.Var, v.Value); err != nil { if _, err := manager.SetVar(v.Var, v.Value); err != nil {
res.HyprVars = append(res.HyprVars, res.HyprVars = append(res.HyprVars,
fmt.Sprintf("Ошибка установки %s: %v", v.Var, err)) fmt.Sprintf("Ошибка установки %s: %v", v.Var, err))
} else { } else {
...@@ -132,7 +132,7 @@ func processHyprVars(prof config.PresetProfile, opts opOptions, res *config.Pres ...@@ -132,7 +132,7 @@ func processHyprVars(prof config.PresetProfile, opts opOptions, res *config.Pres
} }
} }
func processHyprModules(prof config.PresetProfile, opts opOptions, res *config.PresetResult) { func processHyprModules(manager *hyprland.HyprlandManager, prof config.PresetProfile, opts opOptions, res *config.PresetResult) {
for _, m := range prof.Hyprland.Modules { for _, m := range prof.Hyprland.Modules {
if m.Module == "" { if m.Module == "" {
...@@ -174,7 +174,7 @@ func processHyprModules(prof config.PresetProfile, opts opOptions, res *config.P ...@@ -174,7 +174,7 @@ func processHyprModules(prof config.PresetProfile, opts opOptions, res *config.P
} }
if m.Init && m.User && m.Action == "enable" { if m.Init && m.User && m.Action == "enable" {
modulefile := hyprland.HyprlandGetModuleFile(m.Module, m.User) modulefile := manager.GetModuleFile(m.Module, m.User)
if _, err := os.Stat(modulefile); os.IsNotExist(err) { if _, err := os.Stat(modulefile); os.IsNotExist(err) {
if opts.DryRun { if opts.DryRun {
...@@ -203,7 +203,7 @@ func processHyprModules(prof config.PresetProfile, opts opOptions, res *config.P ...@@ -203,7 +203,7 @@ func processHyprModules(prof config.PresetProfile, opts opOptions, res *config.P
continue continue
} }
if _, err := hyprland.HyprlandSetModule( if _, err := manager.SetModule(
m.Action, m.Action,
m.Module, m.Module,
m.User, m.User,
...@@ -226,7 +226,7 @@ func processHyprModules(prof config.PresetProfile, opts opOptions, res *config.P ...@@ -226,7 +226,7 @@ func processHyprModules(prof config.PresetProfile, opts opOptions, res *config.P
} }
} }
func processHyprLayoutSync(prof config.PresetProfile, opts opOptions, res *config.PresetResult) { func processHyprLayoutSync(manager *hyprland.HyprlandManager, prof config.PresetProfile, opts opOptions, res *config.PresetResult) {
if !prof.Hyprland.Option.SyncSystemLayouts { if !prof.Hyprland.Option.SyncSystemLayouts {
return return
} }
...@@ -244,12 +244,7 @@ func processHyprLayoutSync(prof config.PresetProfile, opts opOptions, res *confi ...@@ -244,12 +244,7 @@ func processHyprLayoutSync(prof config.PresetProfile, opts opOptions, res *confi
return return
} }
hyprLayouts, err := hyprland.HyprlandVarGet("kb_layout") hyprLayouts := manager.GetVar("kb_layout")
if err != nil {
res.SyncSystemLayouts = append(res.SyncSystemLayouts,
"Не удалось получить раскладки Hyprland")
return
}
if hyprLayouts == "" { if hyprLayouts == "" {
hyprLayouts = "<empty>" hyprLayouts = "<empty>"
...@@ -261,7 +256,7 @@ func processHyprLayoutSync(prof config.PresetProfile, opts opOptions, res *confi ...@@ -261,7 +256,7 @@ func processHyprLayoutSync(prof config.PresetProfile, opts opOptions, res *confi
fmt.Sprintf("Раскладка Hyprland: %s", hyprLayouts)) fmt.Sprintf("Раскладка Hyprland: %s", hyprLayouts))
if hyprLayouts == "<empty>" { if hyprLayouts == "<empty>" {
if _, err := hyprland.HyprlandVarSet("kb_layout", sysLayouts); err != nil { if _, err := manager.SetVar("kb_layout", sysLayouts); err != nil {
res.SyncSystemLayouts = append(res.SyncSystemLayouts, res.SyncSystemLayouts = append(res.SyncSystemLayouts,
"Не удалось обновить kb_layout") "Не удалось обновить kb_layout")
return return
...@@ -305,9 +300,13 @@ func processProfile(prof config.PresetProfile, dryRun bool, res *config.PresetRe ...@@ -305,9 +300,13 @@ func processProfile(prof config.PresetProfile, dryRun bool, res *config.PresetRe
if config.Env.IsRoot { if config.Env.IsRoot {
processSystemGrub(prof, opts, res) processSystemGrub(prof, opts, res)
} }
processHyprVars(prof, opts, res) manager, err := hyprland.NewHyprlandManager()
processHyprModules(prof, opts, res) if err != nil {
processHyprLayoutSync(prof, opts, res) return
}
processHyprVars(manager, prof, opts, res)
processHyprModules(manager, prof, opts, res)
processHyprLayoutSync(manager, prof, opts, res)
} }
func createProfile(profileName string, prof config.PresetProfile, dryRun bool, res *config.PresetResult) { func createProfile(profileName string, prof config.PresetProfile, dryRun bool, res *config.PresetResult) {
......
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