Sa-m commited on
Commit
0724296
·
verified ·
1 Parent(s): 95c4bc2

Update assets/js/script.js

Browse files
Files changed (1) hide show
  1. assets/js/script.js +14 -14
assets/js/script.js CHANGED
@@ -442,16 +442,14 @@ class GestureDetector {
442
 
443
  detectGesture(landmarks) {
444
  try {
445
- // Convert to pixel coordinates for easier calculation
446
  const indexTip = landmarks[8];
447
  const middleTip = landmarks[12];
448
- const wrist = landmarks[0];
449
 
450
- // Pointing detection (index finger higher than middle)
451
- // Fix: Proper Y-axis calculation (inverted in MediaPipe)
452
  const screenX = indexTip.x * window.innerWidth;
453
- const screenY = (1 - indexTip.y) * window.innerHeight;
454
 
 
455
  if (indexTip.y < middleTip.y) {
456
  this.checkEmailSelection(screenX, screenY);
457
  } else {
@@ -469,7 +467,7 @@ class GestureDetector {
469
  }
470
 
471
  // Get palm center for gesture detection
472
- // Fix: Better palm center calculation
473
  const palmCenterX = (wrist.x + landmarks[9].x) / 2;
474
  const palmCenterY = (wrist.y + landmarks[9].y) / 2;
475
 
@@ -533,14 +531,18 @@ class GestureDetector {
533
 
534
  checkEmailSelection(x, y) {
535
  try {
536
- // Check which email is under the finger
 
 
 
 
537
  for (let i = this.uiManager.emailElements.length - 1; i >= 0; i--) {
538
  const email = this.uiManager.emailElements[i];
539
  if (email.rect &&
540
- x >= email.rect.left &&
541
  x <= email.rect.right &&
542
- y >= email.rect.top &&
543
- y <= email.rect.bottom) {
544
 
545
  // Only select if it's a different email
546
  if (this.selectedEmailId !== email.id) {
@@ -557,8 +559,8 @@ class GestureDetector {
557
  email.rect &&
558
  x >= email.rect.left &&
559
  x <= email.rect.right &&
560
- y >= email.rect.top &&
561
- y <= email.rect.bottom)) {
562
  this.uiManager.clearSelection();
563
  this.selectedEmailId = null;
564
  this.debugManager.updateSelectedEmail(null);
@@ -578,7 +580,6 @@ class GestureDetector {
578
  switch (gesture) {
579
  case 'swipe_left':
580
  this.uiManager.showActionFeedback(`🗑️ Deleted: ${email.subject}`, 'delete');
581
- // Remove from UI
582
  const index = emails.findIndex(e => e.id === this.selectedEmailId);
583
  if (index !== -1) emails.splice(index, 1);
584
  this.uiManager.renderEmails();
@@ -588,7 +589,6 @@ class GestureDetector {
588
 
589
  case 'swipe_right':
590
  this.uiManager.showActionFeedback(`✅ Archived: ${email.subject}`, 'archive');
591
- // In a real app, we'd move to archive
592
  const archiveIndex = emails.findIndex(e => e.id === this.selectedEmailId);
593
  if (archiveIndex !== -1) emails.splice(archiveIndex, 1);
594
  this.uiManager.renderEmails();
 
442
 
443
  detectGesture(landmarks) {
444
  try {
 
445
  const indexTip = landmarks[8];
446
  const middleTip = landmarks[12];
 
447
 
448
+ // 🔥 CRITICAL FIX: Account for 60px header height!
 
449
  const screenX = indexTip.x * window.innerWidth;
450
+ const screenY = (1 - indexTip.y) * (window.innerHeight - 60); // Subtract header height
451
 
452
+ // Pointing detection (index finger higher than middle)
453
  if (indexTip.y < middleTip.y) {
454
  this.checkEmailSelection(screenX, screenY);
455
  } else {
 
467
  }
468
 
469
  // Get palm center for gesture detection
470
+ const wrist = landmarks[0];
471
  const palmCenterX = (wrist.x + landmarks[9].x) / 2;
472
  const palmCenterY = (wrist.y + landmarks[9].y) / 2;
473
 
 
531
 
532
  checkEmailSelection(x, y) {
533
  try {
534
+ // Convert to page-relative coordinates (accounting for scroll)
535
+ const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
536
+ const adjustedY = y + scrollTop;
537
+
538
+ // Find the email under the finger
539
  for (let i = this.uiManager.emailElements.length - 1; i >= 0; i--) {
540
  const email = this.uiManager.emailElements[i];
541
  if (email.rect &&
542
+ x >= email.rect.left &&
543
  x <= email.rect.right &&
544
+ adjustedY >= email.rect.top &&
545
+ adjustedY <= email.rect.bottom) {
546
 
547
  // Only select if it's a different email
548
  if (this.selectedEmailId !== email.id) {
 
559
  email.rect &&
560
  x >= email.rect.left &&
561
  x <= email.rect.right &&
562
+ adjustedY >= email.rect.top &&
563
+ adjustedY <= email.rect.bottom)) {
564
  this.uiManager.clearSelection();
565
  this.selectedEmailId = null;
566
  this.debugManager.updateSelectedEmail(null);
 
580
  switch (gesture) {
581
  case 'swipe_left':
582
  this.uiManager.showActionFeedback(`🗑️ Deleted: ${email.subject}`, 'delete');
 
583
  const index = emails.findIndex(e => e.id === this.selectedEmailId);
584
  if (index !== -1) emails.splice(index, 1);
585
  this.uiManager.renderEmails();
 
589
 
590
  case 'swipe_right':
591
  this.uiManager.showActionFeedback(`✅ Archived: ${email.subject}`, 'archive');
 
592
  const archiveIndex = emails.findIndex(e => e.id === this.selectedEmailId);
593
  if (archiveIndex !== -1) emails.splice(archiveIndex, 1);
594
  this.uiManager.renderEmails();