42 lines
822 B
Go
42 lines
822 B
Go
package hypr
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// IsReachable pings the unix socket to check
|
|
// if Hyprland is ready to accept incoming requests
|
|
func (c *Client) IsReachable() bool {
|
|
str, err := readSocketString(c.SocketPath(), strings.NewReader("dispatch exec echo"))
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
return str == "ok"
|
|
}
|
|
|
|
// WaitUntilReachable periodically calls IsReachable
|
|
// and returns true as soon as IsReachable returns true.
|
|
// When ctx is closed before Hyprland is reachable, false is returned
|
|
func (c *Client) WaitUntilReachable(ctx context.Context) bool {
|
|
if c.IsReachable() {
|
|
return true
|
|
}
|
|
|
|
ticker := time.NewTicker(100 * time.Millisecond)
|
|
defer ticker.Stop()
|
|
|
|
for {
|
|
select {
|
|
case <-ticker.C:
|
|
if c.IsReachable() {
|
|
return true
|
|
}
|
|
case <-ctx.Done():
|
|
return false
|
|
}
|
|
}
|
|
}
|