-
Notifications
You must be signed in to change notification settings - Fork 2k
/
loadingSplash.ts
41 lines (30 loc) · 1.02 KB
/
loadingSplash.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Deferred, idleCallback } from "cfx/utils/async";
let loadingSplashShutdownRequested = true;
export const loadingSplashInactiveDeferred = new Deferred<void>();
export function shutdownLoadingSplash() {
if (!loadingSplashShutdownRequested) {
return;
}
loadingSplashShutdownRequested = false;
try {
const $loader = document.getElementById('loader');
if (!$loader) {
throw new Error('No #loader found, did it get deleted from index.html?');
}
const $loaderMask = $loader.querySelector('#loader-mask');
if (!$loaderMask) {
throw new Error('No #loader-mask found, did it get deleted from index.html?');
}
requestAnimationFrame(() => {
$loader.classList.add('hide');
$loaderMask.addEventListener('animationend', async () => {
await idleCallback(1000);
$loader.parentNode?.removeChild($loader);
});
loadingSplashInactiveDeferred.resolve();
});
} catch (e) {
loadingSplashInactiveDeferred.resolve();
console.error(e);
}
}