WaitForClient implemented
This commit is contained in:
parent
62341d584a
commit
9fad501f41
@ -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)
|
||||
})
|
||||
}
|
||||
|
16
utils.go
16
utils.go
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user