Use correct DOM event name for visibility changes in useWakeLock

This commit is contained in:
Hugh Nimmo-Smith
2024-06-19 17:54:15 +01:00
parent a7c065f300
commit ba647780e8

View File

@@ -27,8 +27,8 @@ export function useWakeLock(): void {
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 (): Promise<void> => {
// so we need to reacquire it on visibility changes
const onVisibilityChange = async (): Promise<void> => {
if (document.visibilityState === "visible") {
try {
lock = await navigator.wakeLock.request("screen");
@@ -44,8 +44,8 @@ export function useWakeLock(): void {
}
};
onVisiblityChange();
document.addEventListener("visiblitychange", onVisiblityChange);
onVisibilityChange();
document.addEventListener("visibilitychange", onVisibilityChange);
return (): void => {
mounted = false;
@@ -53,7 +53,7 @@ export function useWakeLock(): void {
lock
.release()
.catch((e) => logger.warn("Can't release wake lock", e));
document.removeEventListener("visiblitychange", onVisiblityChange);
document.removeEventListener("visibilitychange", onVisibilityChange);
};
}
}, []);