Skip to content

Commit

Permalink
Merge pull request #2435 from element-hq/hughns/visibilitychange
Browse files Browse the repository at this point in the history
Use correct DOM event name for visibility changes in useWakeLock
  • Loading branch information
robintown authored Jun 20, 2024
2 parents 8666ffe + ba64778 commit f9ef037
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/useWakeLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -44,16 +44,16 @@ export function useWakeLock(): void {
}
};

onVisiblityChange();
document.addEventListener("visiblitychange", onVisiblityChange);
onVisibilityChange();
document.addEventListener("visibilitychange", onVisibilityChange);

return (): void => {
mounted = false;
if (lock !== null)
lock
.release()
.catch((e) => logger.warn("Can't release wake lock", e));
document.removeEventListener("visiblitychange", onVisiblityChange);
document.removeEventListener("visibilitychange", onVisibilityChange);
};
}
}, []);
Expand Down

0 comments on commit f9ef037

Please sign in to comment.