From 3fe92537be46c890d2a45e40ece53d813ce9f4bd Mon Sep 17 00:00:00 2001 From: PJ Date: Sun, 31 May 2026 14:30:36 +0530 Subject: [PATCH] feat(driver): add FocusedWindowChecker capability --- internal/driver/driver.go | 12 ++++++++++++ internal/driver/sidecar/client.go | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/internal/driver/driver.go b/internal/driver/driver.go index ccd916d..6bde5e0 100644 --- a/internal/driver/driver.go +++ b/internal/driver/driver.go @@ -47,6 +47,18 @@ type ForegroundChecker interface { ForegroundApp(ctx context.Context) (string, error) } +// FocusedWindowChecker is the optional capability for reporting which app owns +// the focused (on-screen) window. The startup gate prefers it over +// ForegroundChecker: the resumed-activity signal flips to a freshly launched +// app before its first frame draws, so observing on it alone can capture the +// previous app's screen. The focused window only names the app once its window +// is actually up. +type FocusedWindowChecker interface { + // FocusedWindowApp returns the package owning the focused window, or "" + // when no window is focused yet (e.g. mid-launch transition). + FocusedWindowApp(ctx context.Context) (string, error) +} + type LogEntry struct { UnixMillis int64 Level string diff --git a/internal/driver/sidecar/client.go b/internal/driver/sidecar/client.go index fdf4ec5..f356c9a 100644 --- a/internal/driver/sidecar/client.go +++ b/internal/driver/sidecar/client.go @@ -33,6 +33,16 @@ func (c *Client) ForegroundApp(ctx context.Context) (string, error) { return android.ForegroundPackage(ctx) } +// FocusedWindowApp reports the package owning the focused window. Only Android +// is supported (via adb); other platforms return "" so the startup gate falls +// back to the foreground-app signal. +func (c *Client) FocusedWindowApp(ctx context.Context) (string, error) { + if c.platform != "android" { + return "", nil + } + return android.FocusedWindowPackage(ctx) +} + // Dial connects to the sidecar gRPC server at the given address. // Address must be a host:port pair, typically "127.0.0.1:". func Dial(address string) (*Client, error) {