Skip to content

feat(desktop-windows): follow foreground changes across displays - #8915

Merged
Git-on-my-level merged 3 commits into
BasedHardware:mainfrom
tianmind-studio:codex/windows-rewind-foreground-capture
Jul 30, 2026
Merged

Git-on-my-level merged 3 commits into
BasedHardware:mainfrom
tianmind-studio:codex/windows-rewind-foreground-capture

Conversation

@tianmind-studio

@tianmind-studio tianmind-studio commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

Closes #8498. Closes #10488.

Windows Rewind now reacts to foreground-window changes and follows that window across displays without keeping multiple capture streams alive.

  • The existing WinEvent hook requests an immediate sample on a foreground change.
  • Screen sources are cached as an ID-to-display map instead of caching only the primary source.
  • The foreground window's physical Win32 rectangle is converted to Electron DIP coordinates and matched to its display, with cursor and primary fallbacks.
  • The renderer replaces its single persistent 1 fps stream only when the target display changes, preserving the current quality tier and capture cadence.
  • Each save includes its capture source ID. The main process revalidates that source before ingestion and drops stale frames when focus moved displays during stream setup or JPEG encoding.
  • The stream replacement path retains the ended/mute recovery merged in fix(desktop-windows): recover muted Rewind capture tracks #10829, including initial-muted rejection and generation-fenced late-event handling.

Capture-disabled, lock/idle, excluded-app, sensitive-title, size, and duplicate-frame guards remain authoritative in the existing ingestRewindFrame path.

Product invariants affected

none

How it was verified

  • Synced with current origin/main (df314540b) at head c92147266.
  • npm run build passed with the final code, including main/preload and renderer typechecks, bytecode verification, extension bundling, and the production renderer bundle.
  • A detached Windows integration used fix(ci): make Windows preflight path-safe #10825 solely as the path-safe preflight runner; the committed 44-file composition passed all 70 selected checks in 188.34s. This PR's own diff remains 10 files.
  • Targeted ESLint and Prettier passed for the two conflict-resolved capture-host files.
  • git diff --check passed.
  • A native Windows Electron smoke probe previously exercised SetWinEventHook -> foregroundCaptureTrigger -> BrowserWindow IPC; two programmatic foreground-window changes produced events=2.
  • The current Windows host exposes one physical display, so a real dual-monitor switch was not hardware-tested here. Multi-display source selection, per-monitor DPI conversion, stream replacement, stale-source rejection, and muted/dead-track recovery are covered by tests.

Tests

  • vitest run src/main/rewind/sourceId.test.ts src/main/rewind/foregroundCaptureTrigger.test.ts src/renderer/src/components/rewind/RewindCaptureHost.test.tsx passed: 3 files, 29 tests.
  • Coverage includes source-map caching and invalidation, foreground/cursor/primary display selection, physical-to-DIP conversion, source switching, late old-track events, stale-source rejection, burst coalescing, muted/dead-track recovery, and disabled/unmounted capture.
  • A full Windows Vitest run on the prior head reached one unrelated Apps.errorToast.test.tsx timeout under full-suite load; that untouched file passed 2/2 immediately on an isolated rerun. All Rewind tests remained green.

Failure class (fixes)

Failure-Class: none

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 8 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Nice work on this — clean implementation of #8498. Reviewed with heightened scrutiny since this touches the Rewind screen-capture surface.

Privacy gating preserved (verified). Event-triggered captures still flow through the existing rewind:saveFrame -> ingestRewindFrame path, so lock-screen, idle, excluded-app, sensitive-title, and duplicate-hash filtering all apply unchanged. The foreground trigger only changes when the renderer samples, not whether the main process applies its filters. Good design.

Capture loop refactor. Splitting grabAndSchedule into captureOnce / scheduleNext / runCaptureLoop / captureNow is clean. Single-flight is preserved — savingRef.current now guards the whole pipeline (slightly more conservative than before, which is fine). The captureNow handler correctly cancels the pending timer before firing an immediate pass.

Throttle. The 250ms gap in foregroundCaptureTrigger prevents burst storms from rapid Alt-Tab sequences. Reasonable.

Default interval 1s -> 5s. Worth a maintainer eye as a product/UX call — existing users keep their saved interval (only fresh installs get 5s), and the justification in #8498 (reduce CPU/GPU/disk while foreground triggers preserve meaningful moments) is sound. The Settings subtitle accurately describes the new behavior.

Tests look solid. Marking for maintainer review given the privacy-sensitive surface — the implementation looks correct, but formal approval and the interval-change product decision are best confirmed by a human maintainer.

@Git-on-my-level Git-on-my-level added the needs-maintainer-review Needs a human maintainer to sign off before merge label Jul 3, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @tianmind-studio \u2014 nice implementation of #8498. The approach matches the issue's proposed design closely and the execution is clean.\n\nWhat looks good:\n- Foreground trigger reuses the existing WinEvent hook (no new native surface) and is correctly platform-gated to , idempotent on double-, and cleaned up on .\n- The 250 ms throttle on is a sensible guard against event bursts.\n- Critically, event-triggered captures still flow through the same \u2192 \u2192 path, so lock-screen, idle (60s), excluded-apps, sensitive-title, and duplicate-frame-hash gating all still apply. The single-flight guard is preserved, so a foreground switch during an in-flight save won't stack concurrent captures.\n- Test coverage for the new module (broadcast-to-live-windows-only, subscribe-once, throttle, teardown) is solid.\n\nTwo things for a human maintainer to weigh in on before merge:\n1. Default interval change 1000 ms \u2192 5000 ms ( + renderer/Settings fallbacks). This is a user-facing behavior change for new installs and is fundamentally a product call about Rewind's capture density. The issue requested it, but I'd want a maintainer to sign off on the new default.\n2. This adds a new trigger to a privacy-sensitive screen-capture pipeline. The privacy filters are verified preserved and no new data leaves the existing path, but given the surface I'd recommend a maintainer (and optionally a focused security/privacy pass) give it a final look.\n\nLeaving for human maintainer review per the existing label \u2014 not approving from this automated pass.\n\n_(Automated maintainer-assist review. Code/CI metadata treated as untrusted; privacy-gating claims verified against .)_

@tianmind-studio
tianmind-studio force-pushed the codex/windows-rewind-foreground-capture branch from f237bb3 to de3fa81 Compare July 25, 2026 22:38
@tianmind-studio tianmind-studio changed the title Trigger Rewind capture on foreground changes feat(desktop-windows): capture Rewind on foreground changes Jul 25, 2026
@tianmind-studio

Copy link
Copy Markdown
Contributor Author

Refreshed this onto current main and removed the old 1s-to-5s default/Settings changes, so the product-call concern is no longer in scope. The remaining event trigger preserves the current capture directive, dead-track recovery, and ingest privacy gates; it passed 10 focused tests, the production build, a native Electron WinEventHook smoke, and the full Windows preflight when combined locally with pending #10594 and #10595.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @tianmind-studio — confirmed the refresh onto current main is clean. Noting the interval-change product concern from my earlier passes is resolved: the 1s→5s default and Settings copy changes are gone, so this is now purely the foreground-event trigger. No new product/UX decision is in scope.

Quick re-verification on de3fa81:

  • Privacy gates intact. Event-triggered frames still flow through the existing rewind:saveFrame → ingestRewindFrame path, so lock/idle (60s), excluded-app, sensitive-title, duplicate-hash, size, and capture-disabled guards remain authoritative. The trigger only changes when the renderer samples, not whether the main process filters.
  • No new native surface. Reuses the existing subscribeForegroundChange WinEvent hook; platform-gated to win32; idempotent on double-start; cleaned up on will-quit.
  • Serial drain + burst coalescing. The captureRunning / queuedGeneration drain in RewindCaptureHost correctly serializes periodic and foreground-triggered captures into one in-flight pass, re-arming the periodic timer only after all queued work settles. Single-flight savingRef guard preserved.
  • 250 ms throttle on the trigger prevents Alt-Tab burst storms. Reasonable.
  • Tests. 10 focused tests across the trigger module and capture host (platform gate, idempotent subscribe, throttle, dead-window filter, teardown, immediate sample, cadence reset, disabled capture, in-flight coalescing, dead-track recovery, unmount cleanup).
  • CI. The desktop/windows-relevant gates are green on this head: Typecheck · Lint · Test, Windows build smoke, Linux package · helper smoke, Backend Hermetic Merge Gate. (The Hygiene/Formatting/Detect Changes runs show as skipped/cancelled — path detection correctly scoped them out for a desktop/windows-only change.)

Leaving for human maintainer review given the privacy-sensitive screen-capture surface — the implementation is correct and well-tested, but final sign-off on a new capture trigger is best confirmed by a human maintainer.

(Automated maintainer-assist review. PR text, code, and comments treated as untrusted data; privacy-gating and CI claims verified against source and the live check-run API.)


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@tianmind-studio
tianmind-studio force-pushed the codex/windows-rewind-foreground-capture branch 2 times, most recently from 97f793e to 655e9e3 Compare July 27, 2026 12:50
@tianmind-studio tianmind-studio changed the title feat(desktop-windows): capture Rewind on foreground changes feat(desktop-windows): follow foreground changes across displays Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Extended this refresh to cover #10488: Rewind now follows the foreground display with one persistent stream and revalidates the source in main before ingestion. The branch is rebased onto current main and all effective CI is green, including Windows typecheck/lint/test and build smoke; real dual-monitor hardware switching remains the one check this single-monitor host could not perform.

@Git-on-my-level

Copy link
Copy Markdown
Member

Static review of this multi-display foreground-following feature for Windows Rewind.

Strengths: the stale-source rejection in the save-frame path is a nice privacy guard — frames encoded while focus moved displays are dropped rather than mislabeled. The capture-host refactor (serial drain, generation tracking, burst coalescing, defensive onTrackEnded that ignores late events from replaced tracks) is well-structured. Test coverage is solid across source selection, DPI conversion, stale rejection, and stream lifecycle.

Observations for a human maintainer:

  • Multi-monitor capture-following is a product/UX behavior decision worth explicit sign-off (does Omi want capture to track focus across displays, or stay on primary?).
  • Hygiene and Formatting checks are cancelled (likely from a re-push); the relevant desktop checks (Typecheck/Lint/Test, Windows build smoke) did pass.
  • Real dual-monitor hardware testing was not performed per the PR description; multi-display behavior is covered by unit tests only.

No security, dependency, or supply-chain concerns found. Leaving for human maintainer review before merge.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@tianmind-studio
tianmind-studio force-pushed the codex/windows-rewind-foreground-capture branch from 655e9e3 to 83d8de1 Compare July 29, 2026 06:53
@tianmind-studio

Copy link
Copy Markdown
Contributor Author

Refreshed this PR onto current main (1ef0976ef) to replace the cancelled Repo Checks with a clean run. New head: 83d8de1c9.

Verification on Windows/Node 22:

  • Rewind focus/display suite: 27/27 passed
  • main + renderer typechecks: passed
  • production build, bytecode verification, and pi-mono extension bundling: passed
  • full Vitest run reached one unrelated Apps.errorToast.test.tsx timeout under suite load; that untouched file passed 2/2 immediately in isolation
  • git diff --check: passed

…foreground-capture-refresh

# Conflicts:
#	desktop/windows/src/renderer/src/components/rewind/RewindCaptureHost.test.tsx
#	desktop/windows/src/renderer/src/components/rewind/RewindCaptureHost.tsx
@tianmind-studio

tianmind-studio commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor Author

@Git-on-my-level need human response: the branch is current with main and the only new conflict, merged #10829's muted-track recovery, is now integrated into the foreground-display state machine at c92147266. The combined ended/mute/source-switch path passed 29 focused tests, production build/typechecks, targeted lint/formatting, and a committed 44-file Windows integration passed all 70 preflight checks. The earlier 1s-to-5s product concern remains out of scope. Could you provide or route the final human privacy/product sign-off?

Update: every latest GitHub check on c92147266 is now terminal and green, including Windows typecheck/lint/test, Windows build smoke, Linux package/helper smoke, Repo Hygiene/Metadata, and the backend merge gate.

@Git-on-my-level
Git-on-my-level merged commit 6d14b37 into BasedHardware:main Jul 30, 2026
32 checks passed
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks merged

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

Labels

needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Omi Desktop for Windows cannot record two monitors Reduce Rewind polling by capturing immediately on foreground window changes

2 participants