Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example usage of onrelease event. #250

Closed
scheib opened this issue Feb 3, 2020 · 7 comments · Fixed by #251
Closed

Add example usage of onrelease event. #250

scheib opened this issue Feb 3, 2020 · 7 comments · Fixed by #251

Comments

@scheib
Copy link

scheib commented Feb 3, 2020

The WakeLockSentinel onrelease event is "used to notify scripts that a given WakeLockSentinel object's handle has been released, either due to the release() method being called or because the wake lock was released by the user agent."

For spec readability it would help to have usage examples.

@rakuco
Copy link
Member

rakuco commented Feb 4, 2020

Isn't that covered by example 2, which has

navigator.wakeLock.request("screen").then(lock => {
  checkbox.checked = true;

  const listener = (ev) => {
    checkbox.checked = false;
    ev.target.removeEventListener('release', listener);
  };

  lock.addEventListener('release', listener);
});

?

@marcoscaceres
Copy link
Member

We should await that and use more spec terms in the example.

@marcoscaceres
Copy link
Member

(@rakuco you are correct is what I mean - but could be clearer)

@rakuco
Copy link
Member

rakuco commented Feb 4, 2020

How about this:

const sentinel = await navigator.wakeLock.request('screen');
checkbox.checked = true;

const listener = (ev) => {
  checkbox.checked = false;
  ev.target.remoteEventListener('release', listener);
};

sentinel.onrelease = listener;

(not sure whether it's clearer to use onrelease or addEventListener for symmetry)

@marcoscaceres
Copy link
Member

I like it :) @scheib, wdyt? Would that be clearer? We should also make sure we have a link to the relevant example.

@scheib
Copy link
Author

scheib commented Feb 4, 2020

First, I apologize having overlooked that there was an example. I looked adjacent to the release event definition, and searched the page for 'onrelease', and didn't take the time to find example 2.

I do like the rework. Using 'onrelease' will help others who make my mistake. As would having the example linked or moved to be in context.

Also, might keep it even simpler by directly assigning the function and not de-registering it. Focusing just on what's needed to demonstrate the spec:

const sentinel = await navigator.wakeLock.request('screen');
checkbox.checked = true;

sentinel.onrelease = () => checkbox.checked = false;

Are there any other things we expect apps to do when lock is lost? Attempt to reacquire? That's blocked because user activation is needed. Any other possible action other than just notifying the user in UI that lock is lost?

rakuco pushed a commit to rakuco/wake-lock that referenced this issue Feb 5, 2020
Simplify it a little but, use `await` instead of `.then()`. Also replace
`addEventListener()` with a direct assignment of the `onrelease` attribute
to make the example easier to find.

Fixes w3c#250.
@rakuco
Copy link
Member

rakuco commented Feb 5, 2020

#251 updates the example and hopefully makes it easier to find and understand.

Are there any other things we expect apps to do when lock is lost? Attempt to reacquire? That's blocked because user activation is needed. Any other possible action other than just notifying the user in UI that lock is lost?

Note that user activation is needed only when a UA sets the permission to "prompt". The Chromium implementation, for example, always grants screen wake locks regardless of whether the request was triggered by user activation or not.

rakuco pushed a commit to rakuco/wake-lock that referenced this issue Feb 5, 2020
Simplify it a little but, use `await` instead of `.then()`. Also replace
`addEventListener()` with a direct assignment of the `onrelease` attribute
to make the example easier to find.

Fixes w3c#250.
rakuco pushed a commit to rakuco/wake-lock that referenced this issue Feb 7, 2020
Simplify it a little but, use `await` instead of `.then()`. Also replace
`addEventListener()` with a direct assignment of the `onrelease` attribute
to make the example easier to find.

Fixes w3c#250.
rakuco pushed a commit that referenced this issue Feb 7, 2020
Simplify it a little but, use `await` instead of `.then()`. Also replace
`addEventListener()` with a direct assignment of the `onrelease` attribute
to make the example easier to find.

Fixes #250.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants