-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocks.js
33 lines (30 loc) · 782 Bytes
/
locks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { LockManager, actuallySupported, nativeSupport } from './assets/LockManager.js';
import { errorToEvent } from './assets/error.js';
let polyfilled = false;
const polyfilledPromise = new Promise(async resolve => {
if (nativeSupport) {
if (await actuallySupported) {
resolve(false);
} else {
try {
navigator.locks.request = LockManager.request;
navigator.locks.query = LockManager.query;
polyfilled = true;
resolve(true);
} catch(err) {
globalThis.dispatchEvent(errorToEvent(err));
resolve(false);
}
}
} else {
try {
navigator.locks = LockManager;
polyfilled = true;
resolve(true);
} catch(err) {
globalThis.dispatchEvent(errorToEvent(err));
resolve(false);
}
}
});
export { polyfilled, polyfilledPromise };