From 663f9e7180f195c30298489e155dbdcac285dacc Mon Sep 17 00:00:00 2001 From: PJ Date: Thu, 11 Jun 2026 09:17:44 +0530 Subject: [PATCH] fix(runner): apply-time guard consults focused window, not just resumed activity ensureForeground detects a system overlay (notification shade) owning the focused window while the app stays the resumed activity, but appIsForeground only queried ForegroundApp. A swipe that pulls the shade over the app between observe and apply then fired onto the shade. Mirror the focus check at apply time so the action skips and the next step dismisses the overlay. --- internal/runner/runner.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 2de3f4a..ffd6d5c 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -437,7 +437,22 @@ func appIsForeground(ctx context.Context, options Options) bool { if err != nil || foreground == "" { return true } - return foreground == options.BundleID + if foreground != options.BundleID { + return false + } + // The app is the resumed activity, but a system overlay (the notification + // shade) can own the focused window while the app stays resumed; firing the + // action would land on the overlay. Mirror ensureForeground's focus check + // here so the apply-time guard skips and the next step dismisses it. + focusChecker, ok := options.Driver.(driver.FocusedWindowChecker) + if !ok { + return true + } + focused, err := focusChecker.FocusedWindowApp(ctx) + if err != nil || focused == "" { + return true + } + return focused == options.BundleID } // foregroundReadyAttempts bounds how many times waitForForeground tries to