feat: keep mobile screen awake while using trackpad (#78)#365
feat: keep mobile screen awake while using trackpad (#78)#365mrittickdeb wants to merge 2 commits into
Conversation
|
Warning Review limit reached
Next review available in: 49 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe trackpad page now requests a screen wake lock while visible, re-acquires it after visibility changes, and releases it with event-listener cleanup when unmounted. Unsupported APIs and acquisition failures are handled with guards and logging. ChangesTrackpad Wake Lock
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant TrackpadPage
participant BrowserVisibility
participant ScreenWakeLock
TrackpadPage->>ScreenWakeLock: request("screen") when visible
BrowserVisibility->>TrackpadPage: visibilitychange
TrackpadPage->>ScreenWakeLock: re-request lock when visible
TrackpadPage->>ScreenWakeLock: release lock during cleanup
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR adds Screen Wake Lock support to the /trackpad route so a mobile device used as a remote trackpad doesn’t dim/sleep while the trackpad view is active.
Changes:
- Acquire a Screen Wake Lock when the trackpad page mounts.
- Re-acquire the wake lock when the tab becomes visible again.
- Release the wake lock when the trackpad page unmounts.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // Keep the mobile screen awake while using the trackpad | ||
| useEffect(() => { | ||
| let wakeLock: WakeLockSentinel | null = null |
| const requestWakeLock = async () => { | ||
| if (typeof window !== "undefined" && "wakeLock" in navigator) { | ||
| try { | ||
| wakeLock = await navigator.wakeLock.request("screen") | ||
| console.log("[WakeLock] Screen Wake Lock acquired") | ||
| } catch (err) { | ||
| console.warn("[WakeLock] Failed to acquire screen wake lock:", err) | ||
| } | ||
| } | ||
| } |
| return () => { | ||
| document.removeEventListener("visibilitychange", handleVisibilityChange) | ||
| if (wakeLock) { | ||
| wakeLock |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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.
Inline comments:
In `@src/routes/trackpad.tsx`:
- Line 75: Remove the debug console.log statements in the Wake Lock handling
flow, including the messages at the acquisition and release points. Do not
replace them with additional production logging; preserve the existing wake-lock
behavior.
- Around line 68-106: Update the useEffect wake-lock lifecycle around
requestWakeLock and handleVisibilityChange to track cancellation/unmount state
and prevent stale async requests from assigning unreleased sentinels. Serialize
or otherwise guard in-flight requests, release any existing wakeLock before
replacing it, and ensure a sentinel resolved after cleanup is immediately
released; retain listener removal and normal release behavior during unmount.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: f4cbe8fc-9aaa-4ec9-bec1-e5fd804aa62d
📒 Files selected for processing (1)
src/routes/trackpad.tsx
Addressed Issues:
Fixes #78
Description
This PR implements the browser's native Screen Wake Lock API in the trackpad component. When using the mobile device as a remote trackpad, the screen will no longer dim, sleep, or auto-lock.
Key additions:
WakeLockSentineltypes (fully passes the Biome linter and TypeScript compiler checks).Screenshots/Recordings:
(Not applicable as this is a non-visual background API change)
Functional Verification
Screen Mirror
Authentication
Basic Gestures
Modes & Settings
Advanced Input
Any other gesture or input behavior introduced:
Additional Notes:
The Screen Wake Lock API is supported on Chrome, Edge, Opera, and Safari (iOS 13.7+). A warning fallback (
console.warn) is included for unsupported browser contexts to avoid app failures.Checklist
Summary by CodeRabbit