signal-desktop/ts/util/waitForOnline.ts
2021-04-09 00:06:46 -04:00

21 lines
497 B
TypeScript

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export function waitForOnline(
navigator: Readonly<{ onLine: boolean }>,
onlineEventTarget: EventTarget
): Promise<void> {
return new Promise(resolve => {
if (navigator.onLine) {
resolve();
return;
}
const listener = () => {
onlineEventTarget.removeEventListener('online', listener);
resolve();
};
onlineEventTarget.addEventListener('online', listener);
});
}