Enable lint rules for Promise handling to discourage misuse of them.

Squashed all of Hugh's commits into one.
This commit is contained in:
Hugh Nimmo-Smith
2024-07-10 16:20:59 +01:00
committed by Timo
parent c2cc0937c1
commit 480a995be1
31 changed files with 332 additions and 198 deletions

View File

@@ -28,19 +28,22 @@ export function useWakeLock(): void {
// The lock is automatically released whenever the window goes invisible,
// so we need to reacquire it on visibility changes
const onVisibilityChange = async (): Promise<void> => {
const onVisibilityChange = (): void => {
if (document.visibilityState === "visible") {
try {
lock = await navigator.wakeLock.request("screen");
// Handle the edge case where this component unmounts before the
// promise resolves
if (!mounted)
lock
.release()
.catch((e) => logger.warn("Can't release wake lock", e));
} catch (e) {
logger.warn("Can't acquire wake lock", e);
}
navigator.wakeLock
.request("screen")
.then((newLock) => {
lock = newLock;
// Handle the edge case where this component unmounts before the
// promise resolves
if (!mounted)
lock
.release()
.catch((e) => logger.warn("Can't release wake lock", e));
})
.catch((e) => {
logger.warn("Can't acquire wake lock", e);
});
}
};