preset: auto-remove missing and deps-broken modules

parent e876aae1
......@@ -258,7 +258,7 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
name = d.info.Meta.Group + "/" + name
}
if !d.info.DepsInstalled {
missing := missingDeps(d.info.Meta)
missing := MissingDeps(d.info.Meta)
if len(missing) > 0 {
parts = append(parts, fmt.Sprintf("(requires: %s)", strings.Join(missing, ", ")))
}
......
......@@ -235,7 +235,7 @@ func checkDeps(meta *ModuleMeta) bool {
return true
}
func missingDeps(meta *ModuleMeta) []string {
func MissingDeps(meta *ModuleMeta) []string {
if meta == nil {
return nil
}
......@@ -528,7 +528,7 @@ func (m *HyprlandManager) SetModule(action, module string, onlyNew bool) (string
// зависимости не установлены
if !info.DepsInstalled {
return "", fmt.Errorf(locale.T("missing module dependencies: %s"),
strings.Join(missingDeps(info.Meta), ", "))
strings.Join(MissingDeps(info.Meta), ", "))
}
// нет файла
......
......@@ -207,6 +207,42 @@ func processHyprModules(manager *hyprland.HyprlandManager, prof config.PresetPro
}
}
func processCleanupModules(manager *hyprland.HyprlandManager, opts opOptions, res *Result) {
cat := "hypr/" + locale.T("cleanup")
for _, info := range manager.GetModulesList("all") {
needRemove := false
var reason string
switch {
case info.Status.IsEqual(config.ModuleStatus.Missing):
needRemove = true
reason = locale.T("file not found")
case !info.DepsInstalled && info.LineNumber > 0:
needRemove = true
reason = fmt.Sprintf(locale.T("missing dependencies: %s"),
strings.Join(hyprland.MissingDeps(info.Meta), ", "))
}
if !needRemove {
continue
}
msg := fmt.Sprintf(locale.T("Module '%s' removed (%s)"), info.Name, reason)
if opts.DryRun {
res.Add(cat, msg, config.OpStatus.DryRun)
continue
}
if _, err := manager.SetModule("remove", info.Name, false); err != nil {
res.Add(cat, fmt.Sprintf(locale.T("Failed to remove '%s': %v"), info.Name, err), config.OpStatus.Error)
continue
}
res.Add(cat, msg, config.OpStatus.Done)
}
}
func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetProfile, opts opOptions, res *Result) {
if !prof.Hyprland.Check || opts.DryRun {
return
......@@ -324,6 +360,7 @@ func processProfile(prof config.PresetProfile, opts opOptions, res *Result, mana
if manager != nil {
processHyprVars(manager, prof, opts, res)
processHyprModules(manager, prof, opts, res)
processCleanupModules(manager, opts, res)
processHyprLayoutSync(manager, prof, opts, res)
processVerifyModules(manager, prof, opts, res)
}
......
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