keep phone awake on timer#305
Merged
Merged
Conversation
spring1843
commented
Jun 30, 2026
Owner
- Timer app attempts to stop phone from going to sleep so user can continue to see the timer
✅ Deploy Preview for freedevtool ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds screen wake-lock support to the Timer tool so the device is less likely to sleep while timers are running, improving usability for long-running countdowns.
Changes:
- Introduces a new
useWakeLockhook wrapping the Screen Wake Lock API. - Integrates the hook into the Timer page to request/release wake locks based on timer activity.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| client/src/pages/tools/timer.tsx | Requests/releases a wake lock based on whether any timer is running. |
| client/src/hooks/use-wake-lock.ts | New hook encapsulating wake lock request/release and visibility handling. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
+78
to
+87
| // Effect to manage the wake lock | ||
| useEffect(() => { | ||
| const hasRunningTimers = timers.some(timer => timer.isRunning); | ||
|
|
||
| if (hasRunningTimers) { | ||
| void requestWakeLock(); | ||
| } else { | ||
| void releaseWakeLock(); | ||
| } | ||
| }, [timers, isLocked, requestWakeLock, releaseWakeLock]); |
Comment on lines
+28
to
+44
| shouldHoldLock.current = true; | ||
|
|
||
| if (wakeLock.current || requestInFlight.current) { | ||
| return; | ||
| } | ||
|
|
||
| requestInFlight.current = true; | ||
|
|
||
| try { | ||
| const sentinel = await navigator.wakeLock.request("screen"); | ||
|
|
||
| // If release() was called while the request was in flight, | ||
| // release the new sentinel immediately and do nothing. | ||
| if (!shouldHoldLock.current) { | ||
| void sentinel.release(); | ||
| return; | ||
| } |
Comment on lines
+103
to
+108
| shouldHoldLock.current = false; | ||
| const sentinel = wakeLock.current; | ||
| wakeLock.current = null; | ||
| requestInFlight.current = false; | ||
| void sentinel?.release(); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.