Repository navigation
Description
Improve Rewind capture cadence with foreground-window triggered snapshots
Current behavior
Rewind currently samples the screen on a fixed interval, defaulting to roughly every 1 second.
The renderer keeps a desktop getUserMedia stream alive, draws the current video frame to a canvas, encodes it as JPEG, then sends it to the main process via rewind:saveFrame.
This works, but it means the app continuously samples/encodes frames even when the user stays on the same unchanged window.
Proposal
Make Rewind capture less frequent by default, for example every 5 seconds, but trigger an immediate capture whenever the active foreground window changes.
Proposed behavior:
- Periodic capture every ~5 seconds.
- Immediate capture on foreground window/app change.
- Keep existing filters:
- lock screen
- idle state
- excluded apps
- sensitive window titles
- duplicate-frame hash check
- Do not bypass privacy/sensitive-window detection for event-triggered captures.
Why
This could reduce CPU/GPU usage and disk writes while preserving the most important Rewind moments.
A window/app switch is usually a meaningful timeline boundary. Capturing immediately on foreground change avoids waiting up to the next interval, while allowing the normal polling interval to be slower.
Relevant code
desktop/windows/src/renderer/src/components/rewind/RewindCaptureHost.tsx- owns the screen stream, canvas sampling, JPEG encoding
desktop/windows/src/main/rewind/captureService.ts- receives JPEG frames, applies gating/deduping, writes frame + DB row
desktop/windows/src/main/usage/foregroundMonitor.ts- already uses foreground change events for app usage tracking
desktop/windows/src/main/usage/nativeForeground.ts- exposes foreground window detection/subscription
Possible implementation
Since the renderer owns the actual capture stream/canvas, the main process cannot directly grab a frame from captureService.ts.
One possible approach:
- Main process listens for foreground window changes.
- On change, main sends a lightweight IPC event to renderer, e.g.
rewind:captureNow. RewindCaptureHostreceives that event and immediately runs onegrabAndSchedule()pass.- Existing
ingestRewindFrame()logic still decides whether to save or skip the frame.
Acceptance criteria
- Rewind periodic capture interval can be increased to around 5s.
- Switching foreground apps/windows triggers an immediate Rewind sample.
- Immediate samples still respect existing privacy filters and duplicate-frame detection.
- No concurrent frame saves stack up if a foreground-change event fires during an existing save.
- Chat screen context remains reasonably fresh, or the tradeoff is documented.
Activity
feat(desktop-windows): follow foreground changes across displays (#8915)