vandie / mikevdv-dot-dev-comments

The official comment repo for https://mikevdv.dev
https://mikevdv.dev
0 stars 0 forks source link

blog/2022-06-23-stop-the-screen-going-to-sleep-with-javascript #2

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Stop The Screen Going To Sleep With JavaScript | Michael Walter Van Der Velden

We've all been there. Cooking a complex recipe where each step takes a good couple of minutes. Our hands covered in some type of sauce made of who knows how many ingredients. We go to check the next step on our phone only to see that it's gone to sleep due to inactivity. We know that even if we quickly wash our hands, there is inevitably going to be some level of greasy trail left on our phone screen as we are forced to unlock it...

https://mikevdv.dev/blog/2022-06-23-stop-the-screen-going-to-sleep-with-javascript

WORMSS commented 2 years ago

I am presuming this allows multiple locks to be generated? Since the unlock is on the request object? So may be bad if someone calls wakeLoclState() twice. Unless it returns the same object every time request is called? I will test next time I am on my work machine

vandie commented 2 years ago

I am presuming this allows multiple locks to be generated? Since the unlock is on the request object? So may be bad if someone calls wakeLoclState() twice. Unless it returns the same object every time request is called? I will test next time I am on my work machine

navigator.wakeLock.request() only creates a new wake lock request, and can fail for a number of reasons (eg. the tab is not active). further requests will override the old request. While for efficiency sake, you don't want to make a bunch of calls to lockWakeState. It will only ever create a single wake lock.

MykalMachon commented 2 years ago

Thanks for posting this! Your example is well thought out 🙂 Excited to see support in Safari and Firefox in the future; I've never seen the caniuse.com widget embedded in a blog before, was nice to have it inline for reference.

vandie commented 2 years ago

Thanks for posting this! Your example is well thought out 🙂 Excited to see support in Safari and Firefox in the future; I've never seen the caniuse.com widget embedded in a blog before, was nice to have it inline for reference.

The can I use embed isn't actually official. You can find it here. Sorry it took me so long to reply, I honestly thought I already had...

I'm so glad you enjoyed the article.

geoshak commented 2 weeks ago

Thanks a lot for the article!! Really straightforward.