react-screen-wake-lock icon indicating copy to clipboard operation
react-screen-wake-lock copied to clipboard

Feature Request: Re-Aquire Wakelock When User Returns to Page

Open kmgdevelopment opened this issue 1 year ago • 6 comments

I tried to do a pull request but got hit with a bunch of errors so I'll just drop the updated files here.

There are some instances where you would want to release WakeLock without nullifying the sentinel entirely, for example a user requests WakeLock, then navigates to a different tab or application, then returns. The best UX is to automatically re-acquire the WakeLock rather than force the user to manually request it again.

I recommend adding a destroy() function that nullifies the WakeLock when manually called, and then release() simply sets the WakeLock sentinel's released parameter to true while keeping the sentinel active so it can be re-acquired if necessary.

I've also added a visibilitychange event listener on request() to listen for visibility being re-acquired and re-request WakeLock if the sentinel is active.

use-wake-lock.txt README.md

kmgdevelopment avatar Jan 22 '24 23:01 kmgdevelopment

Thank you for submitting your feature request; I'll review it shortly :)

jorisre avatar Jan 23 '24 15:01 jorisre

Hi! Thank you for your feedback, I've just taken the time to review your request. I understand your need, but this module is intended to adhere to the native functionality of the Screen WakeLock described here: https://w3c.github.io/screen-wake-lock/

You can fork this repo to add your features. Have a great day :)

jorisre avatar Jan 26 '24 19:01 jorisre

No problem, thanks for looking! The 'watch/re-aquire' technique is recommended in the MDN docs but I understand it's not explicitly native functionality.

kmgdevelopment avatar Jan 27 '24 03:01 kmgdevelopment

@jorisre just want to give another voice to this feature, so users don’t need to actively remember to activate wakelock every time they switch back and forth between apps.

thanks for putting together this highly useful lib!

loa avatar Jan 27 '24 12:01 loa

@loa, thanks for your feedback.

@kmgdevelopment, thank you for your feedback as well. I hadn't noticed the re-acquire/watch section in the MDN link.

Following your feedback and after some consideration, I believe it's feasible to implement your feature request without interfering with the native behavior of the Screen Wake Lock. I've started testing locally, and I'm envisioning an option like reacquireOnPageVisible: boolean or something similar.

What do you think?

jorisre avatar Jan 27 '24 20:01 jorisre

Making it an optional parameter is a great idea, as I could see possible use cases where someone wouldn't want that functionality by default

kmgdevelopment avatar Jan 27 '24 20:01 kmgdevelopment

did this get merged/added?

ericvrp avatar Dec 30 '24 15:12 ericvrp

:tada: This issue has been resolved in version 3.1.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Apr 01 '25 08:04 github-actions[bot]