Add comments
This commit is contained in:
@@ -26,10 +26,14 @@ export const useWakeLock = () => {
|
|||||||
let mounted = true;
|
let mounted = true;
|
||||||
let lock: WakeLockSentinel | null = null;
|
let lock: WakeLockSentinel | null = null;
|
||||||
|
|
||||||
|
// The lock is automatically released whenever the window goes invisible,
|
||||||
|
// so we need to reacquire it on visiblity changes
|
||||||
const onVisiblityChange = async () => {
|
const onVisiblityChange = async () => {
|
||||||
if (document.visibilityState === "visible") {
|
if (document.visibilityState === "visible") {
|
||||||
try {
|
try {
|
||||||
lock = await navigator.wakeLock.request("screen");
|
lock = await navigator.wakeLock.request("screen");
|
||||||
|
// Handle the edge case where this component unmounts before the
|
||||||
|
// promise resolves
|
||||||
if (!mounted)
|
if (!mounted)
|
||||||
lock
|
lock
|
||||||
.release()
|
.release()
|
||||||
|
|||||||
Reference in New Issue
Block a user