Skip to content

fix: fall back window screenshots to Device Simulator#1767

Merged
hatayama merged 3 commits into
feature/simulator-view-supportfrom
fix/window-capture-simulator-fallback
Jul 14, 2026
Merged

fix: fall back window screenshots to Device Simulator#1767
hatayama merged 3 commits into
feature/simulator-view-supportfrom
fix/window-capture-simulator-fallback

Conversation

@hatayama

@hatayama hatayama commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Refs: MasaVault 2026-07-14_シミュレーターモードでのマウスシミュレート調査.md PR-2 (To-Do 10–12)

Summary

  • When --capture-mode window uses the default window name Game and no matching tab exists, retry with Simulator.
  • Choice: implement fallback (not guidance-only). The change is a small exact-match retry; error text still mentions --window-name Simulator if both miss.
  • Window title constants live in UnityCliLoopConstants; schema default uses the same constant.

User Impact

  • With only Device Simulator open, uloop screenshot --capture-mode window (no --window-name) captures the Simulator chrome instead of returning 0 screenshots.

Test plan

  • dist/darwin-arm64/uloop compile → 0/0
  • ScreenshotWindowNameResolverTests EditMode → passed
  • Game tab closed, Simulator open: default --capture-mode window returns Simulator_*.png
  • GHA: not applicable on this PR — base is umbrella feature/simulator-view-support (workflows only for main / v3-beta). Full GHA on the final umbrella → v3-beta PR.

Made with Cursor

Review in cubic

hatayama and others added 2 commits July 14, 2026 09:47
When Device Simulator replaces the Game tab, the default --window-name
Game finds nothing. Retry with Simulator so unspecified window capture
still returns a chrome screenshot.

Co-authored-by: Cursor <cursoragent@cursor.com>
Cover when the Game-to-Simulator retry applies and when it must not
override an explicit non-Game window name.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@hatayama, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 50 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0974d1b6-bae1-4de6-aa10-53a6c50d229f

📥 Commits

Reviewing files that changed from the base of the PR and between 925ef04 and 9e66ceb.

📒 Files selected for processing (2)
  • Assets/Tests/Editor/ScreenshotWindowNameResolverTests.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs
📝 Walkthrough

Walkthrough

Adds centralized screenshot window-name constants and a resolver that falls back from an unmatched exact “Game” window to “Simulator.” Capture retries with the resolved name, updates related errors and filenames, and logs both requested and effective names.

Changes

Screenshot window fallback

Layer / File(s) Summary
Window-name contracts and fallback resolution
Packages/src/Editor/ToolContracts/UnityCliLoopConstants.cs, Packages/src/Editor/ToolContracts/ScreenshotSchema.cs, Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotWindowNameResolver.cs, Assets/Tests/Editor/ScreenshotWindowNameResolverTests.cs
Adds default and Simulator window constants, uses the default constant in the screenshot schema, implements conditional fallback resolution, and tests the supported and unsupported fallback cases.
Capture retry and result reporting
Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs
Uses the resolved capture name for retry lookup, filename sanitization, error messaging, and success logging alongside the original requested name.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CaptureRequest
  participant CaptureWindowsAsync
  participant ScreenshotWindowNameResolver
  participant UnityEditorWindows
  participant ScreenshotSuccessLogger
  CaptureRequest->>CaptureWindowsAsync: request window capture
  CaptureWindowsAsync->>ScreenshotWindowNameResolver: resolve requested name
  ScreenshotWindowNameResolver-->>CaptureWindowsAsync: Game or Simulator
  CaptureWindowsAsync->>UnityEditorWindows: search effective window
  UnityEditorWindows-->>CaptureWindowsAsync: matching window result
  CaptureWindowsAsync->>ScreenshotSuccessLogger: log requested and effective names
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: screenshot window capture now falls back to Device Simulator.
Description check ✅ Passed The description is directly related to the changeset and accurately describes the fallback behavior and test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/window-capture-simulator-fallback

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Route CaptureWindowsAsync through ResolveCaptureWindowName so production
and tests share one path, and report neither Game nor Simulator when the
fallback lookup also returns empty.

Co-authored-by: Cursor <cursoragent@cursor.com>
@hatayama
hatayama merged commit 2454e40 into feature/simulator-view-support Jul 14, 2026
1 of 2 checks passed
@hatayama
hatayama deleted the fix/window-capture-simulator-fallback branch July 14, 2026 00:50

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs (1)

259-276: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Utilize the ResolveCaptureWindowName helper.

You have explicitly defined and unit-tested ScreenshotWindowNameResolver.ResolveCaptureWindowName, but it is bypassed here in favor of manually assigning the fallback window name. Consider using the helper to eliminate duplicate logic.

♻️ Proposed refactor
-            string captureWindowName = request.WindowName;
-            if (ScreenshotWindowNameResolver.ShouldFallbackToSimulator(
-                    request.WindowName,
-                    request.MatchMode,
-                    windows.Length))
-            {
-                // why: Device Simulator replaces the Game tab, so the default "Game" title miss should retry Simulator
-                captureWindowName = UnityCliLoopConstants.SCREENSHOT_SIMULATOR_WINDOW_NAME;
-                windows = EditorWindowCaptureUtility.FindWindowsByName(captureWindowName, request.MatchMode);
-                if (windows.Length > 0)
-                {
-                    VibeLogger.LogInfo(
-                        "screenshot_window_fallback_simulator",
-                        $"Window '{request.WindowName}' not found; capturing '{captureWindowName}' instead",
-                        correlationId: correlationId
-                    );
-                }
-            }
+            string captureWindowName = ScreenshotWindowNameResolver.ResolveCaptureWindowName(
+                request.WindowName,
+                request.MatchMode,
+                windows.Length);
+
+            if (captureWindowName != request.WindowName)
+            {
+                // why: Device Simulator replaces the Game tab, so the default "Game" title miss should retry Simulator
+                windows = EditorWindowCaptureUtility.FindWindowsByName(captureWindowName, request.MatchMode);
+                if (windows.Length > 0)
+                {
+                    VibeLogger.LogInfo(
+                        "screenshot_window_fallback_simulator",
+                        $"Window '{request.WindowName}' not found; capturing '{captureWindowName}' instead",
+                        correlationId: correlationId
+                    );
+                }
+            }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs` around
lines 259 - 276, Update the screenshot window fallback logic in the surrounding
capture flow to use ScreenshotWindowNameResolver.ResolveCaptureWindowName
instead of manually assigning
UnityCliLoopConstants.SCREENSHOT_SIMULATOR_WINDOW_NAME. Preserve the existing
window lookup, fallback logging, and capture behavior while routing name
selection through the tested helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs`:
- Around line 259-276: Update the screenshot window fallback logic in the
surrounding capture flow to use
ScreenshotWindowNameResolver.ResolveCaptureWindowName instead of manually
assigning UnityCliLoopConstants.SCREENSHOT_SIMULATOR_WINDOW_NAME. Preserve the
existing window lookup, fallback logging, and capture behavior while routing
name selection through the tested helper.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dc6dae54-fb9b-4c6f-b95a-c782cae92193

📥 Commits

Reviewing files that changed from the base of the PR and between fe39a68 and 925ef04.

⛔ Files ignored due to path filters (2)
  • Assets/Tests/Editor/ScreenshotWindowNameResolverTests.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotWindowNameResolver.cs.meta is excluded by none and included by none
📒 Files selected for processing (5)
  • Assets/Tests/Editor/ScreenshotWindowNameResolverTests.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotWindowNameResolver.cs
  • Packages/src/Editor/ToolContracts/ScreenshotSchema.cs
  • Packages/src/Editor/ToolContracts/UnityCliLoopConstants.cs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant