feat: prevent mobile screen timeout using Screen Wake Lock API#79
feat: prevent mobile screen timeout using Screen Wake Lock API#79Nakshatra480 wants to merge 2 commits intoAOSSIE-Org:mainfrom
Conversation
📝 WalkthroughWalkthroughRequests a Screen Wake Lock when the trackpad component mounts, stores the lock, re-requests it on document visibility changes, and releases it when the component unmounts. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/routes/trackpad.tsx`:
- Around line 35-49: The wake-lock can leak if the async request resolves after
unmount; replace the local wl/req/vc pattern with a ref and clearer names: use a
useRef<WakeLockSentinel | null> named sentinelRef and a mountedRef boolean to
track lifecycle, rename req to requestWakeLock and vc to handleVisibilityChange,
and in requestWakeLock await (navigator as any).wakeLock.request('screen') into
a local result variable then if mountedRef.current assign sentinelRef.current =
result else immediately call await result.release(); ensure cleanup sets
mountedRef.current = false, removes the visibility listener, and releases
sentinelRef.current if present; also replace the empty catch with
console.warn(error) and use the WakeLockSentinel type instead of any.
|
Hi @imxade, I’ve implemented the Screen Wake Lock API in trackpad.tsx to prevent mobile screens from dimming while using the remote. I added sentinelRef and mountedRef to handle the lock lifecycle safely, along with a visibility listener to re-acquire it automatically if the user switches back to the tab. Pls review this PR and share your feedback. |
Description
This PR addresses a common usability issue where mobile devices dim or turn off their screens during inactivity while using the remote trackpad. This is particularly inconvenient when using Rein as a media remote or for occasional inputs.
I've implemented the Screen Wake Lock API within the trackpad route to ensure the device remains awake as long as the interface is active and visible.
Changes
useEffectin trackpad.tsx to manage the wake lock lifecycle.visibilitychange).Verification Results
/trackpadroute.Fixes #78
Summary by CodeRabbit