-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathutils.js
More file actions
50 lines (44 loc) · 1.54 KB
/
Copy pathutils.js
File metadata and controls
50 lines (44 loc) · 1.54 KB
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
42
43
44
45
46
47
48
49
50
const utilScripts = [
{ type: 'script', url: 'third-party/html2canvas.min.js' },
{ type: 'script', url: 'third-party/purify.min.js' },
];
async function loadResource(resource) {
return new Promise((resolve) => {
let element;
if (resource.type === 'script') {
element = document.createElement('script');
element.src = resource.url;
}
// Add timeout to avoid hanging if resource never loads
const timeout = setTimeout(() => {
console.warn(`Utils resource load timeout: ${resource.url}`);
resolve();
}, 5000);
// Handle successful load
element.onload = () => {
clearTimeout(timeout);
resolve();
};
// Handle loading error
element.onerror = () => {
clearTimeout(timeout);
console.warn(`Failed to load Utils resource: ${resource.url}`);
resolve(); // Continue despite errors
};
document.body.appendChild(element);
});
}
async function initializeApp() {
// Load all resources in parallel
const loadPromises = utilScripts.map(resource => loadResource(resource));
await Promise.all(loadPromises);
// Dispatch event to notify app.js that Utils is ready
try {
window.dispatchEvent(new Event('Utils-loaded'));
} catch (error) {
console.error('Error dispatching Utils-loaded event:', error);
}
}
initializeApp().catch(error => {
console.error('Unexpected error in Utils initialization:', error);
});