Enable lint rules for Promise handling to discourage misuse of them. (#2607)

* Enable lint rules for Promise handling to discourage misuse of them.
Squashed all of Hugh's commits into one.

---------

Co-authored-by: Hugh Nimmo-Smith <hughns@element.io>
This commit is contained in:
Timo
2024-09-10 09:49:35 +02:00
committed by GitHub
parent c30c8ac7d6
commit c3edd3e25e
35 changed files with 369 additions and 241 deletions

View File

@@ -19,19 +19,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));
},
(e) => {
logger.warn("Can't acquire wake lock", e);
},
);
}
};