-
Notifications
You must be signed in to change notification settings - Fork 161
Add Web Lock APIs #762
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
Merged
Merged
Add Web Lock APIs #762
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
@js.native | ||
sealed trait LockMode extends js.Any | ||
|
||
object LockMode { | ||
val exclusive: LockMode = "exclusive".asInstanceOf[LockMode] | ||
|
||
val shared: LockMode = "shared".asInstanceOf[LockMode] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
opaque type LockMode <: String = String | ||
|
||
object LockMode { | ||
val exclusive: LockMode = "exclusive" | ||
|
||
val shared: LockMode = "shared" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSGlobal | ||
|
||
/** The [[Lock]] interface of the Web Locks API provides the name and mode of a lock. This may be a newly requested lock | ||
* that is received in the callback to [[LockManager.request(name:String,callback:* LockManager.request]], or a record | ||
* of an active or queued lock returned by [[LockManager.query]]. | ||
*/ | ||
@js.native | ||
@JSGlobal | ||
class Lock private[this] extends js.Object { | ||
|
||
/** The access mode passed to [[LockManager.request(name:String,callback:* LockManager.request]] when the lock was | ||
* requested. | ||
*/ | ||
def mode: LockMode = js.native | ||
|
||
/** The name passed to [[LockManager.request(name:String,callback:* LockManager.request]] when the lock was requested. | ||
*/ | ||
def name: String = js.native | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
@js.native | ||
trait LockInfo extends js.Object { | ||
|
||
def name: String = js.native | ||
|
||
def mode: LockMode = js.native | ||
|
||
def clientId: String = js.native | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSGlobal | ||
|
||
/** The [[LockManager]] interface of the Web Locks API provides methods for requesting a new [[Lock]] object and | ||
* querying for an existing [[Lock]] object. To get an instance of [[LockManager]], call `navigator.locks`. | ||
*/ | ||
@js.native | ||
@JSGlobal | ||
class LockManager private[this] extends js.Object { | ||
|
||
/** Resolves with an object containing information about held and pending locks. */ | ||
def query(): js.Promise[LockManagerSnapshot] = js.native | ||
|
||
/** Requests a [[Lock]] object with parameters specifying its name and characteristics. The requested [[Lock]] is | ||
* passed to a callback, while the function itself returns a `Promise` that resolves with `undefined`. | ||
*/ | ||
def request(name: String, callback: js.Function1[Lock, js.Promise[Unit]]): js.Promise[Unit] = js.native | ||
|
||
def request(name: String, options: LockOptions, | ||
callback: js.Function1[Lock, js.Promise[Unit]]): js.Promise[Unit] = js.native | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
dom/src/main/scala/org/scalajs/dom/LockManagerSnapshot.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
/** an object containing a snapshot of the [[LockManager]] state */ | ||
@js.native | ||
trait LockManagerSnapshot extends js.Object { | ||
|
||
/** An array of [[Lock]] objects for held locks. */ | ||
def held: js.Array[LockInfo] = js.native | ||
|
||
/** An array of [[Lock]] objects for pending lock requests. */ | ||
def pending: js.Array[LockInfo] = js.native | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
/** An object describing characteristics of the lock you want to create. */ | ||
trait LockOptions extends js.Object { | ||
|
||
/** Either `"exclusive"` or `"shared"`. The default value is `"exclusive"`. */ | ||
var mode: js.UndefOr[LockMode] = js.undefined | ||
|
||
/** If `true`, the lock request will only be granted if it is not already held. If it cannot be granted, the callback | ||
* will be invoked with `null` instead of a [[Lock]] instance. The default value is `false`. | ||
*/ | ||
var ifAvailable: js.UndefOr[Boolean] = js.undefined | ||
|
||
/** If `true`, then any held locks with the same name will be released, and the request will be granted, preempting | ||
* any queued requests for it. The default value is `false`. | ||
*/ | ||
var steal: js.UndefOr[Boolean] = js.undefined | ||
|
||
/** An [[AbortSignal]] (the `signal` property of an [[AbortController]]); if specified and the [[AbortController]] is | ||
* aborted, the lock request is dropped if it was not already granted. | ||
*/ | ||
var signal: js.UndefOr[AbortSignal] = js.undefined | ||
|
||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
@js.native | ||
trait NavigatorLocks extends js.Object { | ||
|
||
/** A [[LockManager]] object which provides methods for requesting a new [[Lock]] object and querying for an existing | ||
* [[Lock]] object. | ||
*/ | ||
def locks: LockManager = js.native | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.