hypr/dispatch.go

25 lines
539 B
Go
Raw Normal View History

2024-02-09 20:24:48 +01:00
package hypr
import (
"fmt"
"io"
"strings"
)
func (i *Instance) Dispatch(cmd string) (io.ReadCloser, error) {
2024-02-09 22:16:08 +01:00
return readSocketRaw(i.SocketPath(), strings.NewReader(fmt.Sprintf("dispatch %s", cmd)))
2024-02-09 20:24:48 +01:00
}
func (i *Instance) DispatchExpectOK(cmd string) error {
2024-02-09 22:16:08 +01:00
str, err := readSocketString(i.SocketPath(), strings.NewReader(fmt.Sprintf("dispatch %s", cmd)))
2024-02-09 20:24:48 +01:00
if err != nil {
return err
}
if strings.ToLower(strings.TrimSpace(str)) != "ok" {
return fmt.Errorf("dispatcher '%s' returned an error: %s", cmd, str)
}
return nil
}