hyprland/module: unify user and system module namespace

parent 614ff808
...@@ -59,13 +59,12 @@ func HyprlandCheckCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -59,13 +59,12 @@ func HyprlandCheckCommand(ctx context.Context, cmd *cli.Command) error {
} }
func HyprlandModuleStatusCommand(ctx context.Context, cmd *cli.Command) error { func HyprlandModuleStatusCommand(ctx context.Context, cmd *cli.Command) error {
manager, err := GetHyprlandManager(ctx) manager, err := GetHyprlandManager(ctx)
if err != nil { if err != nil {
return err return err
} }
info := manager.GetModuleInfo(cmd.Args().Get(0), cmd.Bool("user")) info := manager.GetModuleInfo(cmd.Args().Get(0))
if !info.Available { if !info.Available {
return errors.New(locale.T("invalid module name")) return errors.New(locale.T("invalid module name"))
} }
...@@ -75,7 +74,6 @@ func HyprlandModuleStatusCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -75,7 +74,6 @@ func HyprlandModuleStatusCommand(ctx context.Context, cmd *cli.Command) error {
func HyprlandModuleCheckCommand(ctx context.Context, cmd *cli.Command) error { func HyprlandModuleCheckCommand(ctx context.Context, cmd *cli.Command) error {
module := cmd.Args().Get(0) module := cmd.Args().Get(0)
user := cmd.Bool("user")
if module == "" { if module == "" {
return errors.New(locale.T("specify module name")) return errors.New(locale.T("specify module name"))
...@@ -86,14 +84,13 @@ func HyprlandModuleCheckCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -86,14 +84,13 @@ func HyprlandModuleCheckCommand(ctx context.Context, cmd *cli.Command) error {
return err return err
} }
moduleinfo := manager.GetModuleInfo(module, user) moduleinfo := manager.GetModuleInfo(module)
if !moduleinfo.Available { if !moduleinfo.Available {
return errors.New(locale.T("invalid module name")) return errors.New(locale.T("invalid module name"))
} }
result, err := manager.CheckModule(module, user) result, err := manager.CheckModule(module)
if err != nil { if err != nil {
return err return err
} }
...@@ -122,7 +119,7 @@ func HyprlandModuleEnableCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -122,7 +119,7 @@ func HyprlandModuleEnableCommand(ctx context.Context, cmd *cli.Command) error {
if err != nil { if err != nil {
return err return err
} }
msg, err := manager.SetModule("enable", cmd.Args().Get(0), cmd.Bool("user"), false) msg, err := manager.SetModule("enable", cmd.Args().Get(0), false)
if err != nil { if err != nil {
return err return err
} }
...@@ -130,6 +127,7 @@ func HyprlandModuleEnableCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -130,6 +127,7 @@ func HyprlandModuleEnableCommand(ctx context.Context, cmd *cli.Command) error {
color.Green(msg) color.Green(msg)
return nil return nil
} }
func HyprlandModuleDisableCommand(ctx context.Context, cmd *cli.Command) error { func HyprlandModuleDisableCommand(ctx context.Context, cmd *cli.Command) error {
remove := cmd.Bool("remove") remove := cmd.Bool("remove")
...@@ -143,10 +141,7 @@ func HyprlandModuleDisableCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -143,10 +141,7 @@ func HyprlandModuleDisableCommand(ctx context.Context, cmd *cli.Command) error {
action = "remove" action = "remove"
} }
msg, err := manager.SetModule( msg, err := manager.SetModule(action, cmd.Args().Get(0), false)
action, cmd.Args().Get(0), cmd.Bool("user"), false,
)
if err != nil { if err != nil {
return err return err
} }
...@@ -154,28 +149,28 @@ func HyprlandModuleDisableCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -154,28 +149,28 @@ func HyprlandModuleDisableCommand(ctx context.Context, cmd *cli.Command) error {
color.Green(msg) color.Green(msg)
return nil return nil
} }
func HyprlandToggleModuleCommand(ctx context.Context, cmd *cli.Command) error { func HyprlandToggleModuleCommand(ctx context.Context, cmd *cli.Command) error {
module := cmd.Args().Get(0) module := cmd.Args().Get(0)
user := cmd.Bool("user")
manager, err := GetHyprlandManager(ctx) manager, err := GetHyprlandManager(ctx)
if err != nil { if err != nil {
return err return err
} }
info := manager.GetModuleInfo(module, user) info := manager.GetModuleInfo(module)
var msg string var msg string
switch { switch {
case info.Status.IsEqual(config.ModuleStatus.Enabled): case info.Status.IsEqual(config.ModuleStatus.Enabled):
msg, err = manager.SetModule("disable", module, user, false) msg, err = manager.SetModule("disable", module, false)
case info.Status.IsEqual(config.ModuleStatus.Disabled), info.Status.IsEqual(config.ModuleStatus.Unused): case info.Status.IsEqual(config.ModuleStatus.Disabled), info.Status.IsEqual(config.ModuleStatus.Unused):
msg, err = manager.SetModule("enable", module, user, false) msg, err = manager.SetModule("enable", module, false)
case info.Status.IsEqual(config.ModuleStatus.Missing): case info.Status.IsEqual(config.ModuleStatus.Missing):
msg, err = manager.SetModule("disable", module, user, false) msg, err = manager.SetModule("disable", module, false)
default: default:
msg, err = manager.SetModule("enable", module, user, false) msg, err = manager.SetModule("enable", module, false)
} }
if err != nil { if err != nil {
...@@ -187,7 +182,6 @@ func HyprlandToggleModuleCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -187,7 +182,6 @@ func HyprlandToggleModuleCommand(ctx context.Context, cmd *cli.Command) error {
} }
func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error { func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
user := cmd.Bool("user")
filter := cmd.String("filter") filter := cmd.String("filter")
manager, err := GetHyprlandManager(ctx) manager, err := GetHyprlandManager(ctx)
...@@ -195,7 +189,7 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -195,7 +189,7 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
return err return err
} }
modules := manager.GetModulesList(user, filter) modules := manager.GetModulesList(filter)
if len(modules) == 0 { if len(modules) == 0 {
if config.IsJSON(cmd) { if config.IsJSON(cmd) {
return ui.PrintJSON([]ModuleInfoJSON{}) return ui.PrintJSON([]ModuleInfoJSON{})
...@@ -210,7 +204,7 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -210,7 +204,7 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
data := make([]moduleData, 0, len(modules)) data := make([]moduleData, 0, len(modules))
for _, info := range modules { for _, info := range modules {
errors, err := manager.CheckModule(info.Name, user) errors, err := manager.CheckModule(info.Name)
if err != nil { if err != nil {
errors = nil errors = nil
} }
...@@ -222,6 +216,7 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -222,6 +216,7 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
for i, d := range data { for i, d := range data {
jsonItems[i] = ModuleInfoJSON{ jsonItems[i] = ModuleInfoJSON{
Name: d.info.Name, Name: d.info.Name,
User: d.info.User,
Status: d.info.Status.Label, Status: d.info.Status.Label,
Errors: d.errorNum, Errors: d.errorNum,
} }
...@@ -233,7 +228,7 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -233,7 +228,7 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
return ui.PrintJSON(jsonItems) return ui.PrintJSON(jsonItems)
} }
items := make([]ui.TreeItem, 0, len(data)) var sysItems, userItems []ui.TreeItem
for _, d := range data { for _, d := range data {
var parts []string var parts []string
if d.info.Meta != nil && d.info.Meta.Summary != "" { if d.info.Meta != nil && d.info.Meta.Summary != "" {
...@@ -246,46 +241,61 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -246,46 +241,61 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
if d.info.Meta != nil && d.info.Meta.Group != "" { if d.info.Meta != nil && d.info.Meta.Group != "" {
name = d.info.Meta.Group + "/" + d.info.Name name = d.info.Meta.Group + "/" + d.info.Name
} }
items = append(items, ui.TreeItem{ item := ui.TreeItem{
Name: name, Name: name,
Status: d.info.Status, Status: d.info.Status,
Description: strings.Join(parts, " "), Description: strings.Join(parts, " "),
}) }
if d.info.User {
userItems = append(userItems, item)
} else {
sysItems = append(sysItems, item)
}
} }
ui.RenderTree(ui.RenderTreeOptions{ opts := ui.RenderTreeOptions{
Title: locale.T("Modules"),
Items: items,
Style: ui.DefaultTreeStyle, Style: ui.DefaultTreeStyle,
Color: true, Color: true,
Sort: true, Sort: true,
}) }
if len(sysItems) > 0 {
opts.Title = locale.T("System modules")
opts.Items = sysItems
ui.RenderTree(opts)
}
if len(userItems) > 0 {
if len(sysItems) > 0 {
fmt.Println()
}
opts.Title = locale.T("User modules")
opts.Items = userItems
ui.RenderTree(opts)
}
return nil return nil
} }
func HyprlandModuleEditCommand(ctx context.Context, cmd *cli.Command) error { func HyprlandModuleEditCommand(ctx context.Context, cmd *cli.Command) error {
module := cmd.Args().Get(0) module := cmd.Args().Get(0)
user := cmd.Bool("user")
manager, err := GetHyprlandManager(ctx) manager, err := GetHyprlandManager(ctx)
if err != nil { if err != nil {
return err return err
} }
modulefile := manager.GetModuleFile(module, user) info := manager.GetModuleInfo(module)
info := manager.GetModuleInfo(module, user)
if !info.Available { if !info.Available {
return errors.New(locale.T("invalid module name")) return errors.New(locale.T("invalid module name"))
} }
if info.Path == "" { if info.Path == "" {
return fmt.Errorf(locale.T("module '%s' not found: %s"), module, modulefile) return fmt.Errorf(locale.T("module '%s' not found"), module)
} }
editor := getEditor() editor := getEditor()
editCmd := exec.Command(editor, modulefile) editCmd := exec.Command(editor, info.Path)
editCmd.Stdin = os.Stdin editCmd.Stdin = os.Stdin
editCmd.Stdout = os.Stdout editCmd.Stdout = os.Stdout
editCmd.Stderr = os.Stderr editCmd.Stderr = os.Stderr
...@@ -304,18 +314,17 @@ func HyprlandModuleShowCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -304,18 +314,17 @@ func HyprlandModuleShowCommand(ctx context.Context, cmd *cli.Command) error {
return errors.New(locale.T("specify module name")) return errors.New(locale.T("specify module name"))
} }
user := cmd.Bool("user")
manager, err := GetHyprlandManager(ctx) manager, err := GetHyprlandManager(ctx)
if err != nil { if err != nil {
return err return err
} }
info := manager.GetModuleInfo(module, user) info := manager.GetModuleInfo(module)
if !info.Available { if !info.Available {
return errors.New(locale.T("invalid module name")) return errors.New(locale.T("invalid module name"))
} }
errors, _ := manager.CheckModule(module, user) errors, _ := manager.CheckModule(module)
if config.IsJSON(cmd) { if config.IsJSON(cmd) {
jsonErrors := make([]ModuleErrorJSON, len(errors)) jsonErrors := make([]ModuleErrorJSON, len(errors))
...@@ -392,7 +401,7 @@ func HyprlandNotifyErrorsCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -392,7 +401,7 @@ func HyprlandNotifyErrorsCommand(ctx context.Context, cmd *cli.Command) error {
} }
func cleanupNotifyModule(manager *HyprlandManager, logPath string) { func cleanupNotifyModule(manager *HyprlandManager, logPath string) {
manager.SetModule("disable", "ximperconf-errors", false, false) manager.SetModule("disable", "ximperconf-errors", false)
os.Remove(logPath) os.Remove(logPath)
} }
......
...@@ -64,14 +64,6 @@ func CommandList() *cli.Command { ...@@ -64,14 +64,6 @@ func CommandList() *cli.Command {
{ {
Name: "module", Name: "module",
Usage: locale.T("Hyprland modules"), Usage: locale.T("Hyprland modules"),
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "user",
Usage: locale.T("use user modules"),
Aliases: []string{"u"},
Value: false,
},
},
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
Name: "check", Name: "check",
...@@ -273,7 +265,7 @@ func ShellCompleteModule(filter string) func(ctx context.Context, cmd *cli.Comma ...@@ -273,7 +265,7 @@ func ShellCompleteModule(filter string) func(ctx context.Context, cmd *cli.Comma
return return
} }
modules := manager.GetModulesList(cmd.Bool("user"), filter) modules := manager.GetModulesList(filter)
for _, m := range modules { for _, m := range modules {
fmt.Println(m.Name) fmt.Println(m.Name)
} }
......
...@@ -12,6 +12,7 @@ type ModuleErrorJSON struct { ...@@ -12,6 +12,7 @@ type ModuleErrorJSON struct {
type ModuleInfoJSON struct { type ModuleInfoJSON struct {
Name string `json:"name"` Name string `json:"name"`
User bool `json:"user"`
Group string `json:"group"` Group string `json:"group"`
Summary string `json:"summary"` Summary string `json:"summary"`
Status string `json:"status"` Status string `json:"status"`
......
...@@ -38,6 +38,7 @@ type SourceLine struct { ...@@ -38,6 +38,7 @@ type SourceLine struct {
type HyprModule struct { type HyprModule struct {
Name string `json:"name"` Name string `json:"name"`
User bool `json:"user"`
Status config.ItemStatus `json:"status"` Status config.ItemStatus `json:"status"`
Path string `json:"path"` Path string `json:"path"`
ConfPath string `json:"conf_path"` ConfPath string `json:"conf_path"`
...@@ -144,12 +145,8 @@ func (m *HyprlandManager) Check(configPath string) ([]HyprConfigError, error) { ...@@ -144,12 +145,8 @@ func (m *HyprlandManager) Check(configPath string) ([]HyprConfigError, error) {
return m.parseCheckOutput(output), nil return m.parseCheckOutput(output), nil
} }
func (m *HyprlandManager) CheckModule( func (m *HyprlandManager) CheckModule(module string) ([]HyprConfigError, error) {
module string, info := m.GetModuleInfo(module)
user bool,
) ([]HyprConfigError, error) {
info := m.GetModuleInfo(module, user)
if info.Path == "" { if info.Path == "" {
return nil, fmt.Errorf(locale.T("module '%s' not found"), module) return nil, fmt.Errorf(locale.T("module '%s' not found"), module)
...@@ -173,34 +170,74 @@ func (m *HyprlandManager) CheckModule( ...@@ -173,34 +170,74 @@ func (m *HyprlandManager) CheckModule(
// Modules // Modules
func (m *HyprlandManager) GetModuleInfo(module string, user bool) HyprModule { func (m *HyprlandManager) resolveModule(name string) (user bool, found bool) {
sysFile := m.GetModuleFile(module, user) inUser := slices.Contains(m.UserModules, name)
inSystem := slices.Contains(m.SystemModules, name)
var confPath string switch {
case inUser:
return true, true
case inSystem:
return false, true
}
// Файла нет ни в одном каталоге — ищем по source-строкам
userConfPath := "~" + strings.TrimPrefix(m.GetModuleFile(name, true), m.Home)
sysConfPath := m.GetModuleFile(name, false)
for _, src := range m.Sources {
if src.Path == userConfPath {
return true, true
}
if src.Path == sysConfPath {
return false, true
}
}
return false, false
}
func (m *HyprlandManager) GetModuleInfo(module string) HyprModule {
user, found := m.resolveModule(module)
if !found {
return HyprModule{
Name: module,
Status: config.ModuleStatus.Unknown,
Available: !slices.Contains(config.HyprlandSkipModules, module),
}
}
return m.getModuleInfo(module, user)
}
func (m *HyprlandManager) getModuleInfo(module string, user bool) HyprModule {
modulePath := m.GetModuleFile(module, user)
var confPath string
if user { if user {
confPath = "~" + strings.TrimPrefix(sysFile, m.Home) confPath = "~" + strings.TrimPrefix(modulePath, m.Home)
} else { } else {
confPath = sysFile confPath = modulePath
} }
available := !slices.Contains(config.HyprlandSkipModules, module) available := !slices.Contains(config.HyprlandSkipModules, module)
fileExists := config.FileExists(sysFile) fileExists := config.FileExists(modulePath)
// Конфиг Hyprland отсутствует // Конфиг Hyprland отсутствует
if !config.FileExists(config.Env.Hyprland.Config) { if !config.FileExists(config.Env.Hyprland.Config) {
if fileExists { if fileExists {
return HyprModule{ return HyprModule{
Name: module, Name: module,
User: user,
Status: config.ModuleStatus.Unused, Status: config.ModuleStatus.Unused,
Path: sysFile, Path: modulePath,
ConfPath: confPath, ConfPath: confPath,
Available: available, Available: available,
Meta: ParseModuleMeta(sysFile), Meta: ParseModuleMeta(modulePath),
} }
} }
return HyprModule{ return HyprModule{
Name: module, Name: module,
User: user,
Status: config.ModuleStatus.Missing, Status: config.ModuleStatus.Missing,
Available: available, Available: available,
} }
...@@ -232,6 +269,7 @@ func (m *HyprlandManager) GetModuleInfo(module string, user bool) HyprModule { ...@@ -232,6 +269,7 @@ func (m *HyprlandManager) GetModuleInfo(module string, user bool) HyprModule {
if !fileExists { if !fileExists {
return HyprModule{ return HyprModule{
Name: module, Name: module,
User: user,
Status: config.ModuleStatus.Missing, Status: config.ModuleStatus.Missing,
LineNumber: lineNumber, LineNumber: lineNumber,
Available: available, Available: available,
...@@ -240,12 +278,13 @@ func (m *HyprlandManager) GetModuleInfo(module string, user bool) HyprModule { ...@@ -240,12 +278,13 @@ func (m *HyprlandManager) GetModuleInfo(module string, user bool) HyprModule {
// файл есть // файл есть
return HyprModule{ return HyprModule{
Name: module, Name: module,
User: user,
Status: config.ModuleStatus.Enabled, Status: config.ModuleStatus.Enabled,
Path: sysFile, Path: modulePath,
ConfPath: confPath, ConfPath: confPath,
LineNumber: lineNumber, LineNumber: lineNumber,
Available: available, Available: available,
Meta: ParseModuleMeta(sysFile), Meta: ParseModuleMeta(modulePath),
} }
} }
...@@ -253,14 +292,15 @@ func (m *HyprlandManager) GetModuleInfo(module string, user bool) HyprModule { ...@@ -253,14 +292,15 @@ func (m *HyprlandManager) GetModuleInfo(module string, user bool) HyprModule {
if foundCommented { if foundCommented {
mod := HyprModule{ mod := HyprModule{
Name: module, Name: module,
User: user,
Status: config.ModuleStatus.Disabled, Status: config.ModuleStatus.Disabled,
Path: sysFile, Path: modulePath,
ConfPath: confPath, ConfPath: confPath,
LineNumber: lineNumber, LineNumber: lineNumber,
Available: available, Available: available,
} }
if fileExists { if fileExists {
mod.Meta = ParseModuleMeta(sysFile) mod.Meta = ParseModuleMeta(modulePath)
} else { } else {
mod.Path = "" mod.Path = ""
} }
...@@ -271,17 +311,19 @@ func (m *HyprlandManager) GetModuleInfo(module string, user bool) HyprModule { ...@@ -271,17 +311,19 @@ func (m *HyprlandManager) GetModuleInfo(module string, user bool) HyprModule {
if fileExists { if fileExists {
return HyprModule{ return HyprModule{
Name: module, Name: module,
User: user,
Status: config.ModuleStatus.Unused, Status: config.ModuleStatus.Unused,
Path: sysFile, Path: modulePath,
ConfPath: confPath, ConfPath: confPath,
Available: available, Available: available,
Meta: ParseModuleMeta(sysFile), Meta: ParseModuleMeta(modulePath),
} }
} }
// Файла нет и упоминаний нет // Файла нет и упоминаний нет
return HyprModule{ return HyprModule{
Name: module, Name: module,
User: user,
Status: config.ModuleStatus.Unknown, Status: config.ModuleStatus.Unknown,
Available: available, Available: available,
} }
...@@ -301,20 +343,27 @@ func (m *HyprlandManager) GetModuleDir(user bool) string { ...@@ -301,20 +343,27 @@ func (m *HyprlandManager) GetModuleDir(user bool) string {
return config.Env.Hyprland.SystemModulesDir return config.Env.Hyprland.SystemModulesDir
} }
func (m *HyprlandManager) GetModulesList(user bool, filter string) []HyprModule { func (m *HyprlandManager) GetModulesList(filter string) []HyprModule {
var modules []string seen := make(map[string]bool)
if user { var allModules []string
modules = m.UserModules
} else { // Системные, потом пользовательские; при совпадении имени — user перекрывает
modules = m.SystemModules for _, name := range m.SystemModules {
allModules = append(allModules, name)
seen[name] = true
}
for _, name := range m.UserModules {
if !seen[name] {
allModules = append(allModules, name)
}
} }
groupFilter := strings.TrimPrefix(filter, "group:") groupFilter := strings.TrimPrefix(filter, "group:")
isGroupFilter := groupFilter != filter isGroupFilter := groupFilter != filter
var res []HyprModule var res []HyprModule
for _, module := range modules { for _, module := range allModules {
info := m.GetModuleInfo(module, user) info := m.GetModuleInfo(module)
if !info.Available { if !info.Available {
continue continue
...@@ -322,6 +371,8 @@ func (m *HyprlandManager) GetModulesList(user bool, filter string) []HyprModule ...@@ -322,6 +371,8 @@ func (m *HyprlandManager) GetModulesList(user bool, filter string) []HyprModule
if filter == "" || filter == "all" || if filter == "" || filter == "all" ||
info.Status.Label == filter || info.Status.Label == filter ||
(filter == "user" && info.User) ||
(filter == "system" && !info.User) ||
(isGroupFilter && info.Meta != nil && info.Meta.Group == groupFilter) { (isGroupFilter && info.Meta != nil && info.Meta.Group == groupFilter) {
res = append(res, info) res = append(res, info)
} }
...@@ -329,8 +380,8 @@ func (m *HyprlandManager) GetModulesList(user bool, filter string) []HyprModule ...@@ -329,8 +380,8 @@ func (m *HyprlandManager) GetModulesList(user bool, filter string) []HyprModule
return res return res
} }
func (m *HyprlandManager) SetModule(action, module string, user, onlyNew bool) (string, error) { func (m *HyprlandManager) SetModule(action, module string, onlyNew bool) (string, error) {
info := m.GetModuleInfo(module, user) info := m.GetModuleInfo(module)
if !info.Available { if !info.Available {
return "", errors.New(locale.T("invalid module name")) return "", errors.New(locale.T("invalid module name"))
...@@ -342,7 +393,6 @@ func (m *HyprlandManager) SetModule(action, module string, user, onlyNew bool) ( ...@@ -342,7 +393,6 @@ func (m *HyprlandManager) SetModule(action, module string, user, onlyNew bool) (
switch action { switch action {
case "enable": case "enable":
// нет файла // нет файла
if info.Path == "" || info.Status.IsEqual(config.ModuleStatus.Unknown) { if info.Path == "" || info.Status.IsEqual(config.ModuleStatus.Unknown) {
return "", errors.New(locale.T("cannot enable this module")) return "", errors.New(locale.T("cannot enable this module"))
...@@ -353,10 +403,10 @@ func (m *HyprlandManager) SetModule(action, module string, user, onlyNew bool) ( ...@@ -353,10 +403,10 @@ func (m *HyprlandManager) SetModule(action, module string, user, onlyNew bool) (
return "", fmt.Errorf(locale.T("module '%s' is already enabled"), module) return "", fmt.Errorf(locale.T("module '%s' is already enabled"), module)
} }
// отключить другие модули той же группы // отключить другие модули той же группы (кросс-типовое)
var disabledGroup []string var disabledGroup []string
if info.Meta != nil && info.Meta.Group != "" { if info.Meta != nil && info.Meta.Group != "" {
for _, other := range m.GetModulesList(user, "enabled") { for _, other := range m.GetModulesList("enabled") {
if other.Name == module { if other.Name == module {
continue continue
} }
...@@ -386,14 +436,13 @@ func (m *HyprlandManager) SetModule(action, module string, user, onlyNew bool) ( ...@@ -386,14 +436,13 @@ func (m *HyprlandManager) SetModule(action, module string, user, onlyNew bool) (
if info.Meta != nil { if info.Meta != nil {
order = info.Meta.Order order = info.Meta.Order
} }
m.insertSourceLine(info.ConfPath, user, order) m.insertSourceLine(info.ConfPath, info.User, order)
return m.enableMessage(module, disabledGroup), nil return m.enableMessage(module, disabledGroup), nil
} }
return "", fmt.Errorf(locale.T("module '%s' not changed"), module) return "", fmt.Errorf(locale.T("module '%s' not changed"), module)
case "disable": case "disable":
// Уже выключен // Уже выключен
if info.Status.IsEqual(config.ModuleStatus.Disabled) || if info.Status.IsEqual(config.ModuleStatus.Disabled) ||
info.Status.IsEqual(config.ModuleStatus.Unused) { info.Status.IsEqual(config.ModuleStatus.Unused) {
......
...@@ -199,7 +199,7 @@ func processHyprModules(manager *hyprland.HyprlandManager, prof config.PresetPro ...@@ -199,7 +199,7 @@ func processHyprModules(manager *hyprland.HyprlandManager, prof config.PresetPro
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.NewOnly); err != nil {
res.Add(cat, 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(cat, 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)
...@@ -253,12 +253,12 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP ...@@ -253,12 +253,12 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP
continue continue
} }
info := manager.GetModuleInfo(name, isUser) info := manager.GetModuleInfo(name)
if !info.Status.IsEqual(config.ModuleStatus.Enabled) { if !info.Status.IsEqual(config.ModuleStatus.Enabled) {
continue continue
} }
if _, err := manager.SetModule("disable", name, isUser, false); err != nil { if _, err := manager.SetModule("disable", name, false); err != nil {
res.Add(cat, 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
} }
...@@ -274,7 +274,7 @@ func processVerifyModules(manager *hyprland.HyprlandManager, prof config.PresetP ...@@ -274,7 +274,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); err != nil {
res.Add(cat, 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)
} }
} }
......
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