mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-04 16:14:07 +00:00
25 lines
819 B
TypeScript
25 lines
819 B
TypeScript
/**
|
|
* The notifications on screen, for closing them. Electron has no answer to
|
|
* `getNotifications()`: its promise stays pending for good, so nothing may wait on
|
|
* it without a limit. A wipe that did never got to the keys.
|
|
*/
|
|
|
|
const SHOWN_WAIT_MS = 1_000;
|
|
|
|
/** Null: no answer in time, and asking again won't get one. */
|
|
export async function shownNotifications(
|
|
registration: Pick<ServiceWorkerRegistration, 'getNotifications'>,
|
|
filter?: GetNotificationOptions,
|
|
waitMs = SHOWN_WAIT_MS,
|
|
): Promise<Notification[] | null> {
|
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
try {
|
|
return await Promise.race([
|
|
registration.getNotifications(filter),
|
|
new Promise<null>((resolve) => { timer = setTimeout(() => resolve(null), waitMs); }),
|
|
]);
|
|
} finally {
|
|
clearTimeout(timer);
|
|
}
|
|
}
|