Skip to content

Commit 6b300f0

Browse files
authored
Update index.html
1 parent 290ed26 commit 6b300f0

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

index.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,53 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
66
<meta name="apple-mobile-web-app-capable" content="yes">
7+
<meta name="mobile-web-app-capable" content="yes">
78
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
89
<meta name="theme-color" content="#232526">
910
<meta name="format-detection" content="telephone=no">
1011
<title>Lacrosse Ball Rep Tracker</title>
1112
<link rel="preconnect" href="https://fonts.googleapis.com">
1213
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
1314
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
15+
<script>
16+
// Global variables
17+
let openCvReady = false;
18+
let domReady = false;
19+
20+
// Called when OpenCV.js is ready
21+
function onOpenCvReady() {
22+
console.log('onOpenCvReady called.');
23+
openCvReady = true;
24+
console.log('OpenCV.js is ready');
25+
// Since the loader is in the body, we can't update it here yet.
26+
// We'll handle the loader in tryInitApp.
27+
tryInitApp();
28+
}
29+
30+
// Tries to initialize the app, called when either DOM or OpenCV is ready
31+
function tryInitApp() {
32+
console.log(`tryInitApp called. domReady: ${domReady}, openCvReady: ${openCvReady}`);
33+
if (domReady && openCvReady) {
34+
console.log('Both DOM and OpenCV are ready. Calling main().');
35+
// Now that the DOM is ready, we can access the loader.
36+
updateLoaderProgress(100, 'OpenCV.js loaded successfully');
37+
main().catch(err => {
38+
console.error('Initialization failed:', err);
39+
document.getElementById('reps').textContent = 'Error: ' + err.message;
40+
}).finally(() => {
41+
// Hide loader regardless of success or failure
42+
console.log('Hiding loader.');
43+
setTimeout(() => {
44+
const loader = document.getElementById('loader');
45+
if(loader) {
46+
loader.style.opacity = '0';
47+
loader.style.visibility = 'hidden';
48+
}
49+
}, 500); // Give a moment for canvas to render
50+
});
51+
}
52+
}
53+
</script>
1454
<script async src="https://docs.opencv.org/4.8.0/opencv.js" onload="onOpenCvReady();" type="text/javascript"></script>
1555

1656
<style>
@@ -841,6 +881,7 @@ <h2>Session History</h2>
841881

842882
// Called when OpenCV.js is ready
843883
function onOpenCvReady() {
884+
console.log('onOpenCvReady called.');
844885
openCvReady = true;
845886
console.log('OpenCV.js is ready');
846887
updateLoaderProgress(100, 'OpenCV.js loaded successfully');
@@ -849,12 +890,15 @@ <h2>Session History</h2>
849890

850891
// Tries to initialize the app, called when either DOM or OpenCV is ready
851892
function tryInitApp() {
893+
console.log(`tryInitApp called. domReady: ${domReady}, openCvReady: ${openCvReady}`);
852894
if (domReady && openCvReady) {
895+
console.log('Both DOM and OpenCV are ready. Calling main().');
853896
main().catch(err => {
854897
console.error('Initialization failed:', err);
855898
document.getElementById('reps').textContent = 'Error: ' + err.message;
856899
}).finally(() => {
857900
// Hide loader regardless of success or failure
901+
console.log('Hiding loader.');
858902
setTimeout(() => {
859903
document.getElementById('loader').style.opacity = '0';
860904
document.getElementById('loader').style.visibility = 'hidden';
@@ -1529,6 +1573,7 @@ <h2>Session History</h2>
15291573

15301574
// Main initialization function
15311575
async function main() {
1576+
console.log('main() started.');
15321577
try {
15331578
// Setup camera
15341579
const video = await setupCamera();
@@ -1552,10 +1597,12 @@ <h2>Session History</h2>
15521597

15531598
// Start detection loop
15541599
window.ballDetectionActive = true;
1600+
console.log('Starting detection loop.');
15551601
detect(video, canvas);
15561602

15571603
// Setup UI event listeners
15581604
setupUI();
1605+
console.log('main() finished successfully.');
15591606
} catch (error) {
15601607
console.error('Camera setup failed:', error);
15611608

@@ -1929,6 +1976,7 @@ <h2>Session History</h2>
19291976

19301977
// Window load event
19311978
window.onload = function() {
1979+
console.log('window.onload called.');
19321980
// Check browser compatibility
19331981
const warnings = checkBrowserCompatibility();
19341982
if (warnings.length > 0) {

0 commit comments

Comments
 (0)