Skip to content

Add screenshot capture settings for token and payload optimization#17

Open
antiartificial wants to merge 1 commit intofarzaa:mainfrom
antiartificial:feature/screenshot-capture-settings
Open

Add screenshot capture settings for token and payload optimization#17
antiartificial wants to merge 1 commit intofarzaa:mainfrom
antiartificial:feature/screenshot-capture-settings

Conversation

@antiartificial
Copy link
Copy Markdown

@antiartificial antiartificial commented Apr 8, 2026

Summary

  • Primary screen only toggle skips secondary monitors, saving ~1,300+ tokens per extra display
  • Active window only toggle captures just the frontmost window instead of the full screen, reducing noise and tokens
  • JPEG quality slider (30%-100%) lets users trade image quality for smaller upload payloads

All three settings live in a new "SCREENSHOT" section in the menu bar panel, persist via UserDefaults, and are wired into both the voice response and onboarding demo capture pipelines. Defaults match existing behavior (all screens, full screen, 80% quality) so nothing changes unless a user opts in.

Files changed

  • CompanionManager.swift three new @Published settings with UserDefaults persistence
  • CompanionScreenCaptureUtility.swift captureAllScreensAsJPEG() accepts new parameters for filtering screens, capturing active window via SCContentFilter(desktopIndependentWindow:), and configurable JPEG compression
  • CompanionPanelView.swift new "SCREENSHOT" settings section with two toggles and a slider
  • ScreenshotSettingsTests.swift 17 unit tests covering defaults, persistence, struct fields, and quality boundaries

Test plan

  • Verify the three new controls appear in the menu bar panel after onboarding
  • Toggle "Primary screen only" on a multi-monitor setup — only cursor screen should be captured
  • Toggle "Active window only" — screenshot should contain only the frontmost app window
  • Adjust JPEG quality slider — verify the printed payload size in console changes accordingly
  • Verify all settings survive app restart
  • Run unit tests (Cmd+U)

Expose three user-configurable settings in the menu bar panel:
- Primary screen only toggle (skips secondary monitors)
- Active window only toggle (captures frontmost window instead of full screen)
- JPEG quality slider (0.3–1.0, adjusts upload payload size)

Settings persist via UserDefaults and are wired through the capture
utility to both the voice response and onboarding demo pipelines.
Includes unit tests for defaults, persistence, and boundary values.
@qodo-ai-reviewer
Copy link
Copy Markdown

Hi, screenshotJPEGQuality is persisted and passed to .compressionFactor without clamping, so out-of-range values in UserDefaults or programmatic calls can cause JPEG encoding to fail and lead to a “Failed to capture any screen” error.

Severity: remediation recommended | Category: reliability

How to fix: Clamp quality to 0..1

Agent prompt to fix - you can give this to your LLM of choice:

Issue description

JPEG compression quality is not validated before being passed to the encoder.

Issue Context

UI uses a slider (0.3–1.0), but persisted defaults or programmatic calls can still set invalid values.

Fix Focus Areas

  • leanring-buddy/CompanionManager.swift[157-164]
  • leanring-buddy/CompanionScreenCaptureUtility.swift[143-145]

Implementation notes

  • Clamp in setScreenshotJPEGQuality(_:) (and/or when reading from UserDefaults) to 0.0...1.0.
  • Consider additionally clamping jpegCompressionQuality inside captureAllScreensAsJPEG as a last line of defense.
  • Optional: log when clamping occurs so it’s diagnosable.

Found by Qodo code review

@qodo-ai-reviewer
Copy link
Copy Markdown

Hi, The setting named/labelled “Primary screen only” actually captures the screen containing the cursor, not the system primary display. This mismatch can lead to incorrect future usage and user confusion about what will be captured.

Severity: informational | Category: maintainability

How to fix: Align name with behavior

Agent prompt to fix - you can give this to your LLM of choice:

Issue description

The “primary screen” naming implies the system primary display, but the implementation captures the cursor’s screen.

Issue Context

This can confuse users and future maintainers.

Fix Focus Areas

  • leanring-buddy/CompanionManager.swift[142-152]
  • leanring-buddy/CompanionPanelView.swift[670-689]
  • leanring-buddy/CompanionScreenCaptureUtility.swift[46-102]

Suggested approach

  • Rename UI label to “Cursor screen only” (or implement true primary-display capture using NSScreen.main/displayID if that’s the intended meaning).
  • Consider renaming the UserDefaults key to match semantics if backward compatibility allows (or migrate old key).

Found by Qodo code review

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.

2 participants