Files

41 lines
1.2 KiB
Go

// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package atspi
import (
"context"
"time"
)
// A successful ScrollTo can precede the browser's visibility/geometry update.
// Retry missing geometry on the calling worker, leaving the native event owner
// free to process those updates. Unsupported geometry gets at most 50ms of
// extra waiting; native calls remain bounded by the caller's context.
func retryDocumentSoundGeometry(ctx context.Context, linked bool, capture func(context.Context) ([2]SoundGeometry, error)) ([2]SoundGeometry, error) {
for attempt := 0; ; attempt++ {
if err := ctx.Err(); err != nil {
return [2]SoundGeometry{}, err
}
geometry, err := capture(ctx)
if err != nil {
return [2]SoundGeometry{}, err
}
ready := geometry[0].ObjectKnown && geometry[0].ReferenceKnown
if linked {
ready = ready && geometry[1].ObjectKnown && geometry[1].ReferenceKnown
}
if ready || attempt == 5 {
return geometry, nil
}
timer := time.NewTimer(10 * time.Millisecond)
select {
case <-ctx.Done():
timer.Stop()
return [2]SoundGeometry{}, ctx.Err()
case <-timer.C:
}
}
}