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 WakeLockSentinel.released. #279

Merged
merged 2 commits into from
Aug 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ <h2>
<pre class="idl">
[SecureContext, Exposed=(Window)]
interface WakeLockSentinel : EventTarget {
readonly attribute boolean released;
readonly attribute WakeLockType type;
Promise&lt;undefined&gt; release();
attribute EventHandler onrelease;
Expand All @@ -436,6 +437,12 @@ <h2>
circumstances under which a given wake lock may be released by the
<a>user agent</a>.
</aside>
<p>
The <dfn>released</dfn> attribute indicates whether the
{{WakeLockSentinel}} has been released. Its initial value is `false`.
rakuco marked this conversation as resolved.
Show resolved Hide resolved
Once a {{WakeLockSentinel}} is released, {{WakeLockSentinel/released}}
becomes `true`, and the value never changes again.
</p>
<p>
The <dfn>type</dfn> attribute corresponds to the {{WakeLockSentinel}}'s
<a>wake lock type</a>.
Expand All @@ -449,7 +456,10 @@ <h3>
following steps:
</p>
<ol class="algorithm">
<li>Let |promise:Promise| be <a>a new promise</a>.
<li>If this object's {{WakeLockSentinel/released}} attribute is
`true`, return <a>a promise resolved with</a> `undefined`.
</li>
<li>Otherwise, let |promise:Promise| be <a>a new promise</a>.
</li>
<li>Run the following steps <a>in parallel</a>:
<ol>
Expand Down Expand Up @@ -714,8 +724,14 @@ <h3>
</ol>
</li>
<li>
<a>Queue a task</a> to <a>fire an event</a> named "`release`" at
|lock|.
<a>Queue a task</a> to run the following steps:
<ol>
<li>Set |lock|.{{WakeLockSentinel/released}} to `true`.
rakuco marked this conversation as resolved.
Show resolved Hide resolved
</li>
<li>
<a>Fire an event</a> named "`release`" at |lock|.
</li>
</ol>
</li>
</ol>
</section>
Expand Down Expand Up @@ -768,8 +784,8 @@ <h2>
document.body.appendChild(checkbox);

const sentinel = await navigator.wakeLock.request("screen");
checkbox.checked = true;
sentinel.onrelease = () =&gt; checkbox.checked = false;
checkbox.checked = !sentinel.released;
sentinel.onrelease = () =&gt; checkbox.checked = !sentinel.released;
</pre>
<p>
In this example, two different wake lock requests are created and
Expand Down