hyprland: add reload command

parent 264fdd09
......@@ -46,6 +46,54 @@ func HyprlandFixConfigCommand(ctx context.Context, cmd *cli.Command) error {
return nil
}
func HyprlandReloadCommand(ctx context.Context, cmd *cli.Command) error {
manager, err := GetHyprlandManager(ctx)
if err != nil {
return err
}
errs, err := manager.Check("")
if err != nil {
return err
}
if len(errs) > 0 {
if cmd.Bool("gui") {
var lines []string
for _, e := range errs {
lines = append(lines, fmt.Sprintf("%s:%d -> %s", e.File, e.Line, e.Text))
}
text := locale.T("Config has errors, not reloading:") + "\n\n" + strings.Join(lines, "\n")
dialogCmd := exec.Command(
"hyprland-dialog",
"--title", locale.T("Hyprland reload"),
"--text", text,
"--buttons", "OK",
)
_ = dialogCmd.Run()
return nil
}
fmt.Println(locale.T("Config has errors, not reloading:"))
for _, e := range errs {
fmt.Printf(" %s:%d -> %s\n", e.File, e.Line, e.Text)
}
return nil
}
if out, err := exec.Command("hyprctl", "reload").CombinedOutput(); err != nil {
return fmt.Errorf(locale.T("failed to reload: %s"), strings.TrimSpace(string(out)))
}
if cmd.Bool("gui") {
// 5 = Ok, цвет 0 (дефолтный для иконки), 3000ms
exec.Command("hyprctl", "notify", "5", "3000", "0", locale.T("Config reloaded")).Run()
} else {
color.Green(locale.T("Config reloaded"))
}
return nil
}
func HyprlandCheckCommand(ctx context.Context, cmd *cli.Command) error {
manager, err := GetHyprlandManager(ctx)
if err != nil {
......
......@@ -49,6 +49,17 @@ func CommandList() *cli.Command {
Action: HyprlandFixConfigCommand,
},
{
Name: "reload",
Usage: locale.T("Verify config and reload Hyprland"),
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "gui",
Usage: locale.T("Show errors in a dialog window"),
},
},
Action: HyprlandReloadCommand,
},
{
Name: "binds",
Usage: locale.T("Show keybindings"),
Flags: []cli.Flag{
......
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