Skip to content

Commit cbe61e0

Browse files
authored
Merge pull request #762 from scala-js/feature/lock-manager
Add Web Lock APIs
2 parents 21d6bad + a8f46df commit cbe61e0

File tree

11 files changed

+176
-1
lines changed

11 files changed

+176
-1
lines changed

Diff for: api-reports/2_12.txt

+19
Original file line numberDiff line numberDiff line change
@@ -15716,6 +15716,23 @@ Location[JT] var protocol: String
1571615716
Location[JT] def reload(): Unit
1571715717
Location[JT] def replace(url: String): Unit
1571815718
Location[JT] var search: String
15719+
Lock[JC] def mode: LockMode
15720+
Lock[JC] def name: String
15721+
LockInfo[JT] def clientId: String
15722+
LockInfo[JT] def mode: LockMode
15723+
LockInfo[JT] def name: String
15724+
LockManager[JC] def query(): js.Promise[LockManagerSnapshot]
15725+
LockManager[JC] def request(name: String, callback: js.Function1[Lock, js.Promise[Unit]]): js.Promise[Unit]
15726+
LockManager[JC] def request(name: String, options: LockOptions, callback: js.Function1[Lock, js.Promise[Unit]]): js.Promise[Unit]
15727+
LockManagerSnapshot[JT] def held: js.Array[LockInfo]
15728+
LockManagerSnapshot[JT] def pending: js.Array[LockInfo]
15729+
LockMode[JT]
15730+
LockMode[SO] val exclusive: LockMode
15731+
LockMode[SO] val shared: LockMode
15732+
LockOptions[JT] var ifAvailable: js.UndefOr[Boolean]
15733+
LockOptions[JT] var mode: js.UndefOr[LockMode]
15734+
LockOptions[JT] var signal: js.UndefOr[AbortSignal]
15735+
LockOptions[JT] var steal: js.UndefOr[Boolean]
1571915736
MIMEType[JT]
1572015737
MIMEType[SO] val `application/xhtml+xml` = "application/xhtml+xml".asInstanceOf[MIMEType]
1572115738
MIMEType[SO] val `application/xml` = "application/xml".asInstanceOf[MIMEType]
@@ -16084,6 +16101,7 @@ Navigator[JC] def geolocation: Geolocation
1608416101
Navigator[JC] def getGamepads(): js.Array[Gamepad]
1608516102
Navigator[JC] def language: String
1608616103
Navigator[JC] def languages: js.Array[String]
16104+
Navigator[JC] def locks: LockManager
1608716105
Navigator[JC] def mediaDevices: MediaDevices
1608816106
Navigator[JC] def onLine: Boolean
1608916107
Navigator[JC] val permissions: Permissions
@@ -16102,6 +16120,7 @@ NavigatorID[JT] def platform: String
1610216120
NavigatorID[JT] def userAgent: String
1610316121
NavigatorLanguage[JT] def language: String
1610416122
NavigatorLanguage[JT] def languages: js.Array[String]
16123+
NavigatorLocks[JT] def locks: LockManager
1610516124
NavigatorOnLine[JT] def onLine: Boolean
1610616125
NavigatorStorageUtils[JT]
1610716126
NavigatorVibration[JT] def vibrate(duration: Double): Boolean

Diff for: api-reports/2_13.txt

+19
Original file line numberDiff line numberDiff line change
@@ -15716,6 +15716,23 @@ Location[JT] var protocol: String
1571615716
Location[JT] def reload(): Unit
1571715717
Location[JT] def replace(url: String): Unit
1571815718
Location[JT] var search: String
15719+
Lock[JC] def mode: LockMode
15720+
Lock[JC] def name: String
15721+
LockInfo[JT] def clientId: String
15722+
LockInfo[JT] def mode: LockMode
15723+
LockInfo[JT] def name: String
15724+
LockManager[JC] def query(): js.Promise[LockManagerSnapshot]
15725+
LockManager[JC] def request(name: String, callback: js.Function1[Lock, js.Promise[Unit]]): js.Promise[Unit]
15726+
LockManager[JC] def request(name: String, options: LockOptions, callback: js.Function1[Lock, js.Promise[Unit]]): js.Promise[Unit]
15727+
LockManagerSnapshot[JT] def held: js.Array[LockInfo]
15728+
LockManagerSnapshot[JT] def pending: js.Array[LockInfo]
15729+
LockMode[JT]
15730+
LockMode[SO] val exclusive: LockMode
15731+
LockMode[SO] val shared: LockMode
15732+
LockOptions[JT] var ifAvailable: js.UndefOr[Boolean]
15733+
LockOptions[JT] var mode: js.UndefOr[LockMode]
15734+
LockOptions[JT] var signal: js.UndefOr[AbortSignal]
15735+
LockOptions[JT] var steal: js.UndefOr[Boolean]
1571915736
MIMEType[JT]
1572015737
MIMEType[SO] val `application/xhtml+xml` = "application/xhtml+xml".asInstanceOf[MIMEType]
1572115738
MIMEType[SO] val `application/xml` = "application/xml".asInstanceOf[MIMEType]
@@ -16084,6 +16101,7 @@ Navigator[JC] def geolocation: Geolocation
1608416101
Navigator[JC] def getGamepads(): js.Array[Gamepad]
1608516102
Navigator[JC] def language: String
1608616103
Navigator[JC] def languages: js.Array[String]
16104+
Navigator[JC] def locks: LockManager
1608716105
Navigator[JC] def mediaDevices: MediaDevices
1608816106
Navigator[JC] def onLine: Boolean
1608916107
Navigator[JC] val permissions: Permissions
@@ -16102,6 +16120,7 @@ NavigatorID[JT] def platform: String
1610216120
NavigatorID[JT] def userAgent: String
1610316121
NavigatorLanguage[JT] def language: String
1610416122
NavigatorLanguage[JT] def languages: js.Array[String]
16123+
NavigatorLocks[JT] def locks: LockManager
1610516124
NavigatorOnLine[JT] def onLine: Boolean
1610616125
NavigatorStorageUtils[JT]
1610716126
NavigatorVibration[JT] def vibrate(duration: Double): Boolean

Diff for: dom/src/main/scala-2/org/scalajs/dom/LockMode.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
@js.native
6+
sealed trait LockMode extends js.Any
7+
8+
object LockMode {
9+
val exclusive: LockMode = "exclusive".asInstanceOf[LockMode]
10+
11+
val shared: LockMode = "shared".asInstanceOf[LockMode]
12+
}

Diff for: dom/src/main/scala-3/org/scalajs/dom/LockMode.scala

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
opaque type LockMode <: String = String
6+
7+
object LockMode {
8+
val exclusive: LockMode = "exclusive"
9+
10+
val shared: LockMode = "shared"
11+
}

Diff for: dom/src/main/scala/org/scalajs/dom/Lock.scala

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSGlobal
5+
6+
/** The [[Lock]] interface of the Web Locks API provides the name and mode of a lock. This may be a newly requested lock
7+
* that is received in the callback to [[LockManager.request(name:String,callback:* LockManager.request]], or a record
8+
* of an active or queued lock returned by [[LockManager.query]].
9+
*/
10+
@js.native
11+
@JSGlobal
12+
class Lock private[this] extends js.Object {
13+
14+
/** The access mode passed to [[LockManager.request(name:String,callback:* LockManager.request]] when the lock was
15+
* requested.
16+
*/
17+
def mode: LockMode = js.native
18+
19+
/** The name passed to [[LockManager.request(name:String,callback:* LockManager.request]] when the lock was requested.
20+
*/
21+
def name: String = js.native
22+
23+
}

Diff for: dom/src/main/scala/org/scalajs/dom/LockInfo.scala

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
@js.native
6+
trait LockInfo extends js.Object {
7+
8+
def name: String = js.native
9+
10+
def mode: LockMode = js.native
11+
12+
def clientId: String = js.native
13+
14+
}

Diff for: dom/src/main/scala/org/scalajs/dom/LockManager.scala

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSGlobal
5+
6+
/** The [[LockManager]] interface of the Web Locks API provides methods for requesting a new [[Lock]] object and
7+
* querying for an existing [[Lock]] object. To get an instance of [[LockManager]], call `navigator.locks`.
8+
*/
9+
@js.native
10+
@JSGlobal
11+
class LockManager private[this] extends js.Object {
12+
13+
/** Resolves with an object containing information about held and pending locks. */
14+
def query(): js.Promise[LockManagerSnapshot] = js.native
15+
16+
/** Requests a [[Lock]] object with parameters specifying its name and characteristics. The requested [[Lock]] is
17+
* passed to a callback, while the function itself returns a `Promise` that resolves with `undefined`.
18+
*/
19+
def request(name: String, callback: js.Function1[Lock, js.Promise[Unit]]): js.Promise[Unit] = js.native
20+
21+
def request(name: String, options: LockOptions,
22+
callback: js.Function1[Lock, js.Promise[Unit]]): js.Promise[Unit] = js.native
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/** an object containing a snapshot of the [[LockManager]] state */
6+
@js.native
7+
trait LockManagerSnapshot extends js.Object {
8+
9+
/** An array of [[Lock]] objects for held locks. */
10+
def held: js.Array[LockInfo] = js.native
11+
12+
/** An array of [[Lock]] objects for pending lock requests. */
13+
def pending: js.Array[LockInfo] = js.native
14+
15+
}

Diff for: dom/src/main/scala/org/scalajs/dom/LockOptions.scala

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/** An object describing characteristics of the lock you want to create. */
6+
trait LockOptions extends js.Object {
7+
8+
/** Either `"exclusive"` or `"shared"`. The default value is `"exclusive"`. */
9+
var mode: js.UndefOr[LockMode] = js.undefined
10+
11+
/** If `true`, the lock request will only be granted if it is not already held. If it cannot be granted, the callback
12+
* will be invoked with `null` instead of a [[Lock]] instance. The default value is `false`.
13+
*/
14+
var ifAvailable: js.UndefOr[Boolean] = js.undefined
15+
16+
/** If `true`, then any held locks with the same name will be released, and the request will be granted, preempting
17+
* any queued requests for it. The default value is `false`.
18+
*/
19+
var steal: js.UndefOr[Boolean] = js.undefined
20+
21+
/** An [[AbortSignal]] (the `signal` property of an [[AbortController]]); if specified and the [[AbortController]] is
22+
* aborted, the lock request is dropped if it was not already granted.
23+
*/
24+
var signal: js.UndefOr[AbortSignal] = js.undefined
25+
26+
}

Diff for: dom/src/main/scala/org/scalajs/dom/Navigator.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import scala.scalajs.js.annotation._
1818
@JSGlobal
1919
class Navigator
2020
extends NavigatorID with NavigatorOnLine with NavigatorContentUtils with NavigatorGeolocation
21-
with NavigatorStorageUtils with NavigatorLanguage with NavigatorVibration {
21+
with NavigatorStorageUtils with NavigatorLanguage with NavigatorLocks with NavigatorVibration {
2222

2323
/** The Clipboard API adds to the Navigator interface the read-only clipboard property, which returns the Clipboard
2424
* object used to read and write the clipboard's contents. The Clipboard API can be used to implement cut, copy, and
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
@js.native
6+
trait NavigatorLocks extends js.Object {
7+
8+
/** A [[LockManager]] object which provides methods for requesting a new [[Lock]] object and querying for an existing
9+
* [[Lock]] object.
10+
*/
11+
def locks: LockManager = js.native
12+
}

0 commit comments

Comments
 (0)