Use correct DOM event name for visibility changes in useWakeLock
This commit is contained in:
@@ -27,8 +27,8 @@ export function useWakeLock(): void {
|
|||||||
let lock: WakeLockSentinel | null = null;
|
let lock: WakeLockSentinel | null = null;
|
||||||
|
|
||||||
// The lock is automatically released whenever the window goes invisible,
|
// The lock is automatically released whenever the window goes invisible,
|
||||||
// so we need to reacquire it on visiblity changes
|
// so we need to reacquire it on visibility changes
|
||||||
const onVisiblityChange = async (): Promise<void> => {
|
const onVisibilityChange = async (): Promise<void> => {
|
||||||
if (document.visibilityState === "visible") {
|
if (document.visibilityState === "visible") {
|
||||||
try {
|
try {
|
||||||
lock = await navigator.wakeLock.request("screen");
|
lock = await navigator.wakeLock.request("screen");
|
||||||
@@ -44,8 +44,8 @@ export function useWakeLock(): void {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onVisiblityChange();
|
onVisibilityChange();
|
||||||
document.addEventListener("visiblitychange", onVisiblityChange);
|
document.addEventListener("visibilitychange", onVisibilityChange);
|
||||||
|
|
||||||
return (): void => {
|
return (): void => {
|
||||||
mounted = false;
|
mounted = false;
|
||||||
@@ -53,7 +53,7 @@ export function useWakeLock(): void {
|
|||||||
lock
|
lock
|
||||||
.release()
|
.release()
|
||||||
.catch((e) => logger.warn("Can't release wake lock", e));
|
.catch((e) => logger.warn("Can't release wake lock", e));
|
||||||
document.removeEventListener("visiblitychange", onVisiblityChange);
|
document.removeEventListener("visibilitychange", onVisibilityChange);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
Reference in New Issue
Block a user