Skip to content

fix(settings): clamp focusMode dimOpacity to safe range#127

Closed
leno23 wants to merge 1 commit into
SamXop123:mainfrom
leno23:fix/focus-mode-dim-opacity-clamp-122
Closed

fix(settings): clamp focusMode dimOpacity to safe range#127
leno23 wants to merge 1 commit into
SamXop123:mainfrom
leno23:fix/focus-mode-dim-opacity-clamp-122

Conversation

@leno23
Copy link
Copy Markdown
Contributor

@leno23 leno23 commented May 30, 2026

Summary

  • Clamps focusMode.dimOpacity to 0.050.9 during settings sanitization
  • Prevents fully transparent or out-of-range values from making focus mode invisible

Fixes #122

Test plan

  • Set focusMode.dimOpacity to 0 in settings and reload — value should clamp to safe minimum
  • Enable focus mode and confirm the overlay remains visible when active

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes
    • Improved focus mode opacity validation. The dimOpacity setting now accepts values strictly between 0.05 and 0.9 (inclusive). Previously, any value between 0 and 1 was allowed. Settings outside the new valid range will automatically reset to the default value, ensuring consistent behavior.

Review Change Stack

Prevent fully transparent or out-of-range overlay opacity values from
making focus mode invisible or undefined.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

@leno23 is attempting to deploy a commit to the Dot_NotSam's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

📝 Walkthrough

Walkthrough

The PR tightens validation for the focus mode overlay opacity setting. sanitizeFocusMode now restricts focusMode.dimOpacity to the safe range of 0.05–0.9 (inclusive), falling back to the default value for out-of-range inputs, preventing the overlay from becoming invisible or behaving unexpectedly.

Changes

Focus Mode Overlay Opacity Bounds

Layer / File(s) Summary
Tighten dimOpacity validation range
settingsStore.js
sanitizeFocusMode enforces bounds on focusMode.dimOpacity: values must fall within 0.05–0.9 (inclusive); out-of-range or non-numeric values now fallback to the default dim opacity.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related PRs

  • SamXop123/Paraline#97: This PR tightens the same sanitizeFocusMode validation for focusMode.dimOpacity, directly addressing the focus mode settings behavior.

Suggested labels

quality:clean, type:bug, level:beginner

Poem

🐰 The opacity bounds now hold tight,
No zero makes the overlay vanish from sight,
Between 0.05 and 0.9 we stay,
So focus mode dims just the right way!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: clamping focusMode.dimOpacity to a safe range during settings sanitization.
Linked Issues check ✅ Passed The PR addresses all coding requirements from issue #122: clamping dimOpacity to 0.05–0.9 range in the sanitizer to prevent invisible or undefined overlay behavior.
Out of Scope Changes check ✅ Passed The PR makes only the necessary changes to settingsStore.js to implement range clamping; no unrelated or out-of-scope modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
settingsStore.js (1)

507-511: ⚡ Quick win

Consider using Math.max/min for true clamping behavior.

The PR title states "clamp focusMode dimOpacity" but the current implementation rejects out-of-range values and falls back to the default (0.1), rather than clamping to the nearest boundary. Using Math.max and Math.min would provide true clamping behavior (e.g., 0 → 0.05, 1.0 → 0.9) and be consistent with the checkIntervalMinutes validation pattern at line 253.

♻️ Proposed refactor to use true clamping
-  const dimOpacity = typeof input.dimOpacity === "number"
-      && input.dimOpacity >= 0.05
-      && input.dimOpacity <= 0.9
-    ? input.dimOpacity
+  const dimOpacity = typeof input.dimOpacity === "number"
+    ? Math.max(0.05, Math.min(0.9, input.dimOpacity))
     : DEFAULT_SETTINGS.focusMode.dimOpacity;
🤖 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 `@settingsStore.js` around lines 507 - 511, The current validation for
dimOpacity (variable dimOpacity / input.dimOpacity) rejects out-of-range numbers
and falls back to DEFAULT_SETTINGS.focusMode.dimOpacity instead of clamping;
change the logic to coerce numeric input into the allowed range using Math.max
and Math.min (e.g., clamp via Math.min(upper, Math.max(lower,
input.dimOpacity))) while still falling back to the default only when
input.dimOpacity is not a number, so dimOpacity becomes the clamped numeric
value between 0.05 and 0.9.
🤖 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 `@settingsStore.js`:
- Around line 507-511: The current validation for dimOpacity (variable
dimOpacity / input.dimOpacity) rejects out-of-range numbers and falls back to
DEFAULT_SETTINGS.focusMode.dimOpacity instead of clamping; change the logic to
coerce numeric input into the allowed range using Math.max and Math.min (e.g.,
clamp via Math.min(upper, Math.max(lower, input.dimOpacity))) while still
falling back to the default only when input.dimOpacity is not a number, so
dimOpacity becomes the clamped numeric value between 0.05 and 0.9.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4f2d40b2-ca72-4b24-9c31-741c748db33f

📥 Commits

Reviewing files that changed from the base of the PR and between 7e6a9e1 and 3ae2eee.

📒 Files selected for processing (1)
  • settingsStore.js

@SamXop123
Copy link
Copy Markdown
Owner

Allowing a dimOpacity of 0 (completely transparent) and 1 (completely opaque) are both valid and intended design choices for Focus Mode. Constraining the range to 0.05–0.9 removes this functionality without providing any security or performance benefit. Additionally, Issue #122 was already closed as invalid since safe [0, 1] bounds checking is already handled in the codebase.
so, we are closing this PR

@SamXop123 SamXop123 closed this May 30, 2026
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.

Bug: focusMode.dimOpacity is applied without bounds clamping, allowing the overlay to be set fully transparent (0.0) and become invisible to the user

2 participants