fix: improve drag handler installation logic to prevent multiple installations and enhance retry mechanism
This commit is contained in:
parent
ced50dd1f6
commit
308f77f84e
1 changed files with 28 additions and 4 deletions
|
|
@ -15,6 +15,7 @@
|
|||
var angularDragHandlers = [];
|
||||
var originalAddEventListener = EventTarget.prototype.addEventListener;
|
||||
var listenerPatchActive = true;
|
||||
var dragHandlerInstalled = false;
|
||||
|
||||
// Capture Authorization token from XHR requests
|
||||
window.capturedAuthToken = null;
|
||||
|
|
@ -75,8 +76,16 @@
|
|||
return;
|
||||
}
|
||||
|
||||
// Stop intercepting addEventListener
|
||||
listenerPatchActive = false;
|
||||
// Only install once, even if called multiple times
|
||||
if (dragHandlerInstalled) {
|
||||
console.log('[Intercept] Handler already installed, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
dragHandlerInstalled = true;
|
||||
|
||||
// NOTE: Keep listenerPatchActive = true to catch new Angular handlers registered later
|
||||
// This is important for page reloads where Angular might register handlers at different times
|
||||
|
||||
// Register OUR handler in capture phase
|
||||
originalAddEventListener.call(document, 'dragstart', function(e) {
|
||||
|
|
@ -150,8 +159,23 @@
|
|||
}
|
||||
|
||||
// Wait for Angular to register its listeners, then install our handler
|
||||
// Start checking after 2 seconds (give Angular time to load on first page load)
|
||||
setTimeout(installDragHandler, 2000);
|
||||
// Start checking after 3 seconds (give Angular time to load), then retry for up to 30 seconds
|
||||
var installRetries = 0;
|
||||
var maxRetries = 27; // 3 initial + 27 retries * 1s = 30s total
|
||||
|
||||
function scheduleInstall() {
|
||||
if (dragHandlerInstalled) return; // Already done
|
||||
installRetries++;
|
||||
console.log('[Intercept] Install attempt', installRetries, '/', maxRetries + 3);
|
||||
installDragHandler();
|
||||
if (!dragHandlerInstalled && installRetries < maxRetries) {
|
||||
setTimeout(scheduleInstall, 1000);
|
||||
} else if (!dragHandlerInstalled) {
|
||||
console.warn('[Intercept] Gave up waiting for Angular handlers after 30s');
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(scheduleInstall, 3000);
|
||||
|
||||
// ============================================================================
|
||||
// PART 3: QWebChannel connection
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue