WaitForClient implemented

This commit is contained in:
Milarin 2024-08-26 21:43:18 +02:00
parent 62341d584a
commit 9fad501f41
2 changed files with 26 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package hypr
import (
"context"
"errors"
"fmt"
"io"
@ -68,3 +69,12 @@ func GetClients() ([]*Client, error) {
return clients, nil
}
func WaitForClient(ctx context.Context, signature string) {
lockFilePath := fmt.Sprintf("/run/user/1000/hypr/%s/hyprland.lock", signature)
waitFor(func() bool {
_, err := os.Stat(lockFilePath)
return !errors.Is(err, os.ErrNotExist)
})
}

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"io"
"net"
"time"
)
func readSocketRaw(socket string, body io.Reader) (io.ReadCloser, error) {
@ -49,3 +50,18 @@ func readSocket[T any](socket string, body io.Reader) (T, error) {
return *value, nil
}
func waitFor(condition func() bool) {
if condition() {
return
}
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
for range ticker.C {
if condition() {
break
}
}
}